Pause and mute videos when removing them from the document.
This commit is contained in:
parent
a59a036a07
commit
b74cf487f6
@ -152,7 +152,7 @@ Gallery =
|
|||||||
file.src = name.href = thumb.href
|
file.src = name.href = thumb.href
|
||||||
|
|
||||||
$.off nodes.current, 'error', Gallery.error
|
$.off nodes.current, 'error', Gallery.error
|
||||||
nodes.current.pause?()
|
ImageCommon.pause nodes.current
|
||||||
$.replace nodes.current, file
|
$.replace nodes.current, file
|
||||||
if elType is 'video'
|
if elType is 'video'
|
||||||
file.loop = true
|
file.loop = true
|
||||||
@ -282,7 +282,7 @@ Gallery =
|
|||||||
|
|
||||||
close: ->
|
close: ->
|
||||||
$.off Gallery.nodes.current, 'error', Gallery.error
|
$.off Gallery.nodes.current, 'error', Gallery.error
|
||||||
Gallery.nodes.current.pause?()
|
ImageCommon.pause Gallery.nodes.current
|
||||||
$.rm Gallery.nodes.el
|
$.rm Gallery.nodes.el
|
||||||
$.rmClass doc, 'gallery-open'
|
$.rmClass doc, 'gallery-open'
|
||||||
if Conf['Fullscreen Gallery']
|
if Conf['Fullscreen Gallery']
|
||||||
|
|||||||
@ -1,4 +1,11 @@
|
|||||||
ImageCommon =
|
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) ->
|
rewind: (el) ->
|
||||||
if el.nodeName is 'VIDEO'
|
if el.nodeName is 'VIDEO'
|
||||||
el.currentTime = 0 if el.readyState >= el.HAVE_METADATA
|
el.currentTime = 0 if el.readyState >= el.HAVE_METADATA
|
||||||
|
|||||||
@ -143,7 +143,7 @@ ImageExpand =
|
|||||||
$.off el, 'error', ImageExpand.error
|
$.off el, 'error', ImageExpand.error
|
||||||
ImageCommon.pushCache el
|
ImageCommon.pushCache el
|
||||||
if file.isVideo
|
if file.isVideo
|
||||||
el.pause()
|
ImageCommon.pause el
|
||||||
for eventName, cb of ImageExpand.videoCB
|
for eventName, cb of ImageExpand.videoCB
|
||||||
$.off el, eventName, cb
|
$.off el, eventName, cb
|
||||||
ImageCommon.rewind file.thumb if Conf['Restart when Opened']
|
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'
|
ImageCommon.rewind el if Conf['Restart when Opened'] and el.id isnt 'ihover'
|
||||||
el.removeAttribute 'id'
|
el.removeAttribute 'id'
|
||||||
else
|
else
|
||||||
isNew = true
|
|
||||||
el = file.fullImage = $.el (if isVideo then 'video' else 'img')
|
el = file.fullImage = $.el (if isVideo then 'video' else 'img')
|
||||||
el.dataset.fullID = post.fullID
|
el.dataset.fullID = post.fullID
|
||||||
$.on el, 'error', ImageExpand.error
|
$.on el, 'error', ImageExpand.error
|
||||||
@ -192,7 +191,7 @@ ImageExpand =
|
|||||||
thumb.parentNode.removeAttribute 'target'
|
thumb.parentNode.removeAttribute 'target'
|
||||||
|
|
||||||
el.loop = true
|
el.loop = true
|
||||||
Volume.setup el, isNew
|
Volume.setup el
|
||||||
ImageExpand.setupVideoCB post
|
ImageExpand.setupVideoCB post
|
||||||
|
|
||||||
if !isVideo
|
if !isVideo
|
||||||
|
|||||||
@ -31,7 +31,6 @@ ImageHover =
|
|||||||
el = ImageCommon.popCache()
|
el = ImageCommon.popCache()
|
||||||
$.on el, 'error', error
|
$.on el, 'error', error
|
||||||
else
|
else
|
||||||
isNew = true
|
|
||||||
el = $.el (if isVideo then 'video' else 'img')
|
el = $.el (if isVideo then 'video' else 'img')
|
||||||
el.dataset.fullID = post.fullID
|
el.dataset.fullID = post.fullID
|
||||||
$.on el, 'error', error
|
$.on el, 'error', error
|
||||||
@ -45,7 +44,7 @@ ImageHover =
|
|||||||
if isVideo
|
if isVideo
|
||||||
el.loop = true
|
el.loop = true
|
||||||
el.controls = false
|
el.controls = false
|
||||||
Volume.setup el, isNew
|
Volume.setup el
|
||||||
el.play() if Conf['Autoplay']
|
el.play() if Conf['Autoplay']
|
||||||
[width, height] = (+x for x in file.dimensions.split 'x')
|
[width, height] = (+x for x in file.dimensions.split 'x')
|
||||||
{left, right} = @getBoundingClientRect()
|
{left, right} = @getBoundingClientRect()
|
||||||
@ -66,7 +65,7 @@ ImageHover =
|
|||||||
cb: ->
|
cb: ->
|
||||||
$.off el, 'error', error
|
$.off el, 'error', error
|
||||||
ImageCommon.pushCache el
|
ImageCommon.pushCache el
|
||||||
el.pause() if isVideo
|
ImageCommon.pause el
|
||||||
$.rm el
|
$.rm el
|
||||||
el.removeAttribute 'style'
|
el.removeAttribute 'style'
|
||||||
|
|
||||||
|
|||||||
@ -31,10 +31,10 @@ Volume =
|
|||||||
Header.menu.addEntry {el: unmuteEntry, order: 200}
|
Header.menu.addEntry {el: unmuteEntry, order: 200}
|
||||||
Header.menu.addEntry {el: volumeEntry, order: 201}
|
Header.menu.addEntry {el: volumeEntry, order: 201}
|
||||||
|
|
||||||
setup: (video, isNew=true) ->
|
setup: (video) ->
|
||||||
video.muted = !Conf['Allow Sound']
|
video.muted = !Conf['Allow Sound']
|
||||||
video.volume = Conf['Default Volume']
|
video.volume = Conf['Default Volume']
|
||||||
$.on video, 'volumechange', Volume.change if isNew
|
$.on video, 'volumechange', Volume.change
|
||||||
|
|
||||||
change: ->
|
change: ->
|
||||||
{muted, volume} = @
|
{muted, volume} = @
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user