diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 6dbe56c2c..ca9224a93 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -1787,9 +1787,9 @@ top = post.getBoundingClientRect().top; if (Conf['Fixed Header'] && !Conf['Bottom Header']) { headRect = Header.bar.getBoundingClientRect(); - top += -headRect.top - headRect.height; + top -= headRect.top + headRect.height; } - return doc.scrollTop += top; + return window.scrollBy(0, top); }, addShortcut: function(el) { var shortcut; @@ -2351,8 +2351,8 @@ $.add(Header.hover, menu); 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; _ref1 = bRect.top + bRect.height + mRect.height < cHeight ? [bRect.bottom, null] : [null, cHeight - bRect.top], top = _ref1[0], bottom = _ref1[1]; @@ -6283,7 +6283,7 @@ } }, toggle: function(post) { - var headRect, node, rect, root, thumb, top; + var headRect, node, rect, thumb, x, y; thumb = post.file.thumb; if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { @@ -6309,17 +6309,18 @@ if (!(rect.top <= 0 || rect.left <= 0)) { return; } - top = rect.top; - if (Conf['Fixed Header'] && !Conf['Bottom Header']) { - headRect = Header.bar.getBoundingClientRect(); - top += -headRect.top - headRect.height; - } - root = doc; if (rect.top < 0) { - root.scrollTop += top; + y = rect.top; + if (Conf['Fixed Header'] && !Conf['Bottom Header']) { + headRect = Header.toggle.getBoundingClientRect(); + y -= headRect.top + headRect.height; + } } if (rect.left < 0) { - return root.scrollLeft = 0; + x = -window.scrollX; + } + if (x || y) { + return window.scrollBy(x, y); } }, contract: function(post) { @@ -6370,16 +6371,15 @@ } prev = post.nodes.root.getBoundingClientRect(); return $.queueTask(function() { - var curr, root; + var curr; $.addClass(post.nodes.root, 'expanded-image'); $.rmClass(post.file.thumb, 'expanding'); if (!(prev.top + prev.height <= 0)) { return; } - root = doc; curr = post.nodes.root.getBoundingClientRect(); - return root.scrollTop += curr.height - prev.height + curr.top - prev.top; + return window.scrollBy(0, curr.height - prev.height + curr.top - prev.top); }); }, error: function() { @@ -7613,7 +7613,7 @@ } if (scroll) { if (Conf['Bottom Scroll']) { - doc.scrollTop = d.body.clientHeight; + window.scrollTo(0, d.body.clientHeight); } else { if (root) { Header.scrollToPost(root); diff --git a/builds/crx/script.js b/builds/crx/script.js index 593d72a9f..d3384960c 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1798,9 +1798,9 @@ top = post.getBoundingClientRect().top; if (Conf['Fixed Header'] && !Conf['Bottom Header']) { headRect = Header.bar.getBoundingClientRect(); - top += -headRect.top - headRect.height; + top -= headRect.top + headRect.height; } - return d.body.scrollTop += top; + return window.scrollBy(0, top); }, addShortcut: function(el) { var shortcut; @@ -2362,8 +2362,8 @@ $.add(Header.hover, menu); 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; _ref1 = bRect.top + bRect.height + mRect.height < cHeight ? [bRect.bottom, null] : [null, cHeight - bRect.top], top = _ref1[0], bottom = _ref1[1]; @@ -6263,7 +6263,7 @@ } }, toggle: function(post) { - var headRect, node, rect, root, thumb, top; + var headRect, node, rect, thumb, x, y; thumb = post.file.thumb; if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { @@ -6289,17 +6289,18 @@ if (!(rect.top <= 0 || rect.left <= 0)) { return; } - top = rect.top; - if (Conf['Fixed Header'] && !Conf['Bottom Header']) { - headRect = Header.bar.getBoundingClientRect(); - top += -headRect.top - headRect.height; - } - root = d.body; if (rect.top < 0) { - root.scrollTop += top; + y = rect.top; + if (Conf['Fixed Header'] && !Conf['Bottom Header']) { + headRect = Header.toggle.getBoundingClientRect(); + y -= headRect.top + headRect.height; + } } if (rect.left < 0) { - return root.scrollLeft = 0; + x = -window.scrollX; + } + if (x || y) { + return window.scrollBy(x, y); } }, contract: function(post) { @@ -6350,16 +6351,15 @@ } prev = post.nodes.root.getBoundingClientRect(); return $.queueTask(function() { - var curr, root; + var curr; $.addClass(post.nodes.root, 'expanded-image'); $.rmClass(post.file.thumb, 'expanding'); if (!(prev.top + prev.height <= 0)) { return; } - root = d.body; curr = post.nodes.root.getBoundingClientRect(); - return root.scrollTop += curr.height - prev.height + curr.top - prev.top; + return window.scrollBy(0, curr.height - prev.height + curr.top - prev.top); }); }, error: function() { @@ -7593,7 +7593,7 @@ } if (scroll) { if (Conf['Bottom Scroll']) { - d.body.scrollTop = d.body.clientHeight; + window.scrollTo(0, d.body.clientHeight); } else { if (root) { Header.scrollToPost(root); diff --git a/src/General/Header.coffee b/src/General/Header.coffee index 783b3f9fe..c1cea716a 100644 --- a/src/General/Header.coffee +++ b/src/General/Header.coffee @@ -302,8 +302,8 @@ Header = {top} = post.getBoundingClientRect() if Conf['Fixed Header'] and not Conf['Bottom Header'] headRect = Header.bar.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 f4bbc30a8..b016b7d5e 100644 --- a/src/General/UI.coffee +++ b/src/General/UI.coffee @@ -70,8 +70,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 c33c04732..afbfcd0a7 100644 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -60,6 +60,8 @@ ImageExpand = 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 @@ -71,15 +73,15 @@ ImageExpand = post.nodes.root.getBoundingClientRect() return unless rect.top <= 0 or rect.left <= 0 - {top} = rect - if Conf['Fixed Header'] and not Conf['Bottom Header'] - headRect = Header.bar.getBoundingClientRect() - top += - headRect.top - headRect.height + if rect.top < 0 + y = rect.top + if Conf['Fixed Header'] and not Conf['Bottom Header'] + headRect = Header.toggle.getBoundingClientRect() + y -= 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 + if rect.left < 0 + x = -window.scrollX + window.scrollBy x, y if x or y contract: (post) -> $.rmClass post.nodes.root, 'expanded-image' @@ -119,9 +121,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 165b498cb..ed4255104 100644 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -293,7 +293,6 @@ ThreadUpdater = unless count ThreadUpdater.set 'status', null, null ThreadUpdater.outdateCount++ - else ThreadUpdater.set 'status', "+#{count}", 'new' ThreadUpdater.outdateCount = 0 @@ -319,7 +318,7 @@ ThreadUpdater = 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 root if root