Preload next image in gallery. #353
This commit is contained in:
parent
c4530be148
commit
0bfbfc6b18
@ -128,43 +128,55 @@ Gallery =
|
|||||||
Gallery.images.push thumb
|
Gallery.images.push thumb
|
||||||
$.add Gallery.nodes.thumbs, thumb
|
$.add Gallery.nodes.thumbs, thumb
|
||||||
|
|
||||||
|
load: (thumb, errorCB) ->
|
||||||
|
ext = thumb.href.match /\w*$/
|
||||||
|
elType = {'webm': 'video', 'pdf': 'iframe'}[ext] or 'img'
|
||||||
|
file = $.el elType,
|
||||||
|
title: thumb.title
|
||||||
|
$.extend file.dataset, thumb.dataset
|
||||||
|
$.on file, 'error', errorCB
|
||||||
|
file.src = thumb.href
|
||||||
|
file
|
||||||
|
|
||||||
open: (thumb) ->
|
open: (thumb) ->
|
||||||
{nodes} = Gallery
|
{nodes} = Gallery
|
||||||
{name} = nodes
|
|
||||||
oldID = +nodes.current.dataset.id
|
oldID = +nodes.current.dataset.id
|
||||||
newID = +thumb.dataset.id
|
newID = +thumb.dataset.id
|
||||||
slideshow = Gallery.slideshow and (newID > oldID or (oldID is Gallery.images.length-1 and newID is 0))
|
|
||||||
|
|
||||||
|
# Highlight, center selected thumbnail
|
||||||
$.rmClass el, 'gal-highlight' if el = $ '.gal-highlight', nodes.thumbs
|
$.rmClass el, 'gal-highlight' if el = $ '.gal-highlight', nodes.thumbs
|
||||||
$.addClass thumb, 'gal-highlight'
|
$.addClass thumb, 'gal-highlight'
|
||||||
|
nodes.thumbs.scrollTop = thumb.offsetTop + thumb.offsetHeight/2 - nodes.thumbs.clientHeight/2
|
||||||
|
|
||||||
elType = if /\.webm$/.test(thumb.href)
|
# Load image or use preloaded image
|
||||||
'video'
|
if Gallery.cache?.dataset.id is ''+newID
|
||||||
else if /\.pdf$/.test(thumb.href)
|
file = Gallery.cache
|
||||||
'iframe'
|
$.off file, 'error', Gallery.cacheError
|
||||||
|
$.on file, 'error', Gallery.error
|
||||||
else
|
else
|
||||||
'img'
|
file = Gallery.load thumb, Gallery.error
|
||||||
|
|
||||||
$[if elType is 'iframe' then 'addClass' else 'rmClass'] doc, 'gal-pdf'
|
|
||||||
file = $.el elType,
|
|
||||||
title: name.download = name.textContent = thumb.title
|
|
||||||
$.extend file.dataset, thumb.dataset
|
|
||||||
$.on file, 'error', Gallery.error
|
|
||||||
file.src = name.href = thumb.href
|
|
||||||
|
|
||||||
|
# Replace old image with new one
|
||||||
$.off nodes.current, 'error', Gallery.error
|
$.off nodes.current, 'error', Gallery.error
|
||||||
ImageCommon.pause nodes.current
|
ImageCommon.pause nodes.current
|
||||||
$.replace nodes.current, file
|
$.replace nodes.current, file
|
||||||
if elType is 'video'
|
nodes.current = file
|
||||||
|
|
||||||
|
if file.nodeName is 'VIDEO'
|
||||||
file.loop = true
|
file.loop = true
|
||||||
Volume.setup file
|
Volume.setup file
|
||||||
file.play() if Conf['Autoplay']
|
file.play() if Conf['Autoplay']
|
||||||
ImageCommon.addControls file if Conf['Show Controls']
|
ImageCommon.addControls file if Conf['Show Controls']
|
||||||
|
|
||||||
|
doc.classList.toggle 'gal-pdf', file.nodeName is 'IFRAME'
|
||||||
nodes.count.textContent = +thumb.dataset.id + 1
|
nodes.count.textContent = +thumb.dataset.id + 1
|
||||||
nodes.current = file
|
nodes.name.download = nodes.name.textContent = thumb.title
|
||||||
|
nodes.name.href = thumb.href
|
||||||
nodes.frame.scrollTop = 0
|
nodes.frame.scrollTop = 0
|
||||||
nodes.next.focus()
|
nodes.next.focus()
|
||||||
if slideshow
|
|
||||||
|
# Continue slideshow if moving forward, stop otherwise
|
||||||
|
if Gallery.slideshow and (newID > oldID or (oldID is Gallery.images.length-1 and newID is 0))
|
||||||
Gallery.setupTimer()
|
Gallery.setupTimer()
|
||||||
else
|
else
|
||||||
Gallery.cb.stop()
|
Gallery.cb.stop()
|
||||||
@ -173,8 +185,8 @@ Gallery =
|
|||||||
if Conf['Scroll to Post'] and (post = g.posts[file.dataset.post])
|
if Conf['Scroll to Post'] and (post = g.posts[file.dataset.post])
|
||||||
Header.scrollTo post.nodes.root
|
Header.scrollTo post.nodes.root
|
||||||
|
|
||||||
# Center selected thumbnail
|
# Preload next image
|
||||||
nodes.thumbs.scrollTop = thumb.offsetTop + thumb.offsetHeight/2 - nodes.thumbs.clientHeight/2
|
Gallery.cache = Gallery.load Gallery.images[(newID + 1) % Gallery.images.length], Gallery.cacheError
|
||||||
|
|
||||||
error: ->
|
error: ->
|
||||||
if @error?.code is MediaError.MEDIA_ERR_DECODE
|
if @error?.code is MediaError.MEDIA_ERR_DECODE
|
||||||
@ -185,6 +197,9 @@ Gallery =
|
|||||||
Gallery.images[@dataset.id].href = url
|
Gallery.images[@dataset.id].href = url
|
||||||
@src = url if Gallery.nodes.current is @
|
@src = url if Gallery.nodes.current is @
|
||||||
|
|
||||||
|
cacheError: ->
|
||||||
|
delete Gallery.cache
|
||||||
|
|
||||||
cleanupTimer: ->
|
cleanupTimer: ->
|
||||||
clearTimeout Gallery.timeoutID
|
clearTimeout Gallery.timeoutID
|
||||||
{current} = Gallery.nodes
|
{current} = Gallery.nodes
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user