From 9159f7adbc199a49ad83fcd0d0bca8d2b267d0f7 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 6 Aug 2013 14:16:49 -0700 Subject: [PATCH] I think I'm satisfied with this now. --- builds/4chan-X.user.js | 18 +++++++++++------- builds/crx/script.js | 18 +++++++++++------- src/Images/ImageExpand.coffee | 14 +++++++++----- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 707f493b1..1f7c82496 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -6283,7 +6283,7 @@ } }, toggle: function(post) { - var headRect, next, rect, root, thumb, x, y; + var headRect, rect, root, thumb, x, y; thumb = post.file.thumb; if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { @@ -6292,14 +6292,18 @@ } ImageExpand.contract(post); root = post.nodes.root; - if (Conf['Advance on contract']) { - while (next = $.x("following::div[contains(@class,'postContainer')][1]", root)) { - if (!($('.stub', next) || next.offsetHeight === 0)) { - break; + rect = (Conf['Advance on contract'] ? (function() { + var next; + + next = root; + while (next = $.x("following::div[contains(@class,'postContainer')][1]", next)) { + if ($('.stub', next) || next.offsetHeight === 0) { + continue; } + return next; } - } - rect = (next || root).getBoundingClientRect(); + return root; + })() : root).getBoundingClientRect(); if (rect.top < 0) { y = rect.top; if (Conf['Fixed Header'] && !Conf['Bottom Header']) { diff --git a/builds/crx/script.js b/builds/crx/script.js index 8aee581ea..0ec4ddd6f 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -6263,7 +6263,7 @@ } }, toggle: function(post) { - var headRect, next, rect, root, thumb, x, y; + var headRect, rect, root, thumb, x, y; thumb = post.file.thumb; if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { @@ -6272,14 +6272,18 @@ } ImageExpand.contract(post); root = post.nodes.root; - if (Conf['Advance on contract']) { - while (next = $.x("following::div[contains(@class,'postContainer')][1]", root)) { - if (!($('.stub', next) || next.offsetHeight === 0)) { - break; + rect = (Conf['Advance on contract'] ? (function() { + var next; + + next = root; + while (next = $.x("following::div[contains(@class,'postContainer')][1]", next)) { + if ($('.stub', next) || next.offsetHeight === 0) { + continue; } + return next; } - } - rect = (next || root).getBoundingClientRect(); + return root; + })() : root).getBoundingClientRect(); if (rect.top < 0) { y = rect.top; if (Conf['Fixed Header'] && !Conf['Bottom Header']) { diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index 53d11f035..a02e5ec31 100644 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -62,11 +62,15 @@ ImageExpand = # Scroll back to the thumbnail when contracting the image # to avoid being left miles away from the relevant post. {root} = post.nodes - if Conf['Advance on contract'] - while next = $.x "following::div[contains(@class,'postContainer')][1]", root - break unless $('.stub', next) or next.offsetHeight is 0 - - rect = (next or root).getBoundingClientRect() + rect = (if Conf['Advance on contract'] then do -> + next = root + while next = $.x "following::div[contains(@class,'postContainer')][1]", next + continue if $('.stub', next) or next.offsetHeight is 0 + return next + root + else + root + ).getBoundingClientRect() if rect.top < 0 y = rect.top