Multifile support in Gallery. #2171

This commit is contained in:
ccd0 2019-07-15 21:03:18 -07:00
parent 7b02e10cd5
commit b86a2e917a

View File

@ -19,13 +19,13 @@ Gallery =
cb: @node cb: @node
node: -> node: ->
return unless @file?.thumb for file in @files when file.thumb
if Gallery.nodes if Gallery.nodes
Gallery.generateThumb @ Gallery.generateThumb @, file
Gallery.nodes.total.textContent = Gallery.images.length Gallery.nodes.total.textContent = Gallery.images.length
unless Conf['Image Expansion'] unless Conf['Image Expansion']
$.on @file.thumbLink, 'click', Gallery.cb.image $.on file.thumbLink, 'click', Gallery.cb.image
build: (image) -> build: (image) ->
{cb} = Gallery {cb} = Gallery
@ -38,7 +38,7 @@ Gallery =
Gallery.images = [] Gallery.images = []
nodes = Gallery.nodes = {} nodes = Gallery.nodes = {}
Gallery.fullIDs = {} Gallery.fileIDs = {}
Gallery.slideshow = false Gallery.slideshow = false
nodes.el = dialog = $.el 'div', nodes.el = dialog = $.el 'div',
@ -84,13 +84,13 @@ Gallery =
for postThumb in $$ g.SITE.selectors.file.thumb for postThumb in $$ g.SITE.selectors.file.thumb
continue unless (post = Get.postFromNode postThumb) continue unless (post = Get.postFromNode postThumb)
continue unless post.file?.thumb for file in post.files when file.thumb
Gallery.generateThumb post Gallery.generateThumb post, file
# If no image to open is given, pick image we have scrolled to. # If no image to open is given, pick image we have scrolled to.
if !image and Gallery.fullIDs[post.fullID] if !image and Gallery.fileIDs["#{post.fullID}.#{file.index}"]
candidate = post.file.thumbLink candidate = file.thumbLink
if Header.getTopOf(candidate) + candidate.getBoundingClientRect().height >= 0 if Header.getTopOf(candidate) + candidate.getBoundingClientRect().height >= 0
image = candidate image = candidate
$.addClass doc, 'gallery-open' $.addClass doc, 'gallery-open'
$.add d.body, dialog $.add d.body, dialog
@ -105,23 +105,24 @@ Gallery =
doc.style.overflow = 'hidden' doc.style.overflow = 'hidden'
nodes.total.textContent = Gallery.images.length nodes.total.textContent = Gallery.images.length
generateThumb: (post) -> generateThumb: (post, file) ->
return if post.isClone or post.isHidden return if post.isClone or post.isHidden
return unless post.file and post.file.thumb and (post.file.isImage or post.file.isVideo or Conf['PDF in Gallery']) return unless file and file.thumb and (file.isImage or file.isVideo or Conf['PDF in Gallery'])
return if Gallery.fullIDs[post.fullID] return if Gallery.fileIDs["#{post.fullID}.#{file.index}"]
Gallery.fullIDs[post.fullID] = true Gallery.fileIDs["#{post.fullID}.#{file.index}"] = true
thumb = $.el 'a', thumb = $.el 'a',
className: 'gal-thumb' className: 'gal-thumb'
href: post.file.url href: file.url
target: '_blank' target: '_blank'
title: post.file.name title: file.name
thumb.dataset.id = Gallery.images.length thumb.dataset.id = Gallery.images.length
thumb.dataset.post = post.fullID thumb.dataset.post = post.fullID
thumb.dataset.file = file.index
thumbImg = post.file.thumb.cloneNode false thumbImg = file.thumb.cloneNode false
thumbImg.style.cssText = '' thumbImg.style.cssText = ''
$.add thumb, thumbImg $.add thumb, thumbImg
@ -196,7 +197,7 @@ Gallery =
return new Notice 'error', 'Corrupt or unplayable video', 30 return new Notice 'error', 'Corrupt or unplayable video', 30
return if ImageCommon.isFromArchive @ return if ImageCommon.isFromArchive @
post = g.posts[@dataset.post] post = g.posts[@dataset.post]
file = post.file file = post.files[@dataset.file]
ImageCommon.error @, post, file, null, (url) => ImageCommon.error @, post, file, null, (url) =>
return unless url return unless url
Gallery.images[@dataset.id].href = url Gallery.images[@dataset.id].href = url
@ -311,7 +312,7 @@ Gallery =
d.mozCancelFullScreen?() d.mozCancelFullScreen?()
d.webkitExitFullscreen?() d.webkitExitFullscreen?()
delete Gallery.nodes delete Gallery.nodes
delete Gallery.fullIDs delete Gallery.fileIDs
doc.style.overflow = '' doc.style.overflow = ''
$.off d, 'keydown', Gallery.cb.keybinds $.off d, 'keydown', Gallery.cb.keybinds