Created
October 13, 2015 11:04
-
-
Save Ahrengot/726d224a18493a493188 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import $ from 'jquery' | |
export default class ImageLoader { | |
constructor(images) { | |
if ( typeof images === 'string' ) { | |
images = [images]; | |
} | |
let promises = images.map(this.loadImage); | |
return $.when.apply($, promises); | |
} | |
loadImage(src) { | |
let dfd = new $.Deferred(); | |
let img = new Image(); | |
img.src = src; | |
img.addEventListener("load", dfd.resolve); | |
return dfd.promise(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment