Pause and mute videos when removing them from the document.

This commit is contained in:
ccd0 2015-02-04 01:33:21 -08:00
parent a59a036a07
commit b74cf487f6
5 changed files with 15 additions and 10 deletions

View File

@ -152,7 +152,7 @@ Gallery =
file.src = name.href = thumb.href
$.off nodes.current, 'error', Gallery.error
nodes.current.pause?()
ImageCommon.pause nodes.current
$.replace nodes.current, file
if elType is 'video'
file.loop = true
@ -282,7 +282,7 @@ Gallery =
close: ->
$.off Gallery.nodes.current, 'error', Gallery.error
Gallery.nodes.current.pause?()
ImageCommon.pause Gallery.nodes.current
$.rm Gallery.nodes.el
$.rmClass doc, 'gallery-open'
if Conf['Fullscreen Gallery']

View File

@ -1,4 +1,11 @@
ImageCommon =
# Pause and mute video in preparation for removing the element from the document.
pause: (video) ->
return unless video.nodeName is 'VIDEO'
video.pause()
$.off video, 'volumechange', Volume.change
video.muted = true
rewind: (el) ->
if el.nodeName is 'VIDEO'
el.currentTime = 0 if el.readyState >= el.HAVE_METADATA

View File

@ -143,7 +143,7 @@ ImageExpand =
$.off el, 'error', ImageExpand.error
ImageCommon.pushCache el
if file.isVideo
el.pause()
ImageCommon.pause el
for eventName, cb of ImageExpand.videoCB
$.off el, eventName, cb
ImageCommon.rewind file.thumb if Conf['Restart when Opened']
@ -172,7 +172,6 @@ ImageExpand =
ImageCommon.rewind el if Conf['Restart when Opened'] and el.id isnt 'ihover'
el.removeAttribute 'id'
else
isNew = true
el = file.fullImage = $.el (if isVideo then 'video' else 'img')
el.dataset.fullID = post.fullID
$.on el, 'error', ImageExpand.error
@ -192,7 +191,7 @@ ImageExpand =
thumb.parentNode.removeAttribute 'target'
el.loop = true
Volume.setup el, isNew
Volume.setup el
ImageExpand.setupVideoCB post
if !isVideo

View File

@ -31,7 +31,6 @@ ImageHover =
el = ImageCommon.popCache()
$.on el, 'error', error
else
isNew = true
el = $.el (if isVideo then 'video' else 'img')
el.dataset.fullID = post.fullID
$.on el, 'error', error
@ -45,7 +44,7 @@ ImageHover =
if isVideo
el.loop = true
el.controls = false
Volume.setup el, isNew
Volume.setup el
el.play() if Conf['Autoplay']
[width, height] = (+x for x in file.dimensions.split 'x')
{left, right} = @getBoundingClientRect()
@ -66,7 +65,7 @@ ImageHover =
cb: ->
$.off el, 'error', error
ImageCommon.pushCache el
el.pause() if isVideo
ImageCommon.pause el
$.rm el
el.removeAttribute 'style'

View File

@ -31,10 +31,10 @@ Volume =
Header.menu.addEntry {el: unmuteEntry, order: 200}
Header.menu.addEntry {el: volumeEntry, order: 201}
setup: (video, isNew=true) ->
setup: (video) ->
video.muted = !Conf['Allow Sound']
video.volume = Conf['Default Volume']
$.on video, 'volumechange', Volume.change if isNew
$.on video, 'volumechange', Volume.change
change: ->
{muted, volume} = @