Created
July 7, 2012 10:26
-
-
Save cybear/3065786 to your computer and use it in GitHub Desktop.
image loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define( | |
function(){ | |
"use strict"; | |
return function(urls, success){ | |
var imgs, counter=0; | |
function isEverythingDone(){ | |
counter++; | |
console.log('Loaded '+counter+' of '+urls.length+': '+this.src+' '+this.width+'*'+this.height); | |
if(counter == urls.length) { | |
success(imgs); | |
} | |
} | |
function urlToImgElement(url){ | |
var el=new Image(); | |
el.src=url; | |
el.onload=isEverythingDone; | |
return el; | |
} | |
console.log('Attempting to load '+urls.length+' images...'); | |
imgs = urls.map(urlToImgElement); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With regards to ES3, I prefer to code for newer and use polyfills for older browsers. I am aware that polyfills are not always 100% identical to the real thing, however for my coding style it usually seems to work.