Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Do not use splice() when in a loop

  • Loading branch information...
commit ddfde16139b4e442c3357133e58186151845586f 1 parent 08bc946
vvo authored
Showing with 9 additions and 9 deletions.
  1. +6 −6 LL.js
  2. +2 −2 LL.min.js
  3. +1 −1  package.json
12 LL.js
View
@@ -37,12 +37,12 @@
if (img.getBoundingClientRect().top < winH + 200) {
img.src = img.getAttribute(lazyAttr);
img.removeAttribute(lazyAttr);
- imgs.splice(index, 1);
- // img shown
- return true;
+ // we do not use splice() as we could be in the checkImages's for loop
+ imgs[index] = null;
+
+ return true; // img shown
} else {
- // img to be shown
- return false;
+ return false; // img to be shown
}
}
@@ -75,7 +75,7 @@
var img = imgs[current];
// if showIfVisible is false, it means we have some waiting images to be
// shown
- if(img !== undefined && showIfVisible(img, current) === false) {
+ if(img !== null && showIfVisible(img, current) === false) {
allImagesDone = false;
}
}
4 LL.min.js
View
@@ -1,2 +1,2 @@
-(function(b,e){function i(a,c){var d=0;return function(){var b=+new Date;b-d<c||(d=b,a.apply(this,arguments))}}function g(a,c,b){a.attachEvent?a.attachEvent&&a.attachEvent("on"+c,b):a.addEventListener(c,b,!1)}function j(a,b,d){a.detachEvent?a.detachEvent&&a.detachEvent("on"+b,d):a.removeEventListener(b,d,!1)}function k(a,b){return a.getBoundingClientRect().top<l+200?(a.src=a.getAttribute(m),a.removeAttribute(m),f.splice(b,1),!0):!1}var m="data-src",l,f=[],n,h=i(function(){l=b.innerHeight||e.documentElement&&
-e.documentElement.clientHeight||e.body&&e.body.clientHeight||1E4},50),o=i(function(){var a=f.length,c,d=!0;for(c=0;c<a;c++){var e=f[c];void 0!==e&&!1===k(e,c)&&(d=!1)}d&&n&&(j(b,"resize",h),j(b,"scroll",o))},20);b.fstrz=!0;b.fzns=b.fzns||{LL:{s:function(a){a.onload=null;k(a,f.push(a)-1)}}};h();g(b,"resize",h);g(b,"scroll",o);g(b,"load",function(){n=!0})})(this,document);
+(function(b,e){function i(a,c){var d=0;return function(){var b=+new Date;b-d<c||(d=b,a.apply(this,arguments))}}function g(a,c,b){a.attachEvent?a.attachEvent&&a.attachEvent("on"+c,b):a.addEventListener(c,b,!1)}function j(a,b,d){a.detachEvent?a.detachEvent&&a.detachEvent("on"+b,d):a.removeEventListener(b,d,!1)}function k(a,b){return a.getBoundingClientRect().top<l+200?(a.src=a.getAttribute(m),a.removeAttribute(m),f[b]=null,!0):!1}var m="data-src",l,f=[],n,h=i(function(){l=b.innerHeight||e.documentElement&&
+e.documentElement.clientHeight||e.body&&e.body.clientHeight||1E4},50),o=i(function(){var a=f.length,c,d=!0;for(c=0;c<a;c++){var e=f[c];null!==e&&!1===k(e,c)&&(d=!1)}d&&n&&(j(b,"resize",h),j(b,"scroll",o))},20);b.fstrz=!0;b.fzns=b.fzns||{LL:{s:function(a){a.onload=null;k(a,f.push(a)-1)}}};h();g(b,"resize",h);g(b,"scroll",o);g(b,"load",function(){n=!0})})(this,document);
2  package.json
View
@@ -1,7 +1,7 @@
{
"name": "LL",
"description": "Lazy load my friend",
- "version": "0.5.1",
+ "version": "0.5.2",
"repository": {
"type": "git",
"url": "http://github.com/fasterize/LL.git"
Please sign in to comment.
Something went wrong with that request. Please try again.