Pause off screen and better clone handling for GIF/WebM etc. replacement
This commit is contained in:
parent
5bf9e0ab8b
commit
b29685b622
@ -56,10 +56,16 @@ class Clone extends Post
|
|||||||
@file[key] = val
|
@file[key] = val
|
||||||
file = $ '.file', post
|
file = $ '.file', post
|
||||||
@file.text = file.firstElementChild
|
@file.text = file.firstElementChild
|
||||||
@file.thumb = $ 'img[data-md5]', file
|
@file.thumb = $ '.fileThumb > [data-md5]', file
|
||||||
@file.fullImage = $ '.full-image', file
|
@file.fullImage = $ '.full-image', file
|
||||||
@file.videoControls = $ '.video-controls', @file.text
|
@file.videoControls = $ '.video-controls', @file.text
|
||||||
|
|
||||||
|
# Restore old image thumbnail in quote preview for replaced WebMs
|
||||||
|
if !@file.thumb
|
||||||
|
@file.thumb = @file.oldThumb.cloneNode true
|
||||||
|
$.prepend $('.fileThumb', file), @file.thumb
|
||||||
|
delete @file.oldThumb
|
||||||
|
|
||||||
# Contract thumbnails in quote preview
|
# Contract thumbnails in quote preview
|
||||||
ImageExpand.contract @ if contractThumb
|
ImageExpand.contract @ if contractThumb
|
||||||
|
|
||||||
|
|||||||
@ -7,9 +7,15 @@ ImageLoader =
|
|||||||
name: 'Image Replace'
|
name: 'Image Replace'
|
||||||
cb: @node
|
cb: @node
|
||||||
|
|
||||||
Thread.callbacks.push
|
if Conf['Replace WEBM'] and Conf['Autoplay']
|
||||||
name: 'Image Replace'
|
$.on d, 'scroll visibilitychange', ->
|
||||||
cb: @thread
|
g.posts.forEach (post) ->
|
||||||
|
if post.file?.oldThumb
|
||||||
|
{thumb} = post.file
|
||||||
|
visible = !d.hidden and Header.isNodeVisible thumb
|
||||||
|
if visible then thumb.play() else thumb.pause()
|
||||||
|
|
||||||
|
return unless Conf['Image Prefetching']
|
||||||
|
|
||||||
prefetch = $.el 'label',
|
prefetch = $.el 'label',
|
||||||
<%= html('<input type="checkbox" name="prefetch"> Prefetch Images') %>
|
<%= html('<input type="checkbox" name="prefetch"> Prefetch Images') %>
|
||||||
@ -21,48 +27,62 @@ ImageLoader =
|
|||||||
el: prefetch
|
el: prefetch
|
||||||
order: 104
|
order: 104
|
||||||
|
|
||||||
thread: ->
|
node: (force) ->
|
||||||
ImageLoader.thread = @
|
|
||||||
|
|
||||||
node: ->
|
|
||||||
return unless @file
|
return unless @file
|
||||||
{isImage, isVideo} = @file
|
{isImage, isVideo, thumb, URL} = @file
|
||||||
|
if @isClone and @file.oldThumb
|
||||||
|
ImageLoader.play thumb
|
||||||
return if @isClone or @isHidden or @thread.isHidden or !(isImage or isVideo)
|
return if @isClone or @isHidden or @thread.isHidden or !(isImage or isVideo)
|
||||||
{thumb, URL} = @file
|
|
||||||
{style} = thumb
|
{style} = thumb
|
||||||
type = if (match = URL.match(/\.([^.]+)$/)[1].toUpperCase()) is 'JPEG' then 'JPG' else match
|
type = if (match = URL.match(/\.([^.]+)$/)[1].toUpperCase()) is 'JPEG' then 'JPG' else match
|
||||||
replace = "Replace #{type}"
|
replace = Conf["Replace #{type}"] and !/spoiler/.test thumb.src
|
||||||
return unless (Conf[replace] and !/spoiler/.test thumb.src) or (Conf['prefetch'] and g.VIEW is 'thread')
|
prefetch = (Conf['prefetch'] and g.VIEW is 'thread') or force
|
||||||
if @file.isSpoiler
|
return unless replace or prefetch
|
||||||
# Revealed spoilers do not have height/width set, this fixes the image's dimensions.
|
el = $.el if isImage then 'img' else 'video'
|
||||||
style.maxHeight = style.maxWidth = if @isReply then '125px' else '250px'
|
if replace
|
||||||
file = $.el if isImage then 'img' else 'video'
|
if @file.isSpoiler
|
||||||
if Conf[replace]
|
# Revealed spoilers do not have height/width set, this fixes the image's dimensions.
|
||||||
|
style.maxHeight = style.maxWidth = if @isReply then '125px' else '250px'
|
||||||
if isVideo
|
if isVideo
|
||||||
|
el.textContent = thumb.alt
|
||||||
file.alt = thumb.alt
|
el.dataset.md5 = thumb.dataset.md5
|
||||||
file.dataset.md5 = thumb.dataset.md5
|
el.style.height = style.height
|
||||||
file.style.height = style.height
|
el.style.width = style.width
|
||||||
file.style.width = style.width
|
el.style.maxHeight = style.maxHeight
|
||||||
file.style.maxHeight = style.maxHeight
|
el.style.maxWidth = style.maxWidth
|
||||||
file.style.maxWidth = style.maxWidth
|
el.loop = true
|
||||||
file.loop = true
|
el.className = thumb.className
|
||||||
file.autoplay = Conf['Autoplay']
|
event = if isVideo then 'loadeddata' else 'load'
|
||||||
if Conf['Image Hover']
|
|
||||||
$.on file, 'mouseover', ImageHover.mouseover
|
|
||||||
cb = =>
|
cb = =>
|
||||||
$.off file, 'load loadedmetadata', cb
|
$.off el, event, cb
|
||||||
# Replace the thumbnail once the file has finished loading.
|
ImageLoader.replace @, el
|
||||||
if isVideo
|
$.on el, event, cb
|
||||||
$.replace thumb, file
|
el.src = URL
|
||||||
@file.thumb = file # XXX expanding requires the post.file.thumb node.
|
|
||||||
return
|
replace: (post, el) ->
|
||||||
thumb.src = URL
|
{file} = post
|
||||||
$.on file, 'load loadedmetadata', cb
|
{isVideo, thumb} = file
|
||||||
file.src = URL
|
if !post.isClone
|
||||||
|
# Replace the thumbnail in clones added before the file was loaded.
|
||||||
|
for clone in post.clones when !isVideo or !$.hasClass clone.nodes.root.parentNode, 'dialog'
|
||||||
|
ImageLoader.replace clone, el.cloneNode true
|
||||||
|
if isVideo
|
||||||
|
$.on el, 'mouseover', ImageHover.mouseover if Conf['Image Hover']
|
||||||
|
$.replace thumb, el
|
||||||
|
file.oldThumb or= thumb
|
||||||
|
file.thumb = el
|
||||||
|
ImageLoader.play el unless post.isFetchedQuote
|
||||||
|
else
|
||||||
|
thumb.src = file.URL
|
||||||
|
|
||||||
|
play: (video) ->
|
||||||
|
if Conf['Autoplay']
|
||||||
|
$.asap (-> doc.contains video), ->
|
||||||
|
if !d.hidden and Header.isNodeVisible video
|
||||||
|
video.play()
|
||||||
|
|
||||||
toggle: ->
|
toggle: ->
|
||||||
enabled = Conf['prefetch'] = @checked
|
enabled = Conf['prefetch'] = @checked
|
||||||
if enabled
|
if enabled
|
||||||
g.BOARD.posts.forEach (post) -> ImageLoader.node.call post
|
g.BOARD.posts.forEach (post) -> ImageLoader.node.call post, true
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user