From e96354bc3e4531be672c3b218aeb963d63e90541 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Thu, 17 Jul 2014 19:19:48 -0700 Subject: [PATCH] Implement #673 --- builds/appchan-x.user.js | 22 +++++++++++++++------- builds/crx/script.js | 22 +++++++++++++++------- src/General/Config.coffee | 6 ++++-- src/Images/Gallery.coffee | 12 +++++++++--- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index ef2c74a0a..5c66946d1 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -255,7 +255,8 @@ gallery: { 'Hide Thumbnails': [false], 'Fit Width': [true], - 'Fit Height': [true] + 'Fit Height': [true], + 'Scroll to Post': [true] }, style: { Interface: { @@ -10523,7 +10524,7 @@ title: title }); thumb.dataset.id = Gallery.images.length; - thumb.dataset.post = $('a[title="Link to this post"]', post.nodes.info).href; + thumb.dataset.post = post.fullID; if (post.file.isVideo) { thumb.dataset.isVideo = true; } @@ -10562,7 +10563,7 @@ return cb(); }, open: function(e) { - var el, elType, file, name, nodes, rect, top, _base; + var el, elType, err, file, name, nodes, post, rect, top, _base, _ref; if (e) { e.preventDefault(); } @@ -10597,11 +10598,18 @@ top = rect.top; if (top > 0) { top += rect.height - doc.clientHeight; - if (top < 0) { - return; - } } - nodes.thumbs.scrollTop += top; + if (top > 0) { + nodes.thumbs.scrollTop += top; + } + try { + if (Conf['Scroll to Post'] && (post = (_ref = (post = g.posts[file.dataset.post])) != null ? _ref.nodes.root : void 0)) { + Header.scrollTo(post); + } + } catch (_error) { + err = _error; + console.log(err); + } return $.on(file, 'error', function() { return Gallery.cb.error(file, thumb); }); diff --git a/builds/crx/script.js b/builds/crx/script.js index 52050e3b1..cec106929 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -230,7 +230,8 @@ gallery: { 'Hide Thumbnails': [false], 'Fit Width': [true], - 'Fit Height': [true] + 'Fit Height': [true], + 'Scroll to Post': [true] }, style: { Interface: { @@ -10556,7 +10557,7 @@ title: title }); thumb.dataset.id = Gallery.images.length; - thumb.dataset.post = $('a[title="Link to this post"]', post.nodes.info).href; + thumb.dataset.post = post.fullID; if (post.file.isVideo) { thumb.dataset.isVideo = true; } @@ -10595,7 +10596,7 @@ return cb(); }, open: function(e) { - var el, elType, file, name, nodes, rect, top, _base; + var el, elType, err, file, name, nodes, post, rect, top, _base, _ref; if (e) { e.preventDefault(); } @@ -10630,11 +10631,18 @@ top = rect.top; if (top > 0) { top += rect.height - doc.clientHeight; - if (top < 0) { - return; - } } - nodes.thumbs.scrollTop += top; + if (top > 0) { + nodes.thumbs.scrollTop += top; + } + try { + if (Conf['Scroll to Post'] && (post = (_ref = (post = g.posts[file.dataset.post])) != null ? _ref.nodes.root : void 0)) { + Header.scrollTo(post); + } + } catch (_error) { + err = _error; + console.log(err); + } return $.on(file, 'error', function() { return Gallery.cb.error(file, thumb); }); diff --git a/src/General/Config.coffee b/src/General/Config.coffee index a69607194..d8c4f68b6 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -407,13 +407,15 @@ Config = 'Hide Thumbnails': [ false ] - # Fit Width =/= Fit width - 'Fit Width': [ + 'Fit Width': [ # 'Fit width' (lowercase W) belongs to Image Expansion. Engine limitations, heh. true ] 'Fit Height': [ true ] + 'Scroll to Post': [ + true + ] style: diff --git a/src/Images/Gallery.coffee b/src/Images/Gallery.coffee index 07cf03f7d..073935fc3 100644 --- a/src/Images/Gallery.coffee +++ b/src/Images/Gallery.coffee @@ -110,7 +110,7 @@ Gallery = title: title thumb.dataset.id = Gallery.images.length - thumb.dataset.post = $('a[title="Link to this post"]', post.nodes.info).href + thumb.dataset.post = post.fullID thumb.dataset.isVideo = true if post.file.isVideo thumbImg = post.file.thumb.cloneNode false @@ -172,9 +172,15 @@ Gallery = {top} = rect if top > 0 top += rect.height - doc.clientHeight - return if top < 0 - nodes.thumbs.scrollTop += top + nodes.thumbs.scrollTop += top if top > 0 + + # Scroll to post + try + if Conf['Scroll to Post'] and post = (post = g.posts[file.dataset.post])?.nodes.root + Header.scrollTo post + catch err + console.log err $.on file, 'error', -> Gallery.cb.error file, thumb