Get some rudimentary error handling setup in the gallery
This is mostly just Mayhem's ImageExpand error code, refactored for the context of the gallery.
This commit is contained in:
parent
128ff46440
commit
5c43ffb272
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -104,14 +104,16 @@ Gallery =
|
|||||||
nodes.total.textContent = --i
|
nodes.total.textContent = --i
|
||||||
|
|
||||||
generateThumb: (file) ->
|
generateThumb: (file) ->
|
||||||
|
post = Get.postFromNode file
|
||||||
title = ($ '.fileText a', file).textContent
|
title = ($ '.fileText a', file).textContent
|
||||||
thumb = ($ '.fileThumb', file).cloneNode true
|
thumb = post.file.thumb.parentNode
|
||||||
if double = $ 'img + img', thumb
|
if double = $ 'img + img', thumb
|
||||||
$.rm double
|
$.rm double
|
||||||
|
|
||||||
thumb.className = 'gal-thumb'
|
thumb.className = 'gal-thumb'
|
||||||
thumb.title = title
|
thumb.title = title
|
||||||
thumb.dataset.id = Gallery.images.length
|
thumb.dataset.id = Gallery.images.length
|
||||||
|
thumb.dataset.post = $('a[title="Highlight this post"]', post.nodes.info).href
|
||||||
thumb.firstElementChild.style.cssText = ''
|
thumb.firstElementChild.style.cssText = ''
|
||||||
|
|
||||||
$.on thumb, 'click', Gallery.cb.open
|
$.on thumb, 'click', Gallery.cb.open
|
||||||
@ -150,7 +152,7 @@ Gallery =
|
|||||||
src: name.href = @href
|
src: name.href = @href
|
||||||
title: name.download = name.textContent = @title
|
title: name.download = name.textContent = @title
|
||||||
|
|
||||||
img.dataset.id = @dataset.id
|
$.extend img.dataset, @dataset
|
||||||
$.replace nodes.current, img
|
$.replace nodes.current, img
|
||||||
nodes.count.textContent = +@dataset.id + 1
|
nodes.count.textContent = +@dataset.id + 1
|
||||||
nodes.current = img
|
nodes.current = img
|
||||||
@ -165,12 +167,47 @@ Gallery =
|
|||||||
return if top < 0
|
return if top < 0
|
||||||
|
|
||||||
nodes.thumbs.scrollTop += top
|
nodes.thumbs.scrollTop += top
|
||||||
|
|
||||||
|
$.on img, 'error', ->
|
||||||
|
Gallery.cb.error img, thumb
|
||||||
|
|
||||||
image: (e) ->
|
image: (e) ->
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
Gallery.build @
|
Gallery.build @
|
||||||
|
|
||||||
|
error: (img, thumb) ->
|
||||||
|
post = Get.postFromLink $.el 'a', href: img.dataset.post
|
||||||
|
delete post.file.fullImage
|
||||||
|
|
||||||
|
src = @src.split '/'
|
||||||
|
if src[2] is 'images.4chan.org'
|
||||||
|
URL = Redirect.to 'file',
|
||||||
|
boardID: src[3]
|
||||||
|
filename: src[5]
|
||||||
|
if URL
|
||||||
|
thumb.href = URL
|
||||||
|
return unless Gallery.nodes.current is img
|
||||||
|
revived = $.el 'img',
|
||||||
|
src: URL
|
||||||
|
title: img.title
|
||||||
|
$.extend revived.dataset, img.dataset
|
||||||
|
$.replace img, revived
|
||||||
|
return
|
||||||
|
if g.DEAD or post.isDead or post.file.isDead
|
||||||
|
return
|
||||||
|
|
||||||
|
# XXX CORS for images.4chan.org WHEN?
|
||||||
|
$.ajax "//api.4chan.org/#{post.board}/res/#{post.thread}.json", onload: ->
|
||||||
|
return if @status isnt 200
|
||||||
|
i = 0
|
||||||
|
while postObj = JSON.parse(@response).posts[i++]
|
||||||
|
break if postObj.no is post.ID
|
||||||
|
unless postObj.no
|
||||||
|
return post.kill()
|
||||||
|
if postObj.filedeleted
|
||||||
|
post.kill true
|
||||||
|
|
||||||
prev: -> Gallery.cb.open.call Gallery.images[+Gallery.nodes.current.dataset.id - 1]
|
prev: -> Gallery.cb.open.call Gallery.images[+Gallery.nodes.current.dataset.id - 1]
|
||||||
next: -> Gallery.cb.open.call Gallery.images[+Gallery.nodes.current.dataset.id + 1]
|
next: -> Gallery.cb.open.call Gallery.images[+Gallery.nodes.current.dataset.id + 1]
|
||||||
toggle: -> (if Gallery.nodes then Gallery.cb.close else Gallery.build)()
|
toggle: -> (if Gallery.nodes then Gallery.cb.close else Gallery.build)()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user