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:
parent
6e06d6b945
commit
61621178c6
@ -3308,7 +3308,7 @@
|
||||
var thumb, _i, _j, _len, _len2, _ref, _ref2, _results, _results2;
|
||||
imgExpand.on = this.checked;
|
||||
if (imgExpand.on) {
|
||||
_ref = $$('.op > a > img[md5]:last-child, table:not([hidden]) img[md5]:last-child');
|
||||
_ref = $$('img[md5]');
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
thumb = _ref[_i];
|
||||
@ -3364,11 +3364,16 @@
|
||||
},
|
||||
contract: function(thumb) {
|
||||
thumb.hidden = false;
|
||||
return $.rm(thumb.nextSibling);
|
||||
return thumb.nextSibling.hidden = true;
|
||||
},
|
||||
expand: function(thumb, url) {
|
||||
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;
|
||||
img = $.el('img', {
|
||||
src: url || a.href
|
||||
@ -3379,7 +3384,6 @@
|
||||
img.style.maxWidth = "" + max[1] + "px";
|
||||
}
|
||||
if (conf['404 Redirect']) $.on(img, 'error', imgExpand.error);
|
||||
thumb.hidden = true;
|
||||
return $.add(a, img);
|
||||
},
|
||||
error: function() {
|
||||
@ -3388,6 +3392,7 @@
|
||||
thumb = this.previousSibling;
|
||||
src = href.split('/');
|
||||
imgExpand.contract(thumb);
|
||||
$.rm(this);
|
||||
if (!(this.src.split('/')[2] === 'images.4chan.org' && (url = redirect.image(src[3], src[5])))) {
|
||||
if (g.dead) return;
|
||||
url = href + '?' + Date.now();
|
||||
|
||||
@ -2541,7 +2541,7 @@ imgExpand =
|
||||
all: ->
|
||||
imgExpand.on = @checked
|
||||
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
|
||||
else #contract
|
||||
for thumb in $$ 'img[md5][hidden]'
|
||||
@ -2577,10 +2577,16 @@ imgExpand =
|
||||
|
||||
contract: (thumb) ->
|
||||
thumb.hidden = false
|
||||
$.rm thumb.nextSibling
|
||||
thumb.nextSibling.hidden = true
|
||||
|
||||
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
|
||||
img = $.el 'img',
|
||||
src: url or a.href
|
||||
@ -2589,7 +2595,6 @@ imgExpand =
|
||||
max = filesize.match /(\d+)x/
|
||||
img.style.maxWidth = "#{max[1]}px"
|
||||
$.on img, 'error', imgExpand.error if conf['404 Redirect']
|
||||
thumb.hidden = true
|
||||
$.add a, img
|
||||
|
||||
error: ->
|
||||
@ -2597,6 +2602,7 @@ imgExpand =
|
||||
thumb = @previousSibling
|
||||
src = href.split '/'
|
||||
imgExpand.contract thumb
|
||||
$.rm @
|
||||
unless @src.split('/')[2] is 'images.4chan.org' and url = redirect.image src[3], src[5]
|
||||
return if g.dead
|
||||
# CloudFlare may cache banned pages instead of images.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user