Refactor and fix. This won't wait for an answer from images.4chan.org to see if the picture 404'd or not.

This commit is contained in:
Nicolas Stepien 2012-01-27 17:42:22 +01:00
parent 43df119987
commit 18525ecee1
2 changed files with 16 additions and 21 deletions

View File

@ -3293,7 +3293,7 @@
return $.add(a, img);
},
error: function() {
var href, req, src, thumb, url;
var href, src, thumb, timeoutID, url;
href = this.parentNode.href;
thumb = this.previousSibling;
imgExpand.contract(thumb);
@ -3302,20 +3302,16 @@
setTimeout(imgExpand.expand, 10000, thumb, url);
return;
}
if (g.dead) return;
url = href + '?' + Date.now();
if (engine === 'webkit') {
return req = $.ajax(this.src, {
onreadystatechange: (function() {
if (this.status !== 404) {
return setTimeout(imgExpand.expand, 10000, thumb, url);
}
})
}, {
type: 'head'
});
} else if (!g.dead) {
return setTimeout(imgExpand.expand, 10000, thumb, url);
}
timeoutID = setTimeout(imgExpand.expand, 10000, thumb, url);
return $.ajax(this.src, {
onreadystatechange: (function() {
if (this.status === 404) return clearTimeout(timeoutID);
})
}, {
type: 'head'
});
},
dialog: function() {
var controls, form, imageType, select;

View File

@ -2512,15 +2512,14 @@ imgExpand =
if @src.split('/')[2] is 'images.4chan.org' and url = redirect.image src[3], src[5]
setTimeout imgExpand.expand, 10000, thumb, url
return
return if g.dead
# CloudFlare may cache banned pages instead of images.
# This will fool CloudFlare's cache.
url = href + '?' + Date.now()
#navigator.online is not x-browser/os yet
if engine is 'webkit'
req = $.ajax @src, onreadystatechange: (-> setTimeout imgExpand.expand, 10000, thumb, url if @status isnt 404),
type: 'head'
#Firefox returns a status code of 0 because of the same origin policy
#Oprah doesn't send any request
else unless g.dead
setTimeout imgExpand.expand, 10000, thumb, url
timeoutID = setTimeout imgExpand.expand, 10000, thumb, url
$.ajax @src, onreadystatechange: (-> clearTimeout timeoutID if @status is 404),
type: 'head'
dialog: ->
controls = $.el 'div',