Refactor ImageExpand.waitExpand():
- wait for the first frame to be loaded instead of the metadata before expanding. - to my understanding, browsers will not always start the download immediately if the video isn't on autoplay, force it with load().
This commit is contained in:
parent
445edcf867
commit
7c97b11601
@ -94,14 +94,12 @@ ImageExpand =
|
|||||||
ImageExpand.waitExpand post
|
ImageExpand.waitExpand post
|
||||||
return
|
return
|
||||||
post.file.fullImage = file = if post.file.isImage
|
post.file.fullImage = file = if post.file.isImage
|
||||||
$.el 'img',
|
$.el 'img'
|
||||||
className: 'full-image'
|
|
||||||
src: src or post.file.URL
|
|
||||||
else
|
else
|
||||||
$.el 'video',
|
$.el 'video',
|
||||||
className: 'full-image'
|
|
||||||
src: src or post.file.URL
|
|
||||||
loop: true
|
loop: true
|
||||||
|
file.className = 'full-image'
|
||||||
|
file.src = src or post.file.URL
|
||||||
$.on file, 'error', ImageExpand.error
|
$.on file, 'error', ImageExpand.error
|
||||||
ImageExpand.waitExpand post
|
ImageExpand.waitExpand post
|
||||||
$.after post.file.thumb, file
|
$.after post.file.thumb, file
|
||||||
@ -113,18 +111,26 @@ ImageExpand =
|
|||||||
return
|
return
|
||||||
|
|
||||||
$.addClass post.file.thumb, 'expanding'
|
$.addClass post.file.thumb, 'expanding'
|
||||||
|
file = post.file.fullImage
|
||||||
|
|
||||||
if post.file.isImage
|
if post.file.isImage
|
||||||
$.asap (-> post.file.fullImage.naturalHeight), ->
|
$.asap (-> file.naturalHeight), ->
|
||||||
post.file.isReady = true
|
|
||||||
ImageExpand.completeExpand post
|
ImageExpand.completeExpand post
|
||||||
else if post.file.isVideo
|
return
|
||||||
complete = ->
|
|
||||||
$.off post.file.fullImage, 'loadedmetadata', complete
|
# Expand the video when the first frame is available.
|
||||||
post.file.isReady = true
|
if file.readyState >= file.HAVE_CURRENT_DATA
|
||||||
ImageExpand.completeExpand post
|
ImageExpand.completeExpand post
|
||||||
$.on post.file.fullImage, 'loadedmetadata', complete
|
return
|
||||||
|
|
||||||
|
file.load() # Don't wait for the browser to lazily preload.
|
||||||
|
complete = ->
|
||||||
|
$.off file, 'loadeddata', complete
|
||||||
|
ImageExpand.completeExpand post
|
||||||
|
$.on file, 'loadeddata', complete
|
||||||
|
|
||||||
completeExpand: (post) ->
|
completeExpand: (post) ->
|
||||||
|
post.file.isReady = true
|
||||||
{thumb} = post.file
|
{thumb} = post.file
|
||||||
return unless post.file.isExpanding # contracted before the image loaded
|
return unless post.file.isExpanding # contracted before the image loaded
|
||||||
delete post.file.isExpanding
|
delete post.file.isExpanding
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user