diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 8f3d0882e..b75bfd0b8 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -6665,11 +6665,14 @@ return cb(); }, open: function(e) { - var el, img, name, nodes; + var el, img, name, nodes, rect, top; if (e) { e.preventDefault(); } + if (!this) { + return; + } nodes = Gallery.nodes; name = nodes.name; if (el = $('.gal-highlight', Gallery.thumbs)) { @@ -6685,7 +6688,16 @@ nodes.count.textContent = +this.dataset.id + 1; nodes.current = img; nodes.frame.scrollTop = 0; - return nodes.current.focus(); + nodes.current.focus(); + rect = this.getBoundingClientRect(); + top = rect.top; + if (top > 0) { + top += rect.height - doc.clientHeight; + if (top < 0) { + return; + } + } + return nodes.thumbs.scrollTop += top; }, image: function(e) { e.preventDefault(); diff --git a/builds/crx/script.js b/builds/crx/script.js index 613ef3d3d..26204303f 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -6650,11 +6650,14 @@ return cb(); }, open: function(e) { - var el, img, name, nodes; + var el, img, name, nodes, rect, top; if (e) { e.preventDefault(); } + if (!this) { + return; + } nodes = Gallery.nodes; name = nodes.name; if (el = $('.gal-highlight', Gallery.thumbs)) { @@ -6670,7 +6673,16 @@ nodes.count.textContent = +this.dataset.id + 1; nodes.current = img; nodes.frame.scrollTop = 0; - return nodes.current.focus(); + nodes.current.focus(); + rect = this.getBoundingClientRect(); + top = rect.top; + if (top > 0) { + top += rect.height - doc.clientHeight; + if (top < 0) { + return; + } + } + return nodes.thumbs.scrollTop += top; }, image: function(e) { e.preventDefault(); diff --git a/src/Images/Gallery.coffee b/src/Images/Gallery.coffee index 98a66d347..197f0a4b8 100644 --- a/src/Images/Gallery.coffee +++ b/src/Images/Gallery.coffee @@ -1,7 +1,7 @@ Gallery = init: -> return if g.VIEW is 'catalog' or g.BOARD is 'f' or !Conf['Gallery'] - + el = $.el 'a', href: 'javascript:;' id: 'appchan-gal' @@ -58,7 +58,7 @@ Gallery = next: '.gal-image a' current: '.gal-image img' } - + menuButton = $ '.menu-button', dialog nodes.menu = new UI.Menu 'gallery' @@ -135,9 +135,11 @@ Gallery = e.stopPropagation() e.preventDefault() cb() - + open: (e) -> e.preventDefault() if e + return unless @ + {nodes} = Gallery {name} = nodes @@ -155,6 +157,15 @@ Gallery = nodes.frame.scrollTop = 0 nodes.current.focus() + # Scroll + rect = @getBoundingClientRect() + {top} = rect + if top > 0 + top += rect.height - doc.clientHeight + return if top < 0 + + nodes.thumbs.scrollTop += top + image: (e) -> e.preventDefault() e.stopPropagation()