simplify caching of last hovered/expanded file
This commit is contained in:
parent
62a242e100
commit
9fe9b373a2
@ -813,10 +813,10 @@ span.hide-announcement {
|
|||||||
.expanded-image > .post > .file > .fileThumb > img[data-md5] {
|
.expanded-image > .post > .file > .fileThumb > img[data-md5] {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.full-image:not(#ihover) {
|
.full-image {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.expanded-image > .post > .file > .fileThumb > .full-image:not(#ihover) {
|
.expanded-image > .post > .file > .fileThumb > .full-image {
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
.expanded-image {
|
.expanded-image {
|
||||||
@ -825,13 +825,13 @@ span.hide-announcement {
|
|||||||
.expanding {
|
.expanding {
|
||||||
opacity: .5;
|
opacity: .5;
|
||||||
}
|
}
|
||||||
:root.fit-height .full-image:not(#ihover) {
|
:root.fit-height .full-image {
|
||||||
max-height: 100vh;
|
max-height: 100vh;
|
||||||
}
|
}
|
||||||
:root.fit-width .full-image:not(#ihover) {
|
:root.fit-width .full-image {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
:root.gecko.fit-width .full-image:not(#ihover) {
|
:root.gecko.fit-width .full-image {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
.fileThumb > .warning {
|
.fileThumb > .warning {
|
||||||
|
|||||||
@ -134,12 +134,15 @@ ImageExpand =
|
|||||||
window.scrollBy 0, d.body.clientHeight - oldHeight
|
window.scrollBy 0, d.body.clientHeight - oldHeight
|
||||||
|
|
||||||
if el = file.fullImage
|
if el = file.fullImage
|
||||||
|
delete file.fullImage
|
||||||
$.off el, 'error', ImageExpand.error
|
$.off el, 'error', ImageExpand.error
|
||||||
if file.isVideo
|
if file.isVideo
|
||||||
el.pause()
|
el.pause()
|
||||||
for eventName, cb of ImageExpand.videoCB
|
for eventName, cb of ImageExpand.videoCB
|
||||||
$.off el, eventName, cb
|
$.off el, eventName, cb
|
||||||
TrashQueue.add el, post
|
$.rm el
|
||||||
|
$.rmClass el, 'full-image'
|
||||||
|
ImageCommon.cache = el
|
||||||
|
|
||||||
expand: (post, src) ->
|
expand: (post, src) ->
|
||||||
# Do not expand images of hidden/filtered replies, or already expanded pictures.
|
# Do not expand images of hidden/filtered replies, or already expanded pictures.
|
||||||
@ -150,18 +153,23 @@ ImageExpand =
|
|||||||
$.addClass thumb, 'expanding'
|
$.addClass thumb, 'expanding'
|
||||||
file.isExpanding = true
|
file.isExpanding = true
|
||||||
|
|
||||||
el = file.fullImage or $.el (if isVideo then 'video' else 'img'), className: 'full-image'
|
|
||||||
$.on el, 'error', ImageExpand.error
|
|
||||||
if file.fullImage
|
if file.fullImage
|
||||||
# Expand already-loaded/ing picture.
|
el = file.fullImage
|
||||||
TrashQueue.remove el
|
else if ImageCommon.cache?.dataset.fullID is post.fullID
|
||||||
|
el = file.fullImage = ImageCommon.cache
|
||||||
|
delete ImageCommon.cache
|
||||||
unless file.isHovered
|
unless file.isHovered
|
||||||
$.queueTask(-> el.src = el.src) if /\.gif$/.test el.src
|
$.queueTask(-> el.src = el.src) if /\.gif$/.test el.src
|
||||||
el.currentTime = 0 if isVideo and el.readyState >= el.HAVE_METADATA
|
el.currentTime = 0 if isVideo and el.readyState >= el.HAVE_METADATA
|
||||||
|
$.on el, 'error', ImageExpand.error
|
||||||
else
|
else
|
||||||
|
el = file.fullImage = $.el (if isVideo then 'video' else 'img')
|
||||||
|
el.dataset.fullID = post.fullID
|
||||||
|
$.on el, 'error', ImageExpand.error
|
||||||
el.src = src or file.URL
|
el.src = src or file.URL
|
||||||
$.after thumb, el
|
|
||||||
file.fullImage = el
|
el.className = 'full-image'
|
||||||
|
$.after thumb, el
|
||||||
|
|
||||||
if isVideo
|
if isVideo
|
||||||
# add contract link to file info
|
# add contract link to file info
|
||||||
|
|||||||
@ -15,24 +15,24 @@ ImageHover =
|
|||||||
{isVideo} = file
|
{isVideo} = file
|
||||||
return if file.isExpanding or file.isExpanded
|
return if file.isExpanding or file.isExpanded
|
||||||
file.isHovered = true
|
file.isHovered = true
|
||||||
if el = file.fullImage
|
if ImageCommon.cache?.dataset.fullID is post.fullID
|
||||||
el.id = 'ihover'
|
el = ImageCommon.cache
|
||||||
TrashQueue.remove el
|
delete ImageCommon.cache
|
||||||
$.queueTask(-> el.src = el.src) if /\.gif$/.test el.src
|
$.queueTask(-> el.src = el.src) if /\.gif$/.test el.src
|
||||||
el.currentTime = 0 if isVideo and el.readyState >= el.HAVE_METADATA
|
el.currentTime = 0 if isVideo and el.readyState >= el.HAVE_METADATA
|
||||||
else
|
else
|
||||||
file.fullImage = el = $.el (if isVideo then 'video' else 'img'),
|
el = $.el (if isVideo then 'video' else 'img')
|
||||||
className: 'full-image'
|
el.dataset.fullID = post.fullID
|
||||||
id: 'ihover'
|
|
||||||
$.on el, 'error', ImageHover.error
|
$.on el, 'error', ImageHover.error
|
||||||
el.src = file.URL
|
el.src = file.URL
|
||||||
$.after file.thumb, el
|
el.id = 'ihover'
|
||||||
|
$.after Header.hover, el
|
||||||
if isVideo
|
if isVideo
|
||||||
el.loop = true
|
el.loop = true
|
||||||
el.controls = false
|
el.controls = false
|
||||||
el.play() if Conf['Autoplay']
|
el.play() if Conf['Autoplay']
|
||||||
[width, height] = file.dimensions.split('x').map (x) -> +x
|
[width, height] = file.dimensions.split('x').map (x) -> +x
|
||||||
{left, right} = file.thumb.getBoundingClientRect()
|
{left, right} = @getBoundingClientRect()
|
||||||
padding = 16
|
padding = 16
|
||||||
maxWidth = Math.max left, doc.clientWidth - right
|
maxWidth = Math.max left, doc.clientWidth - right
|
||||||
maxHeight = doc.clientHeight - padding
|
maxHeight = doc.clientHeight - padding
|
||||||
@ -50,9 +50,10 @@ ImageHover =
|
|||||||
cb: ->
|
cb: ->
|
||||||
if isVideo
|
if isVideo
|
||||||
el.pause()
|
el.pause()
|
||||||
TrashQueue.add el, post
|
$.rm el
|
||||||
el.removeAttribute 'id'
|
el.removeAttribute 'id'
|
||||||
el.removeAttribute 'style'
|
el.removeAttribute 'style'
|
||||||
|
ImageCommon.cache = el
|
||||||
$.queueTask -> delete file.isHovered
|
$.queueTask -> delete file.isHovered
|
||||||
error: ->
|
error: ->
|
||||||
post = Get.postFromNode @
|
post = Get.postFromNode @
|
||||||
@ -64,7 +65,5 @@ ImageHover =
|
|||||||
@src = URL + if @src is URL then '?' + Date.now() else ''
|
@src = URL + if @src is URL then '?' + Date.now() else ''
|
||||||
else
|
else
|
||||||
$.rm @
|
$.rm @
|
||||||
delete post.file.fullImage
|
|
||||||
else
|
else
|
||||||
$.rm @
|
$.rm @
|
||||||
delete post.file.fullImage
|
|
||||||
|
|||||||
@ -1,14 +0,0 @@
|
|||||||
TrashQueue =
|
|
||||||
init: -> return
|
|
||||||
|
|
||||||
add: (video, post) ->
|
|
||||||
if @killNext and video isnt @killNext
|
|
||||||
delete @killNextPost?.file?.fullImage
|
|
||||||
$.rm @killNext
|
|
||||||
@killNext = video
|
|
||||||
@killNextPost = post
|
|
||||||
|
|
||||||
remove: (video) ->
|
|
||||||
if video is @killNext
|
|
||||||
delete @killNext
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user