face-recognition.js/public_html/js/lib/min/image-loader.js

3 lines
756 B
JavaScript
Raw Normal View History

2016-10-05 08:49:25 +00:00
var ImageLoader=function(a,b){this.wrapper=a instanceof HTMLImageElement?a:null;if(!this.wrapper)throw Error("Param 1 expected to be an HTMLImageElement (<img>), but "+a.constructor.name+" received");this.loaded=!1;AJAX.send("./pictures/index.php",function(a){this.images=JSON.parse(a);this.loaded=!0;b.call(this)}.bind(this),"GET")};
ImageLoader.prototype.load=function(a,b){if(!this.loaded)throw Error("image tree not loaded yet");if("string"!=typeof a)throw Error("Param 1 expected to be a <String>");a=a.replace(/:/g,"/");if("function"!=typeof b)throw Error("Param 2 expected to be a <Function>");if(~this.images.indexOf("/"+a))return this.wrapper.addEventListener("load",b,!1),this.wrapper.src="./pictures/"+a,!0;console.warn("Resource not found!")};