From 63cd0aa1641ff35e977c7522500d148edbe45888 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Tue, 6 Aug 2013 15:27:16 +0200 Subject: [PATCH 1/8] ExpandThread tweaking. Also fix code trying to $.off `ExpandThread.cb.toggle`. --- src/Miscellaneous/ExpandThread.coffee | 82 +++++++++++++-------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/src/Miscellaneous/ExpandThread.coffee b/src/Miscellaneous/ExpandThread.coffee index 4fd4d44a4..557770a15 100644 --- a/src/Miscellaneous/ExpandThread.coffee +++ b/src/Miscellaneous/ExpandThread.coffee @@ -6,7 +6,7 @@ ExpandThread = name: 'Thread Expansion' cb: @node node: -> - return unless span = $ '.summary', @OP.nodes.root.parentNode + return unless span = $.x 'following-sibling::span[contains(@class,"summary")][1]', @OP.nodes.root a = $.el 'a', textContent: "+ #{span.textContent}" className: 'summary' @@ -15,8 +15,7 @@ ExpandThread = $.replace span, a cbToggle: -> - op = Get.postFromRoot @previousElementSibling - ExpandThread.toggle op.thread + ExpandThread.toggle Get.threadFromRoot @parentNode toggle: (thread) -> threadRoot = thread.OP.nodes.root.parentNode @@ -24,7 +23,6 @@ ExpandThread = switch thread.isExpanded when false, undefined - thread.isExpanded = 'loading' for post in $$ '.thread > .postContainer', threadRoot ExpandComment.expand Get.postFromRoot post unless a @@ -42,60 +40,58 @@ ExpandThread = when true thread.isExpanded = false - if a - a.textContent = a.textContent.replace '-', '+' - #goddamit moot - num = if thread.isSticky - 1 - else switch g.BOARD.ID - # XXX boards config - when 'b', 'vg', 'q' then 3 - when 't' then 1 - else 5 - replies = $$('.thread > .replyContainer', threadRoot)[...-num] - for reply in replies - if Conf['Quote Inlining'] - # rm clones - inlined.click() while inlined = $ '.inlined', reply - $.rm reply - for post in $$ '.thread > .postContainer', threadRoot + #goddamit moot + num = if thread.isSticky + 1 + else switch g.BOARD.ID + # XXX boards config + when 'b', 'vg', 'q' then 3 + when 't' then 1 + else 5 + posts = $$ ".thread > .replyContainer", threadRoot + for post in [thread.OP.nodes.root].concat posts[-num..] ExpandComment.contract Get.postFromRoot post + return unless a + a.textContent = a.textContent.replace '-', '+' + for reply in posts[...-num] + if Conf['Quote Inlining'] + # rm clones + inlined.click() while inlined = $ '.inlined', reply + $.rm reply return parse: (req, thread, a) -> return if a.textContent[0] is '+' - {status} = req - if status not in [200, 304] - a.textContent = "Error #{req.statusText} (#{status})" - $.off a, 'click', ExpandThread.cb.toggle + if req.status not in [200, 304] + a.textContent = "Error #{req.statusText} (#{req.status})" + $.off a, 'click', ExpandThread.cbToggle return thread.isExpanded = true a.textContent = a.textContent.replace '× Loading...', '-' - posts = JSON.parse(req.response).posts - if spoilerRange = posts[0].custom_spoiler - Build.spoilerRange[g.BOARD] = spoilerRange + {posts} = JSON.parse req.response + if spoilerRange = posts.shift().custom_spoiler + Build.spoilerRange[thread.board] = spoilerRange - replies = posts[1..] - posts = [] - nodes = [] - for reply in replies - if post = thread.posts[reply.no] - nodes.push post.nodes.root + postsObj = [] + postsRoot = [] + for post in posts + if post = thread.posts[post.no] + postsRoot.push post.nodes.root continue - node = Build.postFromObject reply, thread.board.ID - post = new Post node, thread, thread.board - link = $ 'a[title="Highlight this post"]', node + root = Build.postFromObject post, thread.board.ID + post = new Post root, thread, thread.board + link = $ 'a[title="Highlight this post"]', root link.href = "res/#{thread}#p#{post}" link.nextSibling.href = "res/#{thread}#q#{post}" - posts.push post - nodes.push node - Main.callbackNodes Post, posts - $.after a, nodes + postsObj.push post + postsRoot.push root + Main.callbackNodes Post, postsObj + $.after a, postsRoot # Enable 4chan features. if Conf['Enable 4chan\'s Extension'] - $.globalEval "Parser.parseThread(#{thread.ID}, 1, #{nodes.length})" + $.globalEval "Parser.parseThread(#{thread.ID}, 1, #{postsRoot.length})" else - Fourchan.parseThread thread.ID, 1, nodes.length + Fourchan.parseThread thread.ID, 1, postsRoot.length From be7a4052fdb1dbf5acafb827e3247def572630b4 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Tue, 6 Aug 2013 16:28:54 +0200 Subject: [PATCH 2/8] Close #1106 --- src/Miscellaneous/ExpandThread.coffee | 43 +++++++++++++++++++-------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/Miscellaneous/ExpandThread.coffee b/src/Miscellaneous/ExpandThread.coffee index 557770a15..c18bd8088 100644 --- a/src/Miscellaneous/ExpandThread.coffee +++ b/src/Miscellaneous/ExpandThread.coffee @@ -7,13 +7,21 @@ ExpandThread = cb: @node node: -> return unless span = $.x 'following-sibling::span[contains(@class,"summary")][1]', @OP.nodes.root + [posts, files] = span.textContent.match /\d+/g a = $.el 'a', - textContent: "+ #{span.textContent}" + textContent: ExpandThread.text '+', posts, files className: 'summary' href: 'javascript:;' $.on a, 'click', ExpandThread.cbToggle $.replace span, a + text: (status, posts, files) -> + text = [status] + text.push "#{posts} post#{if posts > 1 then 's' else ''}" + text.push "and #{files} image repl#{if files > 1 then 'ies' else 'y'}" if +files + text.push if status is '-' then 'shown' else 'omitted' + text.join(' ') + '.' + cbToggle: -> ExpandThread.toggle Get.threadFromRoot @parentNode @@ -29,14 +37,16 @@ ExpandThread = thread.isExpanded = true return thread.isExpanded = 'loading' - a.textContent = a.textContent.replace '+', '× Loading...' + [posts, files] = a.textContent.match /\d+/g + a.textContent = ExpandThread.text '...', posts, files $.cache "//api.4chan.org/#{thread.board}/res/#{thread}.json", -> ExpandThread.parse @, thread, a when 'loading' thread.isExpanded = false return unless a - a.textContent = a.textContent.replace '× Loading...', '+' + [posts, files] = a.textContent.match /\d+/g + a.textContent = ExpandThread.text '+', posts, files when true thread.isExpanded = false @@ -52,12 +62,16 @@ ExpandThread = for post in [thread.OP.nodes.root].concat posts[-num..] ExpandComment.contract Get.postFromRoot post return unless a - a.textContent = a.textContent.replace '-', '+' + postsCount = 0 + filesCount = 0 for reply in posts[...-num] if Conf['Quote Inlining'] # rm clones inlined.click() while inlined = $ '.inlined', reply + postsCount++ + filesCount++ if 'file' of Get.postFromRoot reply $.rm reply + a.textContent = ExpandThread.text '+', postsCount, filesCount return parse: (req, thread, a) -> @@ -68,30 +82,35 @@ ExpandThread = return thread.isExpanded = true - a.textContent = a.textContent.replace '× Loading...', '-' {posts} = JSON.parse req.response if spoilerRange = posts.shift().custom_spoiler Build.spoilerRange[thread.board] = spoilerRange - postsObj = [] - postsRoot = [] - for post in posts - if post = thread.posts[post.no] + postsObj = [] + postsRoot = [] + filesCount = 0 + for reply in posts + if post = thread.posts[reply.no] + filesCount++ if 'file' of post postsRoot.push post.nodes.root continue - root = Build.postFromObject post, thread.board.ID + root = Build.postFromObject reply, thread.board.ID post = new Post root, thread, thread.board link = $ 'a[title="Highlight this post"]', root link.href = "res/#{thread}#p#{post}" link.nextSibling.href = "res/#{thread}#q#{post}" + filesCount++ if 'file' of post postsObj.push post postsRoot.push root Main.callbackNodes Post, postsObj $.after a, postsRoot + postsCount = postsRoot.length + a.textContent = ExpandThread.text '-', postsCount, filesCount + # Enable 4chan features. if Conf['Enable 4chan\'s Extension'] - $.globalEval "Parser.parseThread(#{thread.ID}, 1, #{postsRoot.length})" + $.globalEval "Parser.parseThread(#{thread.ID}, 1, #{postsCount})" else - Fourchan.parseThread thread.ID, 1, postsRoot.length + Fourchan.parseThread thread.ID, 1, postsCount From 738a175f43b97c45ce471a2ff1e9ba7b51e9d800 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Tue, 6 Aug 2013 21:11:03 +0200 Subject: [PATCH 3/8] Avoid using {d.body,doc}.scroll{Top,Left}, use window.scroll[...] instead. --- src/General/Header.coffee | 4 ++-- src/General/UI.coffee | 4 ++-- src/Images/ImageExpand.coffee | 22 +++++++++++----------- src/Monitoring/ThreadUpdater.coffee | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/General/Header.coffee b/src/General/Header.coffee index ae98518ed..4c76991b1 100644 --- a/src/General/Header.coffee +++ b/src/General/Header.coffee @@ -248,8 +248,8 @@ Header = {top} = post.getBoundingClientRect() unless Conf['Bottom header'] headRect = Header.toggle.getBoundingClientRect() - top += - headRect.top - headRect.height - <% if (type === 'crx') { %>d.body<% } else { %>doc<% } %>.scrollTop += top + top -= headRect.top + headRect.height + window.scrollBy 0, top addShortcut: (el) -> shortcut = $.el 'span', diff --git a/src/General/UI.coffee b/src/General/UI.coffee index 7c6c752e0..84bc40a08 100644 --- a/src/General/UI.coffee +++ b/src/General/UI.coffee @@ -63,8 +63,8 @@ UI = do -> # Position mRect = menu.getBoundingClientRect() bRect = button.getBoundingClientRect() - bTop = doc.scrollTop + d.body.scrollTop + bRect.top - bLeft = doc.scrollLeft + d.body.scrollLeft + bRect.left + bTop = window.scrollY + bRect.top + bLeft = window.scrollX + bRect.left cHeight = doc.clientHeight cWidth = doc.clientWidth [top, bottom] = if bRect.top + bRect.height + mRect.height < cHeight diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index 777cceea8..9a4d8dd3f 100644 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -59,17 +59,18 @@ ImageExpand = ImageExpand.expand post return ImageExpand.contract post - rect = post.nodes.root.getBoundingClientRect() - return unless rect.top <= 0 or rect.left <= 0 + # Scroll back to the thumbnail when contracting the image # to avoid being left miles away from the relevant post. - {top} = rect - unless Conf['Bottom header'] - headRect = Header.toggle.getBoundingClientRect() - top += - headRect.top - headRect.height - root = <% if (type === 'crx') { %>d.body<% } else { %>doc<% } %> - root.scrollTop += top if rect.top < 0 - root.scrollLeft = 0 if rect.left < 0 + rect = post.nodes.root.getBoundingClientRect() + if rect.top < 0 + y = rect.top + unless Conf['Bottom header'] + headRect = Header.toggle.getBoundingClientRect() + y -= headRect.top + headRect.height + if rect.left < 0 + x = -window.scrollX + window.scrollBy x, y if x or y contract: (post) -> $.rmClass post.nodes.root, 'expanded-image' @@ -109,9 +110,8 @@ ImageExpand = $.addClass post.nodes.root, 'expanded-image' $.rmClass post.file.thumb, 'expanding' return unless prev.top + prev.height <= 0 - root = <% if (type === 'crx') { %>d.body<% } else { %>doc<% } %> curr = post.nodes.root.getBoundingClientRect() - root.scrollTop += curr.height - prev.height + curr.top - prev.top + window.scrollBy 0, curr.height - prev.height + curr.top - prev.top error: -> post = Get.postFromNode @ diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index 7dab2983a..ceb1a68bd 100644 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -262,7 +262,7 @@ ThreadUpdater = sendEvent() if scroll if Conf['Bottom Scroll'] - <% if (type === 'crx') { %>d.body<% } else { %>doc<% } %>.scrollTop = d.body.clientHeight + window.scrollTo 0, d.body.clientHeight else Header.scrollToPost nodes[0] From 9b5cb52619bf00ab70f128ef828a0682688ab142 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 6 Aug 2013 12:14:23 -0700 Subject: [PATCH 4/8] Personal choices --- builds/4chan-X.user.js | 10 +--------- builds/crx/script.js | 10 +--------- src/Miscellaneous/ExpandThread.coffee | 9 ++++----- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 497294377..6dbe56c2c 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -8627,15 +8627,7 @@ return $.replace(span, a); }, text: function(status, posts, files) { - var text; - - text = [status]; - text.push("" + posts + " post" + (posts > 1 ? 's' : '')); - if (+files) { - text.push("and " + files + " image repl" + (files > 1 ? 'ies' : 'y')); - } - text.push(status === '-' ? 'shown' : 'omitted'); - return text.join(' ') + '.'; + return ("" + status + " " + posts + " post" + (posts > 1 ? 's' : '')) + (+files ? " and " + files + " image repl" + (files > 1 ? 'ies' : 'y') : "") + (" " + (status === '-' ? 'shown' : 'omitted') + "."); }, cbToggle: function() { return ExpandThread.toggle(Get.threadFromRoot(this.parentNode)); diff --git a/builds/crx/script.js b/builds/crx/script.js index 4816da6d1..593d72a9f 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -8612,15 +8612,7 @@ return $.replace(span, a); }, text: function(status, posts, files) { - var text; - - text = [status]; - text.push("" + posts + " post" + (posts > 1 ? 's' : '')); - if (+files) { - text.push("and " + files + " image repl" + (files > 1 ? 'ies' : 'y')); - } - text.push(status === '-' ? 'shown' : 'omitted'); - return text.join(' ') + '.'; + return ("" + status + " " + posts + " post" + (posts > 1 ? 's' : '')) + (+files ? " and " + files + " image repl" + (files > 1 ? 'ies' : 'y') : "") + (" " + (status === '-' ? 'shown' : 'omitted') + "."); }, cbToggle: function() { return ExpandThread.toggle(Get.threadFromRoot(this.parentNode)); diff --git a/src/Miscellaneous/ExpandThread.coffee b/src/Miscellaneous/ExpandThread.coffee index 4d63a2989..3f3a7c19a 100644 --- a/src/Miscellaneous/ExpandThread.coffee +++ b/src/Miscellaneous/ExpandThread.coffee @@ -5,6 +5,7 @@ ExpandThread = Thread::callbacks.push name: 'Thread Expansion' cb: @node + node: -> return unless span = $.x 'following-sibling::span[contains(@class,"summary")][1]', @OP.nodes.root [posts, files] = span.textContent.match /\d+/g @@ -16,11 +17,9 @@ ExpandThread = $.replace span, a text: (status, posts, files) -> - text = [status] - text.push "#{posts} post#{if posts > 1 then 's' else ''}" - text.push "and #{files} image repl#{if files > 1 then 'ies' else 'y'}" if +files - text.push if status is '-' then 'shown' else 'omitted' - text.join(' ') + '.' + "#{status} #{posts} post#{if posts > 1 then 's' else ''}" + + (if +files then " and #{files} image repl#{if files > 1 then 'ies' else 'y'}" else "") + + " #{if status is '-' then 'shown' else 'omitted'}." cbToggle: -> ExpandThread.toggle Get.threadFromRoot @parentNode From 7939d24640dfa997a27e69c590fe4d18e105d47c Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 6 Aug 2013 13:33:57 -0700 Subject: [PATCH 5/8] Fix "Advance on contract" option with Quote Threading --- builds/4chan-X.user.js | 29 +++++++++-------------------- builds/crx/script.js | 29 +++++++++-------------------- src/Images/ImageExpand.coffee | 17 ++++++----------- 3 files changed, 24 insertions(+), 51 deletions(-) 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 From 1227cbd847054f12f6559fbd2debd44f9e3c1383 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 6 Aug 2013 13:37:24 -0700 Subject: [PATCH 6/8] Small simplify --- builds/4chan-X.user.js | 7 +------ builds/crx/script.js | 7 +------ src/Images/ImageExpand.coffee | 8 ++++---- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 970a9ac5a..50efb10d3 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -6292,12 +6292,7 @@ } ImageExpand.contract(post); 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(); + rect = (Conf['Advance on contract'] ? $.x("following::div[contains(@class,'postContainer')][1]", root) || 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 0b6aa6596..bcdd59bae 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -6272,12 +6272,7 @@ } ImageExpand.contract(post); 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(); + rect = (Conf['Advance on contract'] ? $.x("following::div[contains(@class,'postContainer')][1]", root) || 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 7d6a627b1..25105dd72 100644 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -62,11 +62,11 @@ ImageExpand = # Scroll back to the thumbnail when contracting the image # to avoid being left miles away from the relevant post. {root} = post.nodes - rect = (if Conf['Advance on contract'] then do -> - next = $.x "following::div[contains(@class,'postContainer')][1]", root - next or root + rect = (if Conf['Advance on contract'] + $.x("following::div[contains(@class,'postContainer')][1]", root) or root else - root).getBoundingClientRect() + root + ).getBoundingClientRect() if rect.top < 0 y = rect.top From 5507168019e14608488b4ccbcfb311ff4413f75f Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 6 Aug 2013 13:55:44 -0700 Subject: [PATCH 7/8] Forgot to account for hidden posts. --- builds/4chan-X.user.js | 11 +++++++++-- builds/crx/script.js | 11 +++++++++-- src/Images/ImageExpand.coffee | 10 +++++----- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 50efb10d3..707f493b1 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -6283,7 +6283,7 @@ } }, toggle: function(post) { - var headRect, rect, root, thumb, x, y; + var headRect, next, rect, root, thumb, x, y; thumb = post.file.thumb; if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { @@ -6292,7 +6292,14 @@ } ImageExpand.contract(post); root = post.nodes.root; - rect = (Conf['Advance on contract'] ? $.x("following::div[contains(@class,'postContainer')][1]", root) || root : root).getBoundingClientRect(); + if (Conf['Advance on contract']) { + while (next = $.x("following::div[contains(@class,'postContainer')][1]", root)) { + if (!($('.stub', next) || next.offsetHeight === 0)) { + break; + } + } + } + rect = (next || 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 bcdd59bae..8aee581ea 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -6263,7 +6263,7 @@ } }, toggle: function(post) { - var headRect, rect, root, thumb, x, y; + var headRect, next, rect, root, thumb, x, y; thumb = post.file.thumb; if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { @@ -6272,7 +6272,14 @@ } ImageExpand.contract(post); root = post.nodes.root; - rect = (Conf['Advance on contract'] ? $.x("following::div[contains(@class,'postContainer')][1]", root) || root : root).getBoundingClientRect(); + if (Conf['Advance on contract']) { + while (next = $.x("following::div[contains(@class,'postContainer')][1]", root)) { + if (!($('.stub', next) || next.offsetHeight === 0)) { + break; + } + } + } + rect = (next || 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 25105dd72..53d11f035 100644 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -62,11 +62,11 @@ ImageExpand = # Scroll back to the thumbnail when contracting the image # to avoid being left miles away from the relevant post. {root} = post.nodes - rect = (if Conf['Advance on contract'] - $.x("following::div[contains(@class,'postContainer')][1]", root) or root - else - root - ).getBoundingClientRect() + 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() if rect.top < 0 y = rect.top From 9159f7adbc199a49ad83fcd0d0bca8d2b267d0f7 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 6 Aug 2013 14:16:49 -0700 Subject: [PATCH 8/8] 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