From 08aa9b4624fe814e5ac919a36d40f1f6c9b0594d Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Thu, 10 Apr 2014 22:28:27 -0700 Subject: [PATCH] cleanup? --- LICENSE | 2 +- builds/4chan-X.user.js | 39 +++++++++++++++-------------------- builds/crx/script.js | 39 +++++++++++++++-------------------- src/Images/ImageExpand.coffee | 34 +++++++++++++++--------------- src/Images/ImageHover.coffee | 5 +++-- 5 files changed, 55 insertions(+), 64 deletions(-) diff --git a/LICENSE b/LICENSE index ffac59f17..fa9d3a87f 100755 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.7.3 - 2014-04-08 +* 4chan X - Version 1.7.3 - 2014-04-10 * * Licensed under the MIT license. * https://github.com/ccd0/4chan-x/blob/master/LICENSE diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index e30b390da..d91be5156 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -24,7 +24,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.7.3 - 2014-04-08 +* 4chan X - Version 1.7.3 - 2014-04-10 * * Licensed under the MIT license. * https://github.com/ccd0/4chan-x/blob/master/LICENSE @@ -8021,9 +8021,8 @@ } }, toggle: function(post) { - var headRect, left, root, thumb, top, x, y, _ref; - thumb = post.file.thumb; - if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { + var headRect, left, root, top, x, y, _ref; + if (!(post.file.isExpanded || $.hasClass(post.file.thumb, 'expanding'))) { ImageExpand.expand(post); return; } @@ -8055,12 +8054,13 @@ return ImageExpand.contract(post); }, contract: function(post) { - var cb, eventName, video, _ref; + var cb, eventName, thumb, video, _ref; + thumb = post.file.thumb; if (post.file.isVideo && (video = post.file.fullImage)) { video.pause(); TrashQueue.add(video, post); - post.file.thumb.parentNode.href = video.src; - post.file.thumb.parentNode.target = '_blank'; + thumb.parentNode.href = video.src; + thumb.parentNode.target = '_blank'; _ref = ImageExpand.videoCB; for (eventName in _ref) { cb = _ref[eventName]; @@ -8070,7 +8070,7 @@ delete post.file.videoControls; } $.rmClass(post.nodes.root, 'expanded-image'); - $.rmClass(post.file.thumb, 'expanding'); + $.rmClass(thumb, 'expanding'); return post.file.isExpanded = false; }, expand: function(post, src, disableAutoplay) { @@ -8086,21 +8086,17 @@ el = post.file.fullImage = $.el((isVideo ? 'video' : 'img'), { className: 'full-image' }); + $.on(el, 'error', ImageExpand.error); + el.src = src || post.file.URL; if (isVideo) { el.loop = true; } - $.on(el, 'error', ImageExpand.error); - el.src = src || post.file.URL; } if (el !== thumb.nextSibling) { $.after(thumb, el); } return $.asap((function() { - if (isVideo) { - return el.videoHeight; - } else { - return el.naturalHeight; - } + return el.videoHeight || el.naturalHeight; }), function() { return ImageExpand.completeExpand(post, disableAutoplay); }); @@ -8128,9 +8124,9 @@ $.rmClass(post.file.thumb, 'expanding'); post.file.isExpanded = true; if (post.file.isVideo) { - ImageExpand.setupVideoControls(post); post.file.fullImage.muted = !Conf['Allow Sound']; post.file.fullImage.controls = Conf['Show Controls']; + ImageExpand.setupVideoControls(post); if (Conf['Autoplay'] && !disableAutoplay) { return ImageExpand.startVideo(post); } @@ -8160,19 +8156,19 @@ }, click: function(e) { if (this.paused && !this.controls) { - e.stopPropagation(); - return this.play(); + this.play(); + return e.preventDefault(); } } }; })(), setupVideoControls: function(post) { - var cb, contract, eventName, file, video, _ref; + var cb, contract, eventName, file, thumb, video, _ref; file = post.file; + thumb = file.thumb; video = file.fullImage; file.thumb.parentNode.removeAttribute('href'); file.thumb.parentNode.removeAttribute('target'); - video.dataset.mousedown = 'false'; _ref = ImageExpand.videoCB; for (eventName in _ref) { cb = _ref[eventName]; @@ -8196,8 +8192,7 @@ }, startVideo: function(post) { var controls, file, video; - file = post.file; - video = file.fullImage; + video = (file = post.file).fullImage; controls = video.controls; video.controls = false; video.play(); diff --git a/builds/crx/script.js b/builds/crx/script.js index de985735d..c3c5872e4 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* 4chan X - Version 1.7.3 - 2014-04-08 +* 4chan X - Version 1.7.3 - 2014-04-10 * * Licensed under the MIT license. * https://github.com/ccd0/4chan-x/blob/master/LICENSE @@ -8060,9 +8060,8 @@ } }, toggle: function(post) { - var headRect, left, root, thumb, top, x, y, _ref; - thumb = post.file.thumb; - if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { + var headRect, left, root, top, x, y, _ref; + if (!(post.file.isExpanded || $.hasClass(post.file.thumb, 'expanding'))) { ImageExpand.expand(post); return; } @@ -8094,12 +8093,13 @@ return ImageExpand.contract(post); }, contract: function(post) { - var cb, eventName, video, _ref; + var cb, eventName, thumb, video, _ref; + thumb = post.file.thumb; if (post.file.isVideo && (video = post.file.fullImage)) { video.pause(); TrashQueue.add(video, post); - post.file.thumb.parentNode.href = video.src; - post.file.thumb.parentNode.target = '_blank'; + thumb.parentNode.href = video.src; + thumb.parentNode.target = '_blank'; _ref = ImageExpand.videoCB; for (eventName in _ref) { cb = _ref[eventName]; @@ -8109,7 +8109,7 @@ delete post.file.videoControls; } $.rmClass(post.nodes.root, 'expanded-image'); - $.rmClass(post.file.thumb, 'expanding'); + $.rmClass(thumb, 'expanding'); return post.file.isExpanded = false; }, expand: function(post, src, disableAutoplay) { @@ -8125,21 +8125,17 @@ el = post.file.fullImage = $.el((isVideo ? 'video' : 'img'), { className: 'full-image' }); + $.on(el, 'error', ImageExpand.error); + el.src = src || post.file.URL; if (isVideo) { el.loop = true; } - $.on(el, 'error', ImageExpand.error); - el.src = src || post.file.URL; } if (el !== thumb.nextSibling) { $.after(thumb, el); } return $.asap((function() { - if (isVideo) { - return el.videoHeight; - } else { - return el.naturalHeight; - } + return el.videoHeight || el.naturalHeight; }), function() { return ImageExpand.completeExpand(post, disableAutoplay); }); @@ -8167,9 +8163,9 @@ $.rmClass(post.file.thumb, 'expanding'); post.file.isExpanded = true; if (post.file.isVideo) { - ImageExpand.setupVideoControls(post); post.file.fullImage.muted = !Conf['Allow Sound']; post.file.fullImage.controls = Conf['Show Controls']; + ImageExpand.setupVideoControls(post); if (Conf['Autoplay'] && !disableAutoplay) { return ImageExpand.startVideo(post); } @@ -8199,19 +8195,19 @@ }, click: function(e) { if (this.paused && !this.controls) { - e.stopPropagation(); - return this.play(); + this.play(); + return e.preventDefault(); } } }; })(), setupVideoControls: function(post) { - var cb, contract, eventName, file, video, _ref; + var cb, contract, eventName, file, thumb, video, _ref; file = post.file; + thumb = file.thumb; video = file.fullImage; file.thumb.parentNode.removeAttribute('href'); file.thumb.parentNode.removeAttribute('target'); - video.dataset.mousedown = 'false'; _ref = ImageExpand.videoCB; for (eventName in _ref) { cb = _ref[eventName]; @@ -8235,8 +8231,7 @@ }, startVideo: function(post) { var controls, file, video; - file = post.file; - video = file.fullImage; + video = (file = post.file).fullImage; controls = video.controls; video.controls = false; video.play(); diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index 258c74368..b3c8da980 100755 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -50,8 +50,8 @@ ImageExpand = return unless file and (file.isImage or file.isVideo) and doc.contains post.nodes.root if ImageExpand.on and (!Conf['Expand spoilers'] and file.isSpoiler or - !Conf['Expand videos'] and file.isVideo or - Conf['Expand from here'] and Header.getTopOf(file.thumb) < 0) + !Conf['Expand videos'] and file.isVideo or + Conf['Expand from here'] and Header.getTopOf(file.thumb) < 0) return $.queueTask func, post @@ -72,8 +72,7 @@ ImageExpand = (if @checked then $.addClass else $.rmClass) doc, @name.toLowerCase().replace /\s+/g, '-' toggle: (post) -> - {thumb} = post.file - unless post.file.isExpanded or $.hasClass thumb, 'expanding' + unless post.file.isExpanded or $.hasClass post.file.thumb, 'expanding' ImageExpand.expand post return @@ -102,17 +101,18 @@ ImageExpand = ImageExpand.contract post contract: (post) -> + {thumb} = post.file if post.file.isVideo and video = post.file.fullImage video.pause() TrashQueue.add video, post - post.file.thumb.parentNode.href = video.src - post.file.thumb.parentNode.target = '_blank' + thumb.parentNode.href = video.src + thumb.parentNode.target = '_blank' for eventName, cb of ImageExpand.videoCB $.off video, eventName, cb - $.rm post.file.videoControls + $.rm post.file.videoControls delete post.file.videoControls $.rmClass post.nodes.root, 'expanded-image' - $.rmClass post.file.thumb, 'expanding' + $.rmClass thumb, 'expanding' post.file.isExpanded = false expand: (post, src, disableAutoplay) -> @@ -126,11 +126,12 @@ ImageExpand = else el = post.file.fullImage = $.el (if isVideo then 'video' else 'img'), className: 'full-image' - el.loop = true if isVideo $.on el, 'error', ImageExpand.error el.src = src or post.file.URL + if isVideo + el.loop = true $.after thumb, el unless el is thumb.nextSibling - $.asap (-> if isVideo then el.videoHeight else el.naturalHeight), -> + $.asap (-> el.videoHeight or el.naturalHeight), -> ImageExpand.completeExpand post, disableAutoplay completeExpand: (post, disableAutoplay) -> @@ -151,9 +152,9 @@ ImageExpand = $.rmClass post.file.thumb, 'expanding' post.file.isExpanded = true if post.file.isVideo - ImageExpand.setupVideoControls post post.file.fullImage.muted = !Conf['Allow Sound'] post.file.fullImage.controls = Conf['Show Controls'] + ImageExpand.setupVideoControls post ImageExpand.startVideo post if Conf['Autoplay'] and not disableAutoplay videoCB: do -> @@ -165,19 +166,19 @@ ImageExpand = mouseout: (e) -> ImageExpand.contract(Get.postFromNode @) if mousedown and e.clientX <= @getBoundingClientRect().left click: (e) -> if @paused and not @controls - e.stopPropagation() @play() + e.preventDefault() setupVideoControls: (post) -> - {file} = post - video = file.fullImage + {file} = post + {thumb} = file + video = file.fullImage # disable link to file so native controls can work file.thumb.parentNode.removeAttribute 'href' file.thumb.parentNode.removeAttribute 'target' # setup callbacks on video element - video.dataset.mousedown = 'false' $.on video, eventName, cb for eventName, cb of ImageExpand.videoCB # setup controls in file info @@ -193,8 +194,7 @@ ImageExpand = $.add file.text, file.videoControls startVideo: (post) -> - {file} = post - video = file.fullImage + video = (file = post.file).fullImage {controls} = video video.controls = false video.play() diff --git a/src/Images/ImageHover.coffee b/src/Images/ImageHover.coffee index 7d50f68f5..f216a7ab6 100755 --- a/src/Images/ImageHover.coffee +++ b/src/Images/ImageHover.coffee @@ -29,6 +29,7 @@ ImageHover = src: post.file.URL post.file.fullImage = el {thumb} = post.file + if d.body.contains thumb $.after thumb, el unless el is thumb.nextSibling else @@ -36,9 +37,9 @@ ImageHover = el.id = 'ihover' el.dataset.fullID = post.fullID if isVideo - el.loop = true + el.loop = true el.controls = false - el.muted = not Conf['Allow Sound'] + el.muted = not Conf['Allow Sound'] el.play() if Conf['Autoplay'] UI.hover root: @