diff --git a/dist/image-promise.browser.js b/dist/image-promise.browser.js index 864cd21..0aa9cd0 100644 --- a/dist/image-promise.browser.js +++ b/dist/image-promise.browser.js @@ -1,2 +1,2 @@ /*! npm.im/image-promise */ -var loadImage=function(){"use strict";function e(e,n){n&&(e.src=n);var r=new Promise(function(n,r){e.complete?n(e):(e.addEventListener("load",function(){return n(e)}),e.addEventListener("error",function(){return r(e)}))});return r.image=e,r}function n(r){return void 0!==r.length?Promise.all([].map.call(r,n)):r.src?e(r):(n[r]||(n[r]=e(new Image,r)),n[r])}return n.unload=function(e){e.src&&(void 0!==e.length?[].map.call(e,n.unload):n[e]&&(n[e].image.src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=",delete n[e]))},n}(); \ No newline at end of file +var loadImage=function(){"use strict";function e(e,n){n&&(e.src=n);var t=new Promise(function(n,t){e.complete?n(e):(e.addEventListener("load",function(){return n(e)}),e.addEventListener("error",function(){return t(e)}))});return t.image=e,t}function n(t){return"string"!=typeof t&&void 0!==t.length?Promise.all([].map.call(t,n)):t.src?e(t):(n[t]||(n[t]=e(new Image,t)),n[t])}return n.unload=function(e){e.src||("string"!=typeof e&&void 0!==e.length?[].map.call(e,n.unload):n[e]&&(n[e].image.src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=",delete n[e]))},n}(); \ No newline at end of file diff --git a/index.js b/index.js index 51e9f5a..8d5f67b 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ function trackLoading(image, src) { export default function load(image) { // if argument is an array, treat as // load(['1.jpg', '2.jpg']) - if (image.length !== undefined) { + if (typeof image !== 'string' && image.length !== undefined) { return Promise.all([].map.call(image, load)); } @@ -34,14 +34,14 @@ export default function load(image) { } load.unload = function (image) { - if (!image.src) { + if (image.src) { // an was passed as argument, so nothing to unload return; } // if argument is an array, treat as // load(['1.jpg', '2.jpg']) - if (image.length !== undefined) { + if (typeof image !== 'string' && image.length !== undefined) { [].map.call(image, load.unload); } else if (load[image]) { // GC, http://www.fngtps.com/2010/mobile-safari-image-resource-limit-workaround/ diff --git a/package.json b/package.json index 256b083..4a6e6ce 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Load an image and return a promise in the browser, in 0.3KB", "license": "MIT", "repository": "bfred-it/image-promise", - "author": "Federico Brigante (twitter.com/bfred_it)", + "author": "Federico Brigante (bfred.it)", "keywords": [ "browser", "image",