From 3abff121eec9197a16b46a255a8b2722d64593c7 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sat, 2 Mar 2013 23:28:26 +0100 Subject: [PATCH] Don't scroll out visible posts when invisible images get expanded. Close #938 --- 4chan_x.user.js | 12 +++++++----- src/features.coffee | 10 ++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index d6af90ff2..146a9a15e 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -4543,13 +4543,15 @@ return $.after(thumb, img); }, completeExpand: function(post) { - var thumb; + var rect, root, thumb; thumb = post.file.thumb; - if (!$.hasClass(thumb, 'expanding')) { - return; - } + rect = post.nodes.root.getBoundingClientRect(); $.addClass(post.nodes.root, 'expanded-image'); - $.rmClass(thumb, 'expanding'); + $.rmClass(post.file.thumb, 'expanding'); + if (rect.top + rect.height <= 0) { + root = $.engine === 'webkit' ? d.body : doc; + root.scrollTop += post.nodes.root.clientHeight - rect.height; + } return post.file.isExpanded = true; }, error: function() { diff --git a/src/features.coffee b/src/features.coffee index 579bfb4ec..4b5834eea 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -3023,9 +3023,15 @@ ImageExpand = completeExpand: (post) -> {thumb} = post.file - return unless $.hasClass thumb, 'expanding' + rect = post.nodes.root.getBoundingClientRect() $.addClass post.nodes.root, 'expanded-image' - $.rmClass thumb, 'expanding' + $.rmClass post.file.thumb, 'expanding' + if rect.top + rect.height <= 0 + root = if $.engine is 'webkit' + d.body + else + doc + root.scrollTop += post.nodes.root.clientHeight - rect.height post.file.isExpanded = true error: ->