Changed offset fix for only images that are larger than the viewport

This commit is contained in:
ahodesuka 2012-01-18 16:16:01 -06:00
parent 2a1f482e66
commit 7a2343f6c5
2 changed files with 19 additions and 15 deletions

View File

@ -2960,7 +2960,7 @@
_results2 = []; _results2 = [];
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
thumb = _ref2[_j]; thumb = _ref2[_j];
_results2.push(imgExpand.contract(thumb, false)); _results2.push(imgExpand.contract(thumb));
} }
return _results2; return _results2;
} }
@ -2991,26 +2991,24 @@
} }
}, },
toggle: function(a) { toggle: function(a) {
var thumb; var el, thumb, top;
thumb = a.firstChild; thumb = a.firstChild;
if (thumb.hidden) { if (thumb.hidden) {
return imgExpand.contract(thumb, true); if (thumb.nextSibling.offsetHeight > window.innerHeight) {
el = thumb.nextSibling;
top = el.offsetTop;
while (el = el.offsetParent) {
top += el.offsetTop;
}
if (top < window.scrollY) window.scroll(window.scrollX, top);
}
return imgExpand.contract(thumb);
} else { } else {
return imgExpand.expand(thumb); return imgExpand.expand(thumb);
} }
}, },
contract: function(thumb, bScroll) { contract: function(thumb) {
thumb.hidden = false; 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); return $.rm(thumb.nextSibling);
}, },
expand: function(thumb, url) { expand: function(thumb, url) {
@ -3031,7 +3029,7 @@
error: function() { error: function() {
var req, src, thumb, url; var req, src, thumb, url;
thumb = this.previousSibling; thumb = this.previousSibling;
imgExpand.contract(thumb, true); imgExpand.contract(thumb);
src = this.src.split('/'); src = this.src.split('/');
if (url = redirect.image(src[3], src[5])) { if (url = redirect.image(src[3], src[5])) {
return imgExpand.expand(thumb, url); return imgExpand.expand(thumb, url);

View File

@ -2316,6 +2316,12 @@ imgExpand =
toggle: (a) -> toggle: (a) ->
thumb = a.firstChild thumb = a.firstChild
if thumb.hidden if thumb.hidden
if thumb.nextSibling.offsetHeight > window.innerHeight
el = thumb.nextSibling
top = el.offsetTop
while el = el.offsetParent
top += el.offsetTop
window.scroll window.scrollX, top if top < window.scrollY
imgExpand.contract thumb imgExpand.contract thumb
else else
imgExpand.expand thumb imgExpand.expand thumb