From 7658f575f37060e661b21c7b434130c42f78b3e9 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 8 Apr 2014 15:01:19 -0700 Subject: [PATCH] nitpicking --- builds/4chan-X.user.js | 83 ++++++++++++++++++----------------- builds/crx/script.js | 83 ++++++++++++++++++----------------- src/Images/ImageExpand.coffee | 52 +++++++++++----------- 3 files changed, 112 insertions(+), 106 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 7660b8f77..e30b390da 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -7952,16 +7952,18 @@ } thumb = this.file.thumb; $.on(thumb.parentNode, 'click', ImageExpand.cb.toggle); - if (this.isClone && $.hasClass(thumb, 'expanding')) { - ImageExpand.contract(this); - return ImageExpand.expand(this); - } else if (this.isClone && this.file.isExpanded && this.file.isVideo) { - clone = this; - ImageExpand.setupVideoControls(clone); - if (!clone.origin.file.fullImage.paused) { - return $.queueTask(function() { - return ImageExpand.startVideo(clone); - }); + if (this.isClone) { + if ($.hasClass(thumb, 'expanding')) { + ImageExpand.contract(this); + ImageExpand.expand(this); + } else if (this.file.isExpanded && this.file.isVideo) { + clone = this; + ImageExpand.setupVideoControls(clone); + if (!clone.origin.file.fullImage.paused) { + $.queueTask(function() { + return ImageExpand.startVideo(clone); + }); + } } } else if (ImageExpand.on && !this.isHidden && (Conf['Expand spoilers'] || !this.file.isSpoiler) && (Conf['Expand videos'] || !this.file.isVideo)) { return ImageExpand.expand(this, null, true); @@ -8104,9 +8106,8 @@ }); }, completeExpand: function(post, disableAutoplay) { - var bottom, thumb; - thumb = post.file.thumb; - if (!$.hasClass(thumb, 'expanding')) { + var bottom; + if (!$.hasClass(post.file.thumb, 'expanding')) { return; } if (!post.nodes.root.parentNode) { @@ -8123,8 +8124,6 @@ }); }, completeExpand2: function(post, disableAutoplay) { - var thumb; - thumb = post.file.thumb; $.addClass(post.nodes.root, 'expanded-image'); $.rmClass(post.file.thumb, 'expanding'); post.file.isExpanded = true; @@ -8137,32 +8136,36 @@ } } }, - videoCB: { - click: function(e) { - if (this.paused && !this.controls) { - this.play(); - return e.stopPropagation(); + videoCB: (function() { + var mousedown; + mousedown = false; + return { + mouseover: function() { + return mousedown = false; + }, + mousedown: function(e) { + if (e.button === 0) { + return mousedown = true; + } + }, + mouseup: function(e) { + if (e.button === 0) { + return mousedown = false; + } + }, + mouseout: function(e) { + if (mousedown && e.clientX <= this.getBoundingClientRect().left) { + return ImageExpand.contract(Get.postFromNode(this)); + } + }, + click: function(e) { + if (this.paused && !this.controls) { + e.stopPropagation(); + return this.play(); + } } - }, - mousedown: function(e) { - if (e.button === 0) { - return this.dataset.mousedown = 'true'; - } - }, - mouseup: function(e) { - if (e.button === 0) { - return this.dataset.mousedown = 'false'; - } - }, - mouseover: function(e) { - return this.dataset.mousedown = 'false'; - }, - mouseout: function(e) { - if (this.dataset.mousedown === 'true' && e.clientX <= this.getBoundingClientRect().left) { - return ImageExpand.contract(Get.postFromNode(this)); - } - } - }, + }; + })(), setupVideoControls: function(post) { var cb, contract, eventName, file, video, _ref; file = post.file; diff --git a/builds/crx/script.js b/builds/crx/script.js index 4e35133c8..de985735d 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -7991,16 +7991,18 @@ } thumb = this.file.thumb; $.on(thumb.parentNode, 'click', ImageExpand.cb.toggle); - if (this.isClone && $.hasClass(thumb, 'expanding')) { - ImageExpand.contract(this); - return ImageExpand.expand(this); - } else if (this.isClone && this.file.isExpanded && this.file.isVideo) { - clone = this; - ImageExpand.setupVideoControls(clone); - if (!clone.origin.file.fullImage.paused) { - return $.queueTask(function() { - return ImageExpand.startVideo(clone); - }); + if (this.isClone) { + if ($.hasClass(thumb, 'expanding')) { + ImageExpand.contract(this); + ImageExpand.expand(this); + } else if (this.file.isExpanded && this.file.isVideo) { + clone = this; + ImageExpand.setupVideoControls(clone); + if (!clone.origin.file.fullImage.paused) { + $.queueTask(function() { + return ImageExpand.startVideo(clone); + }); + } } } else if (ImageExpand.on && !this.isHidden && (Conf['Expand spoilers'] || !this.file.isSpoiler) && (Conf['Expand videos'] || !this.file.isVideo)) { return ImageExpand.expand(this, null, true); @@ -8143,9 +8145,8 @@ }); }, completeExpand: function(post, disableAutoplay) { - var bottom, thumb; - thumb = post.file.thumb; - if (!$.hasClass(thumb, 'expanding')) { + var bottom; + if (!$.hasClass(post.file.thumb, 'expanding')) { return; } if (!post.nodes.root.parentNode) { @@ -8162,8 +8163,6 @@ }); }, completeExpand2: function(post, disableAutoplay) { - var thumb; - thumb = post.file.thumb; $.addClass(post.nodes.root, 'expanded-image'); $.rmClass(post.file.thumb, 'expanding'); post.file.isExpanded = true; @@ -8176,32 +8175,36 @@ } } }, - videoCB: { - click: function(e) { - if (this.paused && !this.controls) { - this.play(); - return e.stopPropagation(); + videoCB: (function() { + var mousedown; + mousedown = false; + return { + mouseover: function() { + return mousedown = false; + }, + mousedown: function(e) { + if (e.button === 0) { + return mousedown = true; + } + }, + mouseup: function(e) { + if (e.button === 0) { + return mousedown = false; + } + }, + mouseout: function(e) { + if (mousedown && e.clientX <= this.getBoundingClientRect().left) { + return ImageExpand.contract(Get.postFromNode(this)); + } + }, + click: function(e) { + if (this.paused && !this.controls) { + e.stopPropagation(); + return this.play(); + } } - }, - mousedown: function(e) { - if (e.button === 0) { - return this.dataset.mousedown = 'true'; - } - }, - mouseup: function(e) { - if (e.button === 0) { - return this.dataset.mousedown = 'false'; - } - }, - mouseover: function(e) { - return this.dataset.mousedown = 'false'; - }, - mouseout: function(e) { - if (this.dataset.mousedown === 'true' && e.clientX <= this.getBoundingClientRect().left) { - return ImageExpand.contract(Get.postFromNode(this)); - } - } - }, + }; + })(), setupVideoControls: function(post) { var cb, contract, eventName, file, video, _ref; file = post.file; diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index 913d66991..1e08279c5 100755 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -17,16 +17,20 @@ ImageExpand = return unless @file?.isImage or @file?.isVideo {thumb} = @file $.on thumb.parentNode, 'click', ImageExpand.cb.toggle - if @isClone and $.hasClass thumb, 'expanding' - # If we clone a post where the image is still loading, - # make it loading in the clone too. - ImageExpand.contract @ - ImageExpand.expand @ - else if @isClone and @file.isExpanded and @file.isVideo - clone = @ - ImageExpand.setupVideoControls clone - unless clone.origin.file.fullImage.paused - $.queueTask -> ImageExpand.startVideo clone + if @isClone + if $.hasClass thumb, 'expanding' + # If we clone a post where the image is still loading, + # make it loading in the clone too. + ImageExpand.contract @ + ImageExpand.expand @ + + else if @file.isExpanded and @file.isVideo + clone = @ + ImageExpand.setupVideoControls clone + unless clone.origin.file.fullImage.paused + $.queueTask -> ImageExpand.startVideo clone + + return else if ImageExpand.on and !@isHidden and (Conf['Expand spoilers'] or !@file.isSpoiler) and (Conf['Expand videos'] or !@file.isVideo) @@ -130,8 +134,7 @@ ImageExpand = ImageExpand.completeExpand post, disableAutoplay completeExpand: (post, disableAutoplay) -> - {thumb} = post.file - return unless $.hasClass thumb, 'expanding' # contracted before the image loaded + return unless $.hasClass post.file.thumb, 'expanding' # contracted before the image loaded unless post.nodes.root.parentNode # Image might start/finish loading before the post is inserted. # Don't scroll when it's expanded in a QP for example. @@ -144,29 +147,26 @@ ImageExpand = window.scrollBy 0, post.nodes.root.getBoundingClientRect().bottom - bottom completeExpand2: (post, disableAutoplay) -> - {thumb} = post.file $.addClass post.nodes.root, 'expanded-image' $.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.muted = !Conf['Allow Sound'] post.file.fullImage.controls = Conf['Show Controls'] ImageExpand.startVideo post if Conf['Autoplay'] and not disableAutoplay - videoCB: - click: (e) -> - if @paused and not @controls - @play() - e.stopPropagation() - + videoCB: do -> # dragging to the left contracts the video - mousedown: (e) -> @dataset.mousedown = 'true' if e.button is 0 - mouseup: (e) -> @dataset.mousedown = 'false' if e.button is 0 - mouseover: (e) -> @dataset.mousedown = 'false' - mouseout: (e) -> - if @dataset.mousedown is 'true' and e.clientX <= @getBoundingClientRect().left - ImageExpand.contract (Get.postFromNode @) + mousedown = false + mouseover: -> mousedown = false + mousedown: (e) -> mousedown = true if e.button is 0 + mouseup: (e) -> mousedown = false if e.button is 0 + mouseout: (e) -> ImageExpand.contract (Get.postFromNode @) if mousedown and e.clientX <= @getBoundingClientRect().left + click: (e) -> + if @paused and not @controls + e.stopPropagation() + @play() setupVideoControls: (post) -> {file} = post