Don't scroll back when contracting an image if the image isn't partially visible. Close #859

This commit is contained in:
Nicolas Stepien 2012-12-16 12:22:47 +01:00
parent 763311f7dd
commit 363ea695d7
2 changed files with 24 additions and 19 deletions

View File

@ -5094,6 +5094,7 @@
thumb = a.firstChild; thumb = a.firstChild;
if (thumb.hidden) { if (thumb.hidden) {
rect = a.getBoundingClientRect(); rect = a.getBoundingClientRect();
if (rect.bottom > 0) {
if ($.engine === 'webkit') { if ($.engine === 'webkit') {
if (rect.top < 0) { if (rect.top < 0) {
d.body.scrollTop += rect.top - 42; d.body.scrollTop += rect.top - 42;
@ -5109,6 +5110,7 @@
d.documentElement.scrollLeft += rect.left; d.documentElement.scrollLeft += rect.left;
} }
} }
}
return ImageExpand.contract(thumb); return ImageExpand.contract(thumb);
} else { } else {
return ImageExpand.expand(thumb); return ImageExpand.expand(thumb);

View File

@ -4116,6 +4116,9 @@ ImageExpand =
thumb = a.firstChild thumb = a.firstChild
if thumb.hidden if thumb.hidden
rect = a.getBoundingClientRect() rect = a.getBoundingClientRect()
if rect.bottom > 0 # should be at least partially visible.
# Scroll back to the thumbnail when contracting the image
# to avoid being left miles away from the relevant post.
if $.engine is 'webkit' if $.engine is 'webkit'
d.body.scrollTop += rect.top - 42 if rect.top < 0 d.body.scrollTop += rect.top - 42 if rect.top < 0
d.body.scrollLeft += rect.left if rect.left < 0 d.body.scrollLeft += rect.left if rect.left < 0