diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index ca9224a93..970a9ac5a 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -6283,7 +6283,7 @@ } }, toggle: function(post) { - var headRect, node, rect, thumb, x, y; + var headRect, rect, root, thumb, x, y; thumb = post.file.thumb; if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { @@ -6291,28 +6291,17 @@ return; } ImageExpand.contract(post); - node = post.nodes.root; - rect = Conf['Advance on contract'] ? (function() { - while (node.nextElementSibling) { - if (!(node = node.nextElementSibling)) { - return post.nodes.root; - } - if (!$.hasClass(node, 'postContainer')) { - continue; - } - if (node.offsetHeight > 0 && !$('.stub', node)) { - break; - } - } - return node.getBoundingClientRect(); - })() : post.nodes.root.getBoundingClientRect(); - if (!(rect.top <= 0 || rect.left <= 0)) { - return; - } + root = post.nodes.root; + rect = (Conf['Advance on contract'] ? (function() { + var next; + + next = $.x("following::div[contains(@class,'postContainer')][1]", root); + return next || root; + })() : root).getBoundingClientRect(); if (rect.top < 0) { y = rect.top; if (Conf['Fixed Header'] && !Conf['Bottom Header']) { - headRect = Header.toggle.getBoundingClientRect(); + headRect = Header.bar.getBoundingClientRect(); y -= headRect.top + headRect.height; } } diff --git a/builds/crx/script.js b/builds/crx/script.js index d3384960c..0b6aa6596 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -6263,7 +6263,7 @@ } }, toggle: function(post) { - var headRect, node, rect, thumb, x, y; + var headRect, rect, root, thumb, x, y; thumb = post.file.thumb; if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { @@ -6271,28 +6271,17 @@ return; } ImageExpand.contract(post); - node = post.nodes.root; - rect = Conf['Advance on contract'] ? (function() { - while (node.nextElementSibling) { - if (!(node = node.nextElementSibling)) { - return post.nodes.root; - } - if (!$.hasClass(node, 'postContainer')) { - continue; - } - if (node.offsetHeight > 0 && !$('.stub', node)) { - break; - } - } - return node.getBoundingClientRect(); - })() : post.nodes.root.getBoundingClientRect(); - if (!(rect.top <= 0 || rect.left <= 0)) { - return; - } + root = post.nodes.root; + rect = (Conf['Advance on contract'] ? (function() { + var next; + + next = $.x("following::div[contains(@class,'postContainer')][1]", root); + return next || root; + })() : root).getBoundingClientRect(); if (rect.top < 0) { y = rect.top; if (Conf['Fixed Header'] && !Conf['Bottom Header']) { - headRect = Header.toggle.getBoundingClientRect(); + headRect = Header.bar.getBoundingClientRect(); y -= headRect.top + headRect.height; } } diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index afbfcd0a7..7d6a627b1 100644 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -59,24 +59,19 @@ ImageExpand = ImageExpand.expand post return ImageExpand.contract post - node = post.nodes.root # Scroll back to the thumbnail when contracting the image # to avoid being left miles away from the relevant post. - rect = if Conf['Advance on contract'] then do -> - # FIXME does not work with Quote Threading - while node.nextElementSibling - return post.nodes.root unless node = node.nextElementSibling - continue unless $.hasClass node, 'postContainer' - break if node.offsetHeight > 0 and not $ '.stub', node - node.getBoundingClientRect() + {root} = post.nodes + rect = (if Conf['Advance on contract'] then do -> + next = $.x "following::div[contains(@class,'postContainer')][1]", root + next or root else - post.nodes.root.getBoundingClientRect() - return unless rect.top <= 0 or rect.left <= 0 + root).getBoundingClientRect() if rect.top < 0 y = rect.top if Conf['Fixed Header'] and not Conf['Bottom Header'] - headRect = Header.toggle.getBoundingClientRect() + headRect = Header.bar.getBoundingClientRect() y -= headRect.top + headRect.height if rect.left < 0