fix image error handling
This commit is contained in:
parent
9fe9b373a2
commit
a0e1268e60
@ -1,4 +1,17 @@
|
|||||||
ImageCommon =
|
ImageCommon =
|
||||||
|
pushCache: (el) ->
|
||||||
|
ImageCommon.cache = el
|
||||||
|
$.on el, 'error', ImageCommon.cacheError
|
||||||
|
|
||||||
|
popCache: ->
|
||||||
|
el = ImageCommon.cache
|
||||||
|
$.off el, 'error', ImageCommon.cacheError
|
||||||
|
delete ImageCommon.cache
|
||||||
|
el
|
||||||
|
|
||||||
|
cacheError: ->
|
||||||
|
delete ImageCommon.cache if ImageCommon.cache is @
|
||||||
|
|
||||||
decodeError: (file, post) ->
|
decodeError: (file, post) ->
|
||||||
return false unless file.error?.code is MediaError.MEDIA_ERR_DECODE
|
return false unless file.error?.code is MediaError.MEDIA_ERR_DECODE
|
||||||
unless message = $ '.warning', post.file.thumb.parentNode
|
unless message = $ '.warning', post.file.thumb.parentNode
|
||||||
|
|||||||
@ -142,7 +142,7 @@ ImageExpand =
|
|||||||
$.off el, eventName, cb
|
$.off el, eventName, cb
|
||||||
$.rm el
|
$.rm el
|
||||||
$.rmClass el, 'full-image'
|
$.rmClass el, 'full-image'
|
||||||
ImageCommon.cache = el
|
ImageCommon.pushCache 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.
|
||||||
@ -156,8 +156,7 @@ ImageExpand =
|
|||||||
if file.fullImage
|
if file.fullImage
|
||||||
el = file.fullImage
|
el = file.fullImage
|
||||||
else if ImageCommon.cache?.dataset.fullID is post.fullID
|
else if ImageCommon.cache?.dataset.fullID is post.fullID
|
||||||
el = file.fullImage = ImageCommon.cache
|
el = file.fullImage = ImageCommon.popCache()
|
||||||
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
|
||||||
|
|||||||
@ -7,23 +7,23 @@ ImageHover =
|
|||||||
cb: @node
|
cb: @node
|
||||||
node: ->
|
node: ->
|
||||||
return unless @file?.isImage or @file?.isVideo
|
return unless @file?.isImage or @file?.isVideo
|
||||||
$.on @file.thumb, 'mouseover', ImageHover.mouseover
|
$.on @file.thumb, 'mouseover', ImageHover.mouseover @
|
||||||
mouseover: (e) ->
|
mouseover: (post) -> (e) ->
|
||||||
return unless doc.contains @
|
return unless doc.contains @
|
||||||
post = Get.postFromNode @
|
|
||||||
{file} = post
|
{file} = post
|
||||||
{isVideo} = file
|
{isVideo} = file
|
||||||
return if file.isExpanding or file.isExpanded
|
return if file.isExpanding or file.isExpanded
|
||||||
file.isHovered = true
|
file.isHovered = true
|
||||||
|
error = ImageHover.error post
|
||||||
if ImageCommon.cache?.dataset.fullID is post.fullID
|
if ImageCommon.cache?.dataset.fullID is post.fullID
|
||||||
el = ImageCommon.cache
|
el = ImageCommon.popCache()
|
||||||
delete ImageCommon.cache
|
$.on el, 'error', error
|
||||||
$.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
|
||||||
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', ImageHover.error
|
$.on el, 'error', error
|
||||||
el.src = file.URL
|
el.src = file.URL
|
||||||
el.id = 'ihover'
|
el.id = 'ihover'
|
||||||
$.after Header.hover, el
|
$.after Header.hover, el
|
||||||
@ -51,19 +51,15 @@ ImageHover =
|
|||||||
if isVideo
|
if isVideo
|
||||||
el.pause()
|
el.pause()
|
||||||
$.rm el
|
$.rm el
|
||||||
|
$.off el, 'error', error
|
||||||
el.removeAttribute 'id'
|
el.removeAttribute 'id'
|
||||||
el.removeAttribute 'style'
|
el.removeAttribute 'style'
|
||||||
ImageCommon.cache = el
|
ImageCommon.pushCache el
|
||||||
$.queueTask -> delete file.isHovered
|
$.queueTask -> delete file.isHovered
|
||||||
error: ->
|
error: (post) -> ->
|
||||||
post = Get.postFromNode @
|
return if ImageCommon.decodeError @, post
|
||||||
return if post.file.isExpanding or post.file.isExpanded
|
ImageCommon.error @, post, 3 * $.SECOND, (URL) =>
|
||||||
if @id is 'ihover' # still hovering
|
if URL
|
||||||
return if ImageCommon.decodeError @, post
|
@src = URL + if @src is URL then '?' + Date.now() else ''
|
||||||
ImageCommon.error @, post, 3 * $.SECOND, (URL) =>
|
else
|
||||||
if URL
|
$.rm @
|
||||||
@src = URL + if @src is URL then '?' + Date.now() else ''
|
|
||||||
else
|
|
||||||
$.rm @
|
|
||||||
else
|
|
||||||
$.rm @
|
|
||||||
|
|||||||
@ -51,7 +51,7 @@ ImageLoader =
|
|||||||
video.dataset.md5 = thumb.dataset.md5
|
video.dataset.md5 = thumb.dataset.md5
|
||||||
video.style[attr] = thumb.style[attr] for attr in ['height', 'width', 'maxHeight', 'maxWidth']
|
video.style[attr] = thumb.style[attr] for attr in ['height', 'width', 'maxHeight', 'maxWidth']
|
||||||
video.src = file.URL
|
video.src = file.URL
|
||||||
$.on video, 'mouseover', ImageHover.mouseover if Conf['Image Hover']
|
$.on video, 'mouseover', ImageHover.mouseover post if Conf['Image Hover']
|
||||||
$.replace thumb, video
|
$.replace thumb, video
|
||||||
file.thumb = video
|
file.thumb = video
|
||||||
file.videoThumb = true
|
file.videoThumb = true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user