better approach to rewinding, and restore rewind on expand if not from hover

This commit is contained in:
ccd0 2014-09-27 14:20:59 -07:00
parent cb50f17567
commit 6c9757632f
3 changed files with 8 additions and 11 deletions

View File

@ -1,14 +1,9 @@
ImageCommon =
rewind: (post, el) ->
{file} = post
{thumb} = file
if file.isVideo
rewind: (el) ->
if el.nodeName is 'VIDEO'
el.currentTime = 0 if el.readyState >= el.HAVE_METADATA
thumb.currentTime = 0 if file.videoThumb and thumb.readyState >= thumb.HAVE_METADATA
else if /\.gif$/.test el.src
$.queueTask ->
el.src = el.src
thumb.src = thumb.src
$.queueTask -> el.src = el.src
pushCache: (el) ->
ImageCommon.cache = el

View File

@ -140,7 +140,7 @@ ImageExpand =
el.pause()
for eventName, cb of ImageExpand.videoCB
$.off el, eventName, cb
ImageCommon.rewind post, el
ImageCommon.rewind file.thumb
delete file.fullImage
$.queueTask ->
# XXX Work around Chrome/Chromium not firing mouseover on the thumbnail.
@ -163,6 +163,8 @@ ImageExpand =
else if ImageCommon.cache?.dataset.fullID is post.fullID
el = file.fullImage = ImageCommon.popCache()
$.on el, 'error', ImageExpand.error
ImageCommon.rewind el unless el.id is 'ihover'
el.removeAttribute 'id'
else
el = file.fullImage = $.el (if isVideo then 'video' else 'img')
el.dataset.fullID = post.fullID

View File

@ -30,7 +30,8 @@ ImageHover =
el.dataset.fullID = post.fullID
$.on el, 'error', error
el.src = file.URL
ImageCommon.rewind post, el
ImageCommon.rewind el
ImageCommon.rewind @
el.id = 'ihover'
$.after Header.hover, el
if isVideo
@ -58,7 +59,6 @@ ImageHover =
ImageCommon.pushCache el
el.pause() if isVideo
$.rm el
el.removeAttribute 'id'
el.removeAttribute 'style'
error: (post) -> ->
return if ImageCommon.decodeError @, post