Don't remove images when unexpanding, hide them: this will avoid another redirections if it fails to load again, and will keep it loaded in memory even if it's not in the cache anymore (sup preloading users). Image expanding selector optimization.

This commit is contained in:
Nicolas Stepien 2012-02-03 16:39:42 +01:00
parent 6e06d6b945
commit 61621178c6
2 changed files with 19 additions and 8 deletions

View File

@ -3308,7 +3308,7 @@
var thumb, _i, _j, _len, _len2, _ref, _ref2, _results, _results2; var thumb, _i, _j, _len, _len2, _ref, _ref2, _results, _results2;
imgExpand.on = this.checked; imgExpand.on = this.checked;
if (imgExpand.on) { if (imgExpand.on) {
_ref = $$('.op > a > img[md5]:last-child, table:not([hidden]) img[md5]:last-child'); _ref = $$('img[md5]');
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
thumb = _ref[_i]; thumb = _ref[_i];
@ -3364,11 +3364,16 @@
}, },
contract: function(thumb) { contract: function(thumb) {
thumb.hidden = false; thumb.hidden = false;
return $.rm(thumb.nextSibling); return thumb.nextSibling.hidden = true;
}, },
expand: function(thumb, url) { expand: function(thumb, url) {
var a, filesize, img, max; var a, filesize, img, max;
if (thumb.hidden) return; if ($.x('ancestor-or-self::*[@hidden]', thumb)) return;
thumb.hidden = true;
if (img = thumb.nextSibling) {
img.hidden = false;
return;
}
a = thumb.parentNode; a = thumb.parentNode;
img = $.el('img', { img = $.el('img', {
src: url || a.href src: url || a.href
@ -3379,7 +3384,6 @@
img.style.maxWidth = "" + max[1] + "px"; img.style.maxWidth = "" + max[1] + "px";
} }
if (conf['404 Redirect']) $.on(img, 'error', imgExpand.error); if (conf['404 Redirect']) $.on(img, 'error', imgExpand.error);
thumb.hidden = true;
return $.add(a, img); return $.add(a, img);
}, },
error: function() { error: function() {
@ -3388,6 +3392,7 @@
thumb = this.previousSibling; thumb = this.previousSibling;
src = href.split('/'); src = href.split('/');
imgExpand.contract(thumb); imgExpand.contract(thumb);
$.rm(this);
if (!(this.src.split('/')[2] === 'images.4chan.org' && (url = redirect.image(src[3], src[5])))) { if (!(this.src.split('/')[2] === 'images.4chan.org' && (url = redirect.image(src[3], src[5])))) {
if (g.dead) return; if (g.dead) return;
url = href + '?' + Date.now(); url = href + '?' + Date.now();

View File

@ -2541,7 +2541,7 @@ imgExpand =
all: -> all: ->
imgExpand.on = @checked imgExpand.on = @checked
if imgExpand.on #expand if imgExpand.on #expand
for thumb in $$ '.op > a > img[md5]:last-child, table:not([hidden]) img[md5]:last-child' for thumb in $$ 'img[md5]'
imgExpand.expand thumb imgExpand.expand thumb
else #contract else #contract
for thumb in $$ 'img[md5][hidden]' for thumb in $$ 'img[md5][hidden]'
@ -2577,10 +2577,16 @@ imgExpand =
contract: (thumb) -> contract: (thumb) ->
thumb.hidden = false thumb.hidden = false
$.rm thumb.nextSibling thumb.nextSibling.hidden = true
expand: (thumb, url) -> expand: (thumb, url) ->
return if thumb.hidden # Do not expand images of hidden/filtered replies, or already expanded pictures.
return if $.x 'ancestor-or-self::*[@hidden]', thumb
thumb.hidden = true
if img = thumb.nextSibling
# Expand already loaded picture
img.hidden = false
return
a = thumb.parentNode a = thumb.parentNode
img = $.el 'img', img = $.el 'img',
src: url or a.href src: url or a.href
@ -2589,7 +2595,6 @@ imgExpand =
max = filesize.match /(\d+)x/ max = filesize.match /(\d+)x/
img.style.maxWidth = "#{max[1]}px" img.style.maxWidth = "#{max[1]}px"
$.on img, 'error', imgExpand.error if conf['404 Redirect'] $.on img, 'error', imgExpand.error if conf['404 Redirect']
thumb.hidden = true
$.add a, img $.add a, img
error: -> error: ->
@ -2597,6 +2602,7 @@ imgExpand =
thumb = @previousSibling thumb = @previousSibling
src = href.split '/' src = href.split '/'
imgExpand.contract thumb imgExpand.contract thumb
$.rm @
unless @src.split('/')[2] is 'images.4chan.org' and url = redirect.image src[3], src[5] unless @src.split('/')[2] is 'images.4chan.org' and url = redirect.image src[3], src[5]
return if g.dead return if g.dead
# CloudFlare may cache banned pages instead of images. # CloudFlare may cache banned pages instead of images.