Pause videos when they are not visible. #1538
This commit is contained in:
parent
7f1abad58b
commit
fba314e05a
@ -291,6 +291,9 @@ Header =
|
|||||||
headRect = (if $.hasClass Header.bar, 'autohide' then Header.hitzone else Header.bar).getBoundingClientRect()
|
headRect = (if $.hasClass Header.bar, 'autohide' then Header.hitzone else Header.bar).getBoundingClientRect()
|
||||||
bottom -= clientHeight - headRect.bottom + headRect.height
|
bottom -= clientHeight - headRect.bottom + headRect.height
|
||||||
bottom
|
bottom
|
||||||
|
isNodeVisible: (node) ->
|
||||||
|
{height} = node.getBoundingClientRect()
|
||||||
|
Header.getTopOf(node) + height >= 0 and Header.getBottomOf(node) + height >= 0
|
||||||
isHidden: ->
|
isHidden: ->
|
||||||
{top} = Header.bar.getBoundingClientRect()
|
{top} = Header.bar.getBoundingClientRect()
|
||||||
if Conf['Bottom header']
|
if Conf['Bottom header']
|
||||||
|
|||||||
@ -6,8 +6,9 @@ ImageExpand =
|
|||||||
className: 'expand-all-shortcut fa fa-expand'
|
className: 'expand-all-shortcut fa fa-expand'
|
||||||
title: 'Expand All Images'
|
title: 'Expand All Images'
|
||||||
href: 'javascript:;'
|
href: 'javascript:;'
|
||||||
$.on @EAI, 'click', ImageExpand.cb.toggleAll
|
$.on @EAI, 'click', @cb.toggleAll
|
||||||
Header.addShortcut @EAI, 3
|
Header.addShortcut @EAI, 3
|
||||||
|
$.on d, 'scroll visibilitychange', @cb.playVideos
|
||||||
|
|
||||||
Post.callbacks.push
|
Post.callbacks.push
|
||||||
name: 'Image Expansion'
|
name: 'Image Expansion'
|
||||||
@ -15,12 +16,16 @@ ImageExpand =
|
|||||||
node: ->
|
node: ->
|
||||||
return unless @file and (@file.isImage or @file.isVideo)
|
return unless @file and (@file.isImage or @file.isVideo)
|
||||||
$.on @file.thumb.parentNode, 'click', ImageExpand.cb.toggle
|
$.on @file.thumb.parentNode, 'click', ImageExpand.cb.toggle
|
||||||
if @isClone and @file.isImage and @file.isExpanding
|
if @isClone
|
||||||
# If we clone a post where the image is still loading,
|
if @file.isImage and @file.isExpanding
|
||||||
# make it loading in the clone too.
|
# If we clone a post where the image is still loading,
|
||||||
ImageExpand.contract @
|
# make it loading in the clone too.
|
||||||
ImageExpand.expand @
|
ImageExpand.contract @
|
||||||
return
|
ImageExpand.expand @
|
||||||
|
return
|
||||||
|
if @file.isVideo and @file.isExpanded
|
||||||
|
@file.fullImage.play()
|
||||||
|
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)
|
||||||
ImageExpand.expand @
|
ImageExpand.expand @
|
||||||
cb:
|
cb:
|
||||||
@ -48,6 +53,12 @@ ImageExpand =
|
|||||||
continue
|
continue
|
||||||
$.queueTask func, post
|
$.queueTask func, post
|
||||||
return
|
return
|
||||||
|
playVideos: (e) ->
|
||||||
|
for fullID, post of g.posts
|
||||||
|
continue unless post.file and post.file.isVideo and post.file.isExpanded
|
||||||
|
play = !d.hidden and !post.isHidden and doc.contains(post.nodes.root) and Header.isNodeVisible post.nodes.root
|
||||||
|
if play then post.file.fullImage.play() else post.file.fullImage.pause()
|
||||||
|
return
|
||||||
setFitness: ->
|
setFitness: ->
|
||||||
(if @checked then $.addClass else $.rmClass) doc, @name.toLowerCase().replace /\s+/g, '-'
|
(if @checked then $.addClass else $.rmClass) doc, @name.toLowerCase().replace /\s+/g, '-'
|
||||||
|
|
||||||
@ -116,13 +127,13 @@ ImageExpand =
|
|||||||
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
|
||||||
post.file.isExpanded = true
|
post.file.isExpanded = true
|
||||||
post.file.fullImage.play() if post.file.isVideo
|
|
||||||
unless post.nodes.root.parentNode
|
unless post.nodes.root.parentNode
|
||||||
# Image might start/finish loading before the post is inserted.
|
# Image might start/finish loading before the post is inserted.
|
||||||
# Don't scroll when it's expanded in a QP for example.
|
# Don't scroll when it's expanded in a QP for example.
|
||||||
$.addClass post.nodes.root, 'expanded-image'
|
$.addClass post.nodes.root, 'expanded-image'
|
||||||
$.rmClass post.file.thumb, 'expanding'
|
$.rmClass post.file.thumb, 'expanding'
|
||||||
return
|
return
|
||||||
|
post.file.fullImage.play() if post.file.isVideo and !d.hidden and Header.isNodeVisible post.nodes.root
|
||||||
{bottom} = post.nodes.root.getBoundingClientRect()
|
{bottom} = post.nodes.root.getBoundingClientRect()
|
||||||
$.queueTask ->
|
$.queueTask ->
|
||||||
$.addClass post.nodes.root, 'expanded-image'
|
$.addClass post.nodes.root, 'expanded-image'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user