Make gallery open at the image we've scrolled to.

Also fixes a bug with spoilered image file names.
This commit is contained in:
ccd0 2014-08-13 00:38:36 -07:00
parent b7b5e49221
commit c9d2f66d42

View File

@ -22,7 +22,7 @@ Gallery =
node: -> node: ->
return unless @file return unless @file
if Gallery.nodes if Gallery.nodes
Gallery.generateThumb $ '.file', @nodes.root Gallery.generateThumb @
Gallery.nodes.total.textContent = Gallery.images.length Gallery.nodes.total.textContent = Gallery.images.length
unless Conf['Image Expansion'] unless Conf['Image Expansion']
@ -70,7 +70,14 @@ Gallery =
$.on d, 'keydown', cb.keybinds $.on d, 'keydown', cb.keybinds
$.off d, 'keydown', Keybinds.keydown $.off d, 'keydown', Keybinds.keydown
Gallery.generateThumb file for file in $$ '.post .file' when !$ '.fileDeletedRes, .fileDeleted', file for file in $$ '.post .file' when !$ '.fileDeletedRes, .fileDeleted', file
post = Get.postFromNode file
Gallery.generateThumb post
# If no image to open is given, pick image we have scrolled to.
if !image and Gallery.fullIDs[post.fullID]
{thumb} = post.file
if Header.getTopOf(thumb) + thumb.getBoundingClientRect().height >= 0
image = thumb.parentNode
$.add d.body, dialog $.add d.body, dialog
nodes.thumbs.scrollTop = 0 nodes.thumbs.scrollTop = 0
@ -84,19 +91,17 @@ Gallery =
d.body.style.overflow = 'hidden' d.body.style.overflow = 'hidden'
nodes.total.textContent = Gallery.images.length nodes.total.textContent = Gallery.images.length
generateThumb: (file) -> generateThumb: (post) ->
post = Get.postFromNode file
return if post.isClone or post.isHidden return if post.isClone or post.isHidden
return unless post.file and (post.file.isImage or post.file.isVideo or Conf['PDF in Gallery']) return unless post.file and (post.file.isImage or post.file.isVideo or Conf['PDF in Gallery'])
return if Gallery.fullIDs[post.fullID] return if Gallery.fullIDs[post.fullID]
Gallery.fullIDs[post.fullID] = true Gallery.fullIDs[post.fullID] = true
title = ($ '.fileText a', file).textContent
thumb = $.el 'a', thumb = $.el 'a',
className: 'gal-thumb' className: 'gal-thumb'
href: post.file.URL href: post.file.URL
target: '_blank' target: '_blank'
title: title title: post.file.name
thumb.dataset.id = Gallery.images.length thumb.dataset.id = Gallery.images.length
thumb.dataset.post = post.fullID thumb.dataset.post = post.fullID