From 2a3f7ecd541ced9a661e5d97aae5534eef5ad6cf Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 5 Apr 2014 19:53:26 -0700 Subject: [PATCH] remove listeners on contract --- builds/4chan-X.user.js | 64 +++++++++++++++++++++-------------- builds/crx/script.js | 64 +++++++++++++++++++++-------------- src/Images/ImageExpand.coffee | 24 ++++++++----- 3 files changed, 91 insertions(+), 61 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 8f5f5012e..34e0790a9 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -8036,18 +8036,23 @@ return ImageExpand.contract(post); }, contract: function(post) { - var video, _ref; + var cb, eventName, video, _ref, _ref1; if (post.file.isVideo && (video = post.file.fullImage)) { video.pause(); + _ref = ImageExpand.videoCB; + for (eventName in _ref) { + cb = _ref[eventName]; + $.off(video, eventName, cb); + } TrashQueue.add(video); + if ((_ref1 = post.file.videoControls) != null) { + _ref1.map($.rm); + } + delete post.file.videoControls; } $.rmClass(post.nodes.root, 'expanded-image'); $.rmClass(post.file.thumb, 'expanding'); - post.file.isExpanded = false; - if ((_ref = post.file.videoControls) != null) { - _ref.map($.rm); - } - return delete post.file.videoControls; + return post.file.isExpanded = false; }, expand: function(post, src) { var img, isVideo, naturalHeight, thumb, _ref; @@ -8110,8 +8115,28 @@ return window.scrollBy(0, post.nodes.root.getBoundingClientRect().bottom - bottom); }); }, + videoCB: { + 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)); + } + } + }, setupVideo: function(post) { - var contract, file, play, video; + var cb, contract, eventName, file, play, video, _ref; file = post.file; video = file.fullImage; file.videoControls = []; @@ -8126,25 +8151,12 @@ return ImageExpand.contract(post); }); file.videoControls.push($.tn('\u00A0'), contract); - file.mousedown = false; - $.on(video, 'mousedown', function(e) { - if (e.button === 0) { - return file.mousedown = true; - } - }); - $.on(video, 'mouseup', function(e) { - if (e.button === 0) { - return file.mousedown = false; - } - }); - $.on(video, 'mouseover', function(e) { - return file.mousedown = false; - }); - $.on(video, 'mouseout', function(e) { - if (file.mousedown && e.clientX <= video.getBoundingClientRect().left) { - return ImageExpand.contract(post); - } - }); + video.dataset.mousedown = 'false'; + _ref = ImageExpand.videoCB; + for (eventName in _ref) { + cb = _ref[eventName]; + $.on(video, eventName, cb); + } } if (Conf['Autoplay']) { video.play(); diff --git a/builds/crx/script.js b/builds/crx/script.js index c472f5ac2..f27355813 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -8075,18 +8075,23 @@ return ImageExpand.contract(post); }, contract: function(post) { - var video, _ref; + var cb, eventName, video, _ref, _ref1; if (post.file.isVideo && (video = post.file.fullImage)) { video.pause(); + _ref = ImageExpand.videoCB; + for (eventName in _ref) { + cb = _ref[eventName]; + $.off(video, eventName, cb); + } TrashQueue.add(video); + if ((_ref1 = post.file.videoControls) != null) { + _ref1.map($.rm); + } + delete post.file.videoControls; } $.rmClass(post.nodes.root, 'expanded-image'); $.rmClass(post.file.thumb, 'expanding'); - post.file.isExpanded = false; - if ((_ref = post.file.videoControls) != null) { - _ref.map($.rm); - } - return delete post.file.videoControls; + return post.file.isExpanded = false; }, expand: function(post, src) { var img, isVideo, naturalHeight, thumb, _ref; @@ -8149,8 +8154,28 @@ return window.scrollBy(0, post.nodes.root.getBoundingClientRect().bottom - bottom); }); }, + videoCB: { + 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)); + } + } + }, setupVideo: function(post) { - var contract, file, play, video; + var cb, contract, eventName, file, play, video, _ref; file = post.file; video = file.fullImage; file.videoControls = []; @@ -8165,25 +8190,12 @@ return ImageExpand.contract(post); }); file.videoControls.push($.tn('\u00A0'), contract); - file.mousedown = false; - $.on(video, 'mousedown', function(e) { - if (e.button === 0) { - return file.mousedown = true; - } - }); - $.on(video, 'mouseup', function(e) { - if (e.button === 0) { - return file.mousedown = false; - } - }); - $.on(video, 'mouseover', function(e) { - return file.mousedown = false; - }); - $.on(video, 'mouseout', function(e) { - if (file.mousedown && e.clientX <= video.getBoundingClientRect().left) { - return ImageExpand.contract(post); - } - }); + video.dataset.mousedown = 'false'; + _ref = ImageExpand.videoCB; + for (eventName in _ref) { + cb = _ref[eventName]; + $.on(video, eventName, cb); + } } if (Conf['Autoplay']) { video.play(); diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index b2d6141e8..770f67004 100755 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -89,12 +89,14 @@ ImageExpand = contract: (post) -> if post.file.isVideo and video = post.file.fullImage video.pause() + for eventName, cb of ImageExpand.videoCB + $.off video, eventName, cb TrashQueue.add video + post.file.videoControls?.map($.rm) + delete post.file.videoControls $.rmClass post.nodes.root, 'expanded-image' $.rmClass post.file.thumb, 'expanding' post.file.isExpanded = false - post.file.videoControls?.map($.rm) - delete post.file.videoControls expand: (post, src) -> # Do not expand images of hidden/filtered replies, or already expanded pictures. @@ -140,6 +142,14 @@ ImageExpand = return unless bottom <= 0 window.scrollBy 0, post.nodes.root.getBoundingClientRect().bottom - bottom + videoCB: + 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 @) + setupVideo: (post) -> {file} = post video = file.fullImage @@ -154,13 +164,9 @@ ImageExpand = $.on contract, 'click', (e) -> ImageExpand.contract post file.videoControls.push $.tn('\u00A0'), contract # drag left to contract - file.mousedown = false - $.on video, 'mousedown', (e) -> file.mousedown = true if e.button is 0 - $.on video, 'mouseup', (e) -> file.mousedown = false if e.button is 0 - $.on video, 'mouseover', (e) -> file.mousedown = false - $.on video, 'mouseout', (e) -> - if file.mousedown and e.clientX <= video.getBoundingClientRect().left - ImageExpand.contract post + video.dataset.mousedown = 'false' + for eventName, cb of ImageExpand.videoCB + $.on video, eventName, cb if Conf['Autoplay'] video.play() else unless video.controls