From 2a1f482e66d0c1325fc03fb69ebb1a1eb7f72dd2 Mon Sep 17 00:00:00 2001 From: ahodesuka Date: Tue, 17 Jan 2012 23:39:38 -0600 Subject: [PATCH] Fix scroll offset when contracting images --- 4chan_x.user.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 6f59cf6ff..71db82528 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2960,7 +2960,7 @@ _results2 = []; for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { thumb = _ref2[_j]; - _results2.push(imgExpand.contract(thumb)); + _results2.push(imgExpand.contract(thumb, false)); } return _results2; } @@ -2994,13 +2994,23 @@ var thumb; thumb = a.firstChild; if (thumb.hidden) { - return imgExpand.contract(thumb); + return imgExpand.contract(thumb, true); } else { return imgExpand.expand(thumb); } }, - contract: function(thumb) { + contract: function(thumb, bScroll) { thumb.hidden = false; + if (bScroll) { + var el, top; + el = thumb.parentNode.parentNode; + top = el.offsetTop; + while (el.offsetParent) { + el = el.offsetParent; + top += el.offsetTop; + } + if (top < window.scrollY) window.scroll(window.scrollX, top); + } return $.rm(thumb.nextSibling); }, expand: function(thumb, url) { @@ -3021,7 +3031,7 @@ error: function() { var req, src, thumb, url; thumb = this.previousSibling; - imgExpand.contract(thumb); + imgExpand.contract(thumb, true); src = this.src.split('/'); if (url = redirect.image(src[3], src[5])) { return imgExpand.expand(thumb, url);