update image loading

This commit is contained in:
Luke Pulverenti 2016-05-17 16:04:20 -04:00
parent 22a0210633
commit 3685bd3766
3 changed files with 9 additions and 12 deletions

View file

@ -94,10 +94,11 @@ define(['visibleinviewport', 'imageFetcher', 'layoutManager', 'events'], functio
return;
}
var filledImages = [];
var cancellationTokens = [];
function unveilInternal(tokenIndex) {
var remaining = [];
var anyFound = false;
var out = false;
@ -108,25 +109,22 @@ define(['visibleinviewport', 'imageFetcher', 'layoutManager', 'events'], functio
if (cancellationTokens[tokenIndex]) {
return;
}
if (filledImages[i]) {
continue;
}
var img = images[i];
if (!out && isVisible(img)) {
anyFound = true;
filledImages[i] = true;
fillImage(img);
} else {
if (anyFound) {
out = true;
}
remaining.push(img);
}
if (out) {
return;
}
}
images = remaining;
if (!images.length) {
document.removeEventListener('focus', unveil, true);
document.removeEventListener('scroll', unveil, true);