Wait for the video metadata to be loaded before completing the expansion.

This commit is contained in:
Mayhem 2014-04-07 09:45:33 +02:00
parent 480ffba15c
commit 40d8d06266

View File

@ -14,16 +14,15 @@ ImageExpand =
cb: @node cb: @node
node: -> node: ->
return unless @file and (@file.isImage or @file.isVideo) return unless @file and (@file.isImage or @file.isVideo)
{thumb} = @file $.on @file.thumb.parentNode, 'click', ImageExpand.cb.toggle
$.on thumb.parentNode, 'click', ImageExpand.cb.toggle
if @isClone if @isClone
if @file.isImage and $.hasClass thumb, 'expanding' if @file.isImage and $.hasClass @file.thumb, 'expanding'
# If we clone a post where the image is still loading, # If we clone a post where the image is still loading,
# make it loading in the clone too. # make it loading in the clone too.
ImageExpand.contract @ ImageExpand.contract @
ImageExpand.expand @ ImageExpand.expand @
return return
if @file.isVideo and $.hasClass @nodes.root, 'expanded-image' if @file.isVideo and @file.isExpanded
@file.fullImage.play() @file.fullImage.play()
return return
if ImageExpand.on and !@isHidden and (Conf['Expand spoilers'] or !@file.isSpoiler) if ImageExpand.on and !@isHidden and (Conf['Expand spoilers'] or !@file.isSpoiler)
@ -76,7 +75,7 @@ ImageExpand =
$.rmClass post.nodes.root, 'expanded-image' $.rmClass post.nodes.root, 'expanded-image'
$.rmClass post.file.thumb, 'expanding' $.rmClass post.file.thumb, 'expanding'
post.file.isExpanded = false post.file.isExpanded = false
post.file.fullImage.pause() if post.file.isVideo post.file.fullImage.pause() if post.file.isVideo and post.file.fullImage
expand: (post, src) -> expand: (post, src) ->
# Do not expand images of hidden/filtered replies, or already expanded pictures. # Do not expand images of hidden/filtered replies, or already expanded pictures.
@ -85,10 +84,9 @@ ImageExpand =
$.addClass thumb, 'expanding' $.addClass thumb, 'expanding'
if post.file.fullImage if post.file.fullImage
# Expand already-loaded/ing picture. # Expand already-loaded/ing picture.
$.asap (-> post.file.isVideo or post.file.fullImage.naturalHeight), -> ImageExpand.waitExpand post
ImageExpand.completeExpand post
return return
file = if post.file.isImage post.file.fullImage = file = if post.file.isImage
$.el 'img', $.el 'img',
className: 'full-image' className: 'full-image'
src: src or post.file.URL src: src or post.file.URL
@ -97,12 +95,24 @@ ImageExpand =
className: 'full-image' className: 'full-image'
src: src or post.file.URL src: src or post.file.URL
loop: true loop: true
post.file.fullImage = file
$.on file, 'error', ImageExpand.error $.on file, 'error', ImageExpand.error
$.asap (-> post.file.isVideo or post.file.fullImage.naturalHeight), -> ImageExpand.waitExpand post
ImageExpand.completeExpand post
$.after thumb, file $.after thumb, file
waitExpand: (post) ->
if post.file.isReady
ImageExpand.completeExpand post
else if post.file.isImage
$.asap (-> post.file.fullImage.naturalHeight), ->
post.file.isReady = true
ImageExpand.completeExpand post
else if post.file.isVideo
complete = ->
$.off post.file.fullImage, 'loadedmetadata', complete
post.file.isReady = true
ImageExpand.completeExpand post
$.on post.file.fullImage, 'loadedmetadata', complete
completeExpand: (post) -> completeExpand: (post) ->
{thumb} = post.file {thumb} = post.file
return unless $.hasClass thumb, 'expanding' # contracted before the image loaded return unless $.hasClass thumb, 'expanding' # contracted before the image loaded
@ -123,6 +133,7 @@ ImageExpand =
error: -> error: ->
post = Get.postFromNode @ post = Get.postFromNode @
post.file.isReady = false
$.rm @ $.rm @
delete post.file.fullImage delete post.file.fullImage
# Images can error: # Images can error: