From f64fa9e08afee371a7f00e66047427e9aecd6bbd Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 7 Apr 2014 20:52:36 -0700 Subject: [PATCH] disable autoplay when expanding all images --- builds/4chan-X.user.js | 16 +++++++++------- builds/crx/script.js | 16 +++++++++------- src/Images/ImageExpand.coffee | 14 +++++++------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 8e35fbb98..0dcb93101 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -7647,7 +7647,9 @@ if (ImageExpand.on = $.hasClass(ImageExpand.EAI, 'expand-all-shortcut')) { ImageExpand.EAI.className = 'contract-all-shortcut fa fa-compress'; ImageExpand.EAI.title = 'Contract All Images'; - func = ImageExpand.expand; + func = function(post) { + return ImageExpand.expand(post, null, true); + }; } else { ImageExpand.EAI.className = 'expand-all-shortcut fa fa-expand'; ImageExpand.EAI.title = 'Expand All Images'; @@ -7720,7 +7722,7 @@ $.rmClass(post.file.thumb, 'expanding'); return post.file.isExpanded = false; }, - expand: function(post, src) { + expand: function(post, src, disableAutoplay) { var el, isVideo, thumb, _ref; _ref = post.file, thumb = _ref.thumb, isVideo = _ref.isVideo; if (post.isHidden || post.file.isExpanded || $.hasClass(thumb, 'expanding')) { @@ -7749,10 +7751,10 @@ return el.naturalHeight; } }), function() { - return ImageExpand.completeExpand(post); + return ImageExpand.completeExpand(post, disableAutoplay); }); }, - completeExpand: function(post) { + completeExpand: function(post, disableAutoplay) { var bottom, thumb; thumb = post.file.thumb; if (!$.hasClass(thumb, 'expanding')) { @@ -7764,14 +7766,14 @@ } bottom = post.nodes.root.getBoundingClientRect().bottom; return $.queueTask(function() { - ImageExpand.completeExpand2(post); + ImageExpand.completeExpand2(post, disableAutoplay); if (!(bottom <= 0)) { return; } return window.scrollBy(0, post.nodes.root.getBoundingClientRect().bottom - bottom); }); }, - completeExpand2: function(post) { + completeExpand2: function(post, disableAutoplay) { var thumb; thumb = post.file.thumb; $.addClass(post.nodes.root, 'expanded-image'); @@ -7781,7 +7783,7 @@ ImageExpand.setupVideoControls(post); post.file.fullImage.muted = !Conf['Allow Sound']; post.file.fullImage.controls = Conf['Show Controls']; - if (Conf['Autoplay']) { + if (Conf['Autoplay'] && !disableAutoplay) { return ImageExpand.startVideo(post); } } diff --git a/builds/crx/script.js b/builds/crx/script.js index d535e794d..6b39dda17 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -7666,7 +7666,9 @@ if (ImageExpand.on = $.hasClass(ImageExpand.EAI, 'expand-all-shortcut')) { ImageExpand.EAI.className = 'contract-all-shortcut fa fa-compress'; ImageExpand.EAI.title = 'Contract All Images'; - func = ImageExpand.expand; + func = function(post) { + return ImageExpand.expand(post, null, true); + }; } else { ImageExpand.EAI.className = 'expand-all-shortcut fa fa-expand'; ImageExpand.EAI.title = 'Expand All Images'; @@ -7739,7 +7741,7 @@ $.rmClass(post.file.thumb, 'expanding'); return post.file.isExpanded = false; }, - expand: function(post, src) { + expand: function(post, src, disableAutoplay) { var el, isVideo, thumb, _ref; _ref = post.file, thumb = _ref.thumb, isVideo = _ref.isVideo; if (post.isHidden || post.file.isExpanded || $.hasClass(thumb, 'expanding')) { @@ -7768,10 +7770,10 @@ return el.naturalHeight; } }), function() { - return ImageExpand.completeExpand(post); + return ImageExpand.completeExpand(post, disableAutoplay); }); }, - completeExpand: function(post) { + completeExpand: function(post, disableAutoplay) { var bottom, thumb; thumb = post.file.thumb; if (!$.hasClass(thumb, 'expanding')) { @@ -7783,14 +7785,14 @@ } bottom = post.nodes.root.getBoundingClientRect().bottom; return $.queueTask(function() { - ImageExpand.completeExpand2(post); + ImageExpand.completeExpand2(post, disableAutoplay); if (!(bottom <= 0)) { return; } return window.scrollBy(0, post.nodes.root.getBoundingClientRect().bottom - bottom); }); }, - completeExpand2: function(post) { + completeExpand2: function(post, disableAutoplay) { var thumb; thumb = post.file.thumb; $.addClass(post.nodes.root, 'expanded-image'); @@ -7800,7 +7802,7 @@ ImageExpand.setupVideoControls(post); post.file.fullImage.muted = !Conf['Allow Sound']; post.file.fullImage.controls = Conf['Show Controls']; - if (Conf['Autoplay']) { + if (Conf['Autoplay'] && !disableAutoplay) { return ImageExpand.startVideo(post); } } diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index 272557ce3..c952e2557 100755 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -51,7 +51,7 @@ ImageExpand = if ImageExpand.on = $.hasClass ImageExpand.EAI, 'expand-all-shortcut' ImageExpand.EAI.className = 'contract-all-shortcut fa fa-compress' ImageExpand.EAI.title = 'Contract All Images' - func = ImageExpand.expand + func = (post) -> ImageExpand.expand post, null, true else ImageExpand.EAI.className = 'expand-all-shortcut fa fa-expand' ImageExpand.EAI.title = 'Expand All Images' @@ -109,7 +109,7 @@ ImageExpand = $.rmClass post.file.thumb, 'expanding' post.file.isExpanded = false - expand: (post, src) -> + expand: (post, src, disableAutoplay) -> # Do not expand images of hidden/filtered replies, or already expanded pictures. {thumb, isVideo} = post.file return if post.isHidden or post.file.isExpanded or $.hasClass thumb, 'expanding' @@ -125,9 +125,9 @@ ImageExpand = el.src = src or post.file.URL $.after thumb, el unless el is thumb.nextSibling $.asap (-> if isVideo then el.videoHeight else el.naturalHeight), -> - ImageExpand.completeExpand post + ImageExpand.completeExpand post, disableAutoplay - completeExpand: (post) -> + completeExpand: (post, disableAutoplay) -> {thumb} = post.file return unless $.hasClass thumb, 'expanding' # contracted before the image loaded unless post.nodes.root.parentNode @@ -137,11 +137,11 @@ ImageExpand = return {bottom} = post.nodes.root.getBoundingClientRect() $.queueTask -> - ImageExpand.completeExpand2 post + ImageExpand.completeExpand2 post, disableAutoplay return unless bottom <= 0 window.scrollBy 0, post.nodes.root.getBoundingClientRect().bottom - bottom - completeExpand2: (post) -> + completeExpand2: (post, disableAutoplay) -> {thumb} = post.file $.addClass post.nodes.root, 'expanded-image' $.rmClass post.file.thumb, 'expanding' @@ -150,7 +150,7 @@ ImageExpand = ImageExpand.setupVideoControls post post.file.fullImage.muted = !Conf['Allow Sound'] post.file.fullImage.controls = Conf['Show Controls'] - ImageExpand.startVideo post if Conf['Autoplay'] + ImageExpand.startVideo post if Conf['Autoplay'] and not disableAutoplay videoCB: click: (e) ->