-
Notifications
You must be signed in to change notification settings - Fork 0
/
esquire-full.min.js
1 lines (1 loc) · 12.6 KB
/
esquire-full.min.js
1
"use strict";!function a(b){function c(a,b){var d=0,f=null,g=[],h=function(a){var b=d>0?"resolve":0>d?"reject":null;if(b)for(var c in a)a[c][b](f)},i=this;Object.defineProperties(this,{resolve:{enumerable:!0,configurable:!1,value:function(b){if(b&&"function"==typeof b.then)b.then(function(a){i.resolve(a)},function(a){i.reject(a)});else if(0==d){if(f=b,d=1,a)try{f=a(f)}catch(c){f=c,d=-1}h(g)}}},reject:{enumerable:!0,configurable:!1,value:function(a){if(0==d){if(f=a,d=-1,b)try{f=b(f),d=1}catch(c){f=c}h(g)}}},promise:{enumerable:!0,configurable:!1,value:Object.defineProperties(Object.create(e.prototype),{then:{enumerable:!0,configurable:!1,value:function(a,b){var e=new c(a,b);return 0==d?g.push(e):h([e]),e.promise}}})}})}function d(a,e){if(!(this instanceof d))return new d(a,e);if(void 0===a)c.call(this);else{if(!("number"==typeof a&&a>=0))throw new TypeError("Deferred constructor must be called with a non-negative number");null==e?e=new Error("Timeout waiting for resolution/rejection"):"string"==typeof e&&(e=new Error(e));var f=this,g=b.setTimeout(function(){f.reject(e)},a);c.call(this,function(a){return b.clearTimeout(g),a},function(a){throw b.clearTimeout(g),a})}}function e(a){if(!(this instanceof e))return new e(a);if("function"!=typeof a)throw new TypeError("Executor is not a function");var b=new d;Object.defineProperties(this,{then:{enumerable:!0,configurable:!1,value:function(){return b.promise.then.apply(b.promise,arguments)}}});try{a(b.resolve,b.reject)}catch(c){b.reject(c)}}function f(a,b){a="Esquire: "+(a||"Unknown error");var c="";if(b&&b.length)for(var d=0;d<b.length;d++)b[d]&&(c+=" -> "+b[d]);c&&(a+=" resolving"+c),Error.call(this,a),this.message=a;var e=this.stack||(new Error).stack;e&&(e=e.replace(new RegExp("^(Error|"+this.name+")\n"),""),this.stack=this.name+": "+this.message+"\n"+e)}function g(a){f.call(this,"Module '"+a+"' not found")}function h(a,b){var c=a?"Error instantiating '"+a+"' module":"Injection failed";this.$$message=c,b&&(this.originalCause=b.originalCause||b,this.cause=b);for(var d=b;null!=d;d=d.cause)c+="\n- Cause: "+(d.$$message||d.message||"[no message]");f.call(this,c)}function i(a){var b="Detected circular dependency in ";for(var c in a)b+=a[c]+" -> ";b+=a[0],this.$$message=b,f.call(this,b)}function j(a,b,c,d){a=p(a);for(var e in b)b[e]=p(b[e]);Object.defineProperty(this,"name",{enumerable:!0,configurable:!1,value:a}),Object.defineProperty(this,"dependencies",{enumerable:!0,configurable:!1,value:b}),Object.defineProperty(this,"constructor",{enumerable:!0,configurable:!1,value:c}),Object.defineProperty(this,"$$dynamic",{enumerable:!1,configurable:!1,value:d||!1}),Object.defineProperty(this,"$$script",{enumerable:!1,configurable:!1,get:function(){return"Esquire.define("+JSON.stringify(this.name)+","+JSON.stringify(this.dependencies)+","+c.toString()+");"}}),Object.freeze(this)}function k(a){j.call(this,a,["$global"],function(a){function b(a,c,d){if(!d&&a in c)return c[a];var e=["Ms","ms","Moz","moz","WebKit","webkit"];for(var f in e){var g=e[f]+a;if(g in c)return c[g]}return a[0]!==a[0].toUpperCase()?b(a[0].toUpperCase()+a.substring(1),c,!0):void 0}function c(a,d){if(!d)return void 0;if(!a)return void 0;switch(a.length){case 0:return void 0;case 1:return b(a[0],d);default:return c(a.slice(1),b(a[0],d))}}return c(this.name.substring(8).split("."),a)},!0)}function l(a){j.call(this,a,[],function(){throw new f("The constructor for '"+a+"' should not be called'")},!0)}function m(a){if(!a)return[];for(var b=[],c=0;c<a.length;c++){var d=a[c];if("string"==typeof d)b.push(d);else if("function"==typeof d)b.push(d);else if(Array.isArray(d))b=b.concat(m(d));else{if("object"!=typeof d||"number"!=typeof d.length)throw new f("Invalid dependency: "+JSON.stringify(d));b=b.concat(m(d))}}return b}function n(){var a=m(arguments),b={arguments:[],"function":null};if(!a.length)return b;"function"==typeof a[a.length-1]&&(b.function=a.splice(-1)[0]);for(var c in a){var d=a[c];if("string"!=typeof d)throw new f("Found "+typeof d+" but needed string: "+d);b.arguments.push(d)}return b}function o(a){return/^\$global[\/\.].+/.test(a)}function p(a){return o(a)?"$global/"+a.substring(8):a}function q(){if(1==arguments.length&&arguments[0].name&&arguments[0].constructor){var a=arguments[0];return q(a.name,a.dependencies||[],a.constructor)}var b,c,d=n(arguments),e=[];if(!d.arguments.length)throw new f("No module name specified");if(b=p(d.arguments.splice(0,1)[0]),e=d.arguments,y[b])throw new f("Module '"+b+"' already defined");if(!d.function)throw new f("No constructor function specified for module '"+b+"'");c=d.function;var a=y[b]=new j(b,e,c);for(var g in x.define)try{x.define[g](a)}catch(h){console.error("Error notifying listener",h)}return z[a.name]&&(z[a.name].resolve(a),delete z[a.name]),a}function r(a){if(a instanceof j)return a;if("string"==typeof a){if(y[a])return y[a];if(z[a])return z[a].promise;if(o(a))return y[a]=new k(a);var b=new d(w/2,new g(a));return z[a]=b,b.promise}return v.reject("Unable to resolve module of type "+typeof a)}function s(a){if(!(a instanceof j))return v.reject("Unable to resolve module of type "+typeof a);if(0==a.dependencies.length)return A;var b=[];for(var c in a.dependencies){var d=a.dependencies[c];b.push(r(d))}return v.all(b)}function t(a,b){if(!(a instanceof j))return v.reject("Unable to resolve module of type "+typeof a);var c=[];for(var d in a.dependencies)!function(a){if(!b[a]){var d=b[a]=r(a);c.push(v.resolve(d).then(function(c){return b[a]=c,t(c,b)}))}}(a.dependencies[d]);return v.all(c).then(function(){return b})}function u(a){function c(a,b,e){if(e=e.slice(0),null!=a.name&&e.push(a.name),k[a.name])return k[a.name];50>b&&(b=50);var f=new d(b,"Timeout waiting for module '"+a.name+"'");return a.name&&!a.$$dynamic&&(k[a.name]=f.promise),s(a).then(function(d){var f=[];for(var g in d){var h=d[g],j=e.indexOf(h.name);if(j>=0){var l=e.slice(j);throw new i(l)}f.push(k[h.name]?k[h.name]:c(h,b-5,e))}return v.all(f).then(function(b){return a.constructor.apply(a,b)})}).then(function(b){a.name&&!a.$$dynamic&&(k[a.name]=b),f.resolve(b)},function(b){f.reject(new h(a.name,b))}),f.promise}function e(){return 1==arguments.length&&"string"==typeof arguments[0]?g([arguments[0]],function(a){return a}):g(arguments,function(){for(var a=[],b=0;b<arguments.length;b++)a.push(arguments[b]);return a})}function g(){var b=n(arguments);if(!b.function)throw new f("Callback for injection unspecified");var d=new j(null,b.arguments,b.function);try{return c(d,a,[])}catch(e){return v.reject(e)}}if(!(this instanceof u))return new u(a);if(void 0===a)a=w;else{if(a=Number(a),0/0===a)throw new f("Timeout is not a number");if(100>a)throw new f("Timeout must be greater or equal than 100ms")}var k={$global:b,$esquire:this,$promise:v,$deferred:d};Object.defineProperties(this,{inject:{enumerable:!0,configurable:!1,value:g},require:{enumerable:!0,configurable:!1,value:e}})}b.console||(b.console={}),b.console.error||(b.console.error=function(){}),b.console.warn||(b.console.warn=function(){}),b.console.log||(b.console.log=function(){}),b.console.info||(b.console.info=function(){}),b.console.debug||(b.console.debug=function(){}),b.Array.isArray||(b.Array.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)});var v=b.Promise||e;c.prototype=Object.create(Object.prototype),c.prototype.constructor=c,c.prototype.name="Deferring",d.prototype=Object.create(c.prototype),d.prototype.constructor=d,d.prototype.name="Deferred",e.prototype=Object.create(Object.prototype),e.prototype.constructor=e,e.prototype.name="Promise",e.prototype.catch=function(a){return this.then(null,a)},Object.defineProperty(e,"all",{enumerable:!0,configurable:!1,value:function(a){if(!Array.isArray(a))return e.reject(new TypeError("Invalid argument"));var b=new d;if(0==a.length)return b.resolve([]),b.promise;for(var c=new Array(a.length),f=a.length,g=0;g<a.length;g++)!function(d){var e=a[d];e&&"function"==typeof e.then?e.then(function(a){c[d]=a,0==--f&&b.resolve(c)},function(a){b.reject(a)}):(c[d]=e,0==--f&&b.resolve(c))}(g);return b.promise}}),Object.defineProperty(e,"race",{enumerable:!0,configurable:!1,value:function(a){if(!Array.isArray(a))return e.reject(new TypeError("Invalid argument"));var b=new d;for(var c in a){var f=a[c];f&&"function"==typeof f.then?f.then(function(a){b.resolve(a)},function(a){b.reject(a)}):b.resolve(f)}return b.promise}}),Object.defineProperty(e,"resolve",{enumerable:!0,configurable:!1,value:function(a){var b=new d;return a&&"function"==typeof a.then?a.then(function(a){b.resolve(a)},function(a){b.reject(a)}):b.resolve(a),b.promise}}),Object.defineProperty(e,"reject",{enumerable:!0,configurable:!1,value:function(a){var b=new d;return b.reject(a),b.promise}}),f.prototype=Object.create(Error.prototype),f.prototype.constructor=f,f.prototype.name="EsquireError",g.prototype=Object.create(f.prototype),g.prototype.constructor=g,g.prototype.name="NoModuleError",h.prototype=Object.create(f.prototype),h.prototype.constructor=h,h.prototype.name="InjectionError",i.prototype=Object.create(f.prototype),i.prototype.constructor=i,i.prototype.name="CircularDependencyError",k.prototype=Object.create(j.prototype),k.prototype.constructor=k,k.prototype.name="GlobalModule",l.prototype=Object.create(j.prototype),l.prototype.constructor=l,l.prototype.name="InternalModule";var w=2e3,x={define:[]},y={$global:new l("$global"),$esquire:new l("$esquire"),$promise:new l("$promise"),$deferred:new l("$deferred")},z={},A=v.resolve([]);if(Object.defineProperties(u,{$$script:{enumerable:!1,configurable:!1,value:a.toString()},$$Promise:{enumerable:!1,configurable:!1,value:e},$$Deferred:{enumerable:!1,configurable:!1,value:d},define:{enumerable:!0,configurable:!1,value:q},resolve:{enumerable:!0,configurable:!1,value:function(a,b,c){if("string"==typeof a)return v.resolve(r(a)).then(function(a){return u.resolve(a,b,c)});if(!(a instanceof j))throw new TypeError("Must be invoked with Module or module name");var d={};return c&&(d[a.name]=a),b?t(a,d):s(a).then(function(a){for(var b in a)d[a[b].name]=a[b];return d})}},timeout:{enumerable:!0,configurable:!1,get:function(){return w},set:function(a){if(a=Number(a),0/0===a)throw new f("Timeout is not a number");if(100>a)throw new f("Timeout must be greater or equal than 100ms");w=a}},modules:{enumerable:!0,configurable:!1,get:function(){var a={};for(var b in y)a[b]=y[b];return Object.freeze(a)}},module:{enumerable:!0,configurable:!1,value:function(a){return v.resolve(r(a))}},on:{enumerable:!0,configurable:!1,value:function(a,b){if("string"!=typeof a)throw new f("Event name must be a string");if("function"!=typeof b)throw new f("Listener must be a function");return"define"===a&&x.define.push(b),u}}}),b.Esquire)throw new Error("Esquire already defined in global scope");b.Esquire=u;var B=new u;b.esquire=function(){if(0==arguments.length)throw new f("No dependencies/callback specified");var a=n(arguments);return a.function?B.inject(a.arguments,a.function):B.require(1==arguments.length&&"string"==typeof arguments[0]?arguments[0]:a.arguments)}}(function(){try{return window}catch(a){return global}}()),function(a){function b(a){if(!a)return[];for(var c=[],d=0;d<a.length;d++){var e=a[d];if("string"==typeof e)c.push(e);else if("function"==typeof e)c.push(e);else if(Array.isArray(e))c=c.concat(b(e));else{if("object"!=typeof e||"number"!=typeof e.length)throw new EsquireError("Invalid dependency: "+JSON.stringify(e));c=c.concat(b(e))}}return c}function c(a){var b=a.filename||a.target&&a.target.src;if(h[b]){if(a.stopPropagation&&a.stopPropagation(),a.preventDefault&&a.preventDefault(),a.target&&a.target.parentNode)try{a.target.parentNode.removeChild(a.target)}catch(c){}var d=h[b];return delete h[b],d.remaining-=1,{script:b,promise:d}}}function d(a){var b=c(a);b&&(console.debug("Esquire: Successfully loaded script '",b.script,"'"),0==b.promise.remaining&&b.promise.resolve(Esquire.modules))}function e(a){var b=c(a);if(b){console.warn("Esquire: Unable to load script '",b.script,"'");var d=a.error||new Error("Unable to load script '"+b.script+"'");b.promise.reject(d)}}function f(){if(!i)throw new Error("Esquire: Document not available");var a=i.getElementsByTagName("script")[0],c=a.parentNode,f=new Esquire.$$Deferred;f.remaining=0;var j=b(arguments),k=[];for(var l in j)!function(a){var b=i.createElement("script");b.async=!0,b.defer=!0,b.src=a,a=b.src,g[a]?console.debug("Esquire: Script '"+a+"' already loaded"):h[a]?console.debug("Esquire: Script '"+a+"' already being loaded"):(b.addEventListener("load",d,!1),b.addEventListener("error",e,!1),h[a]=f,f.remaining+=1,k.push(b))}(j[l]);if(0==k.length)f.resolve(Esquire.modules);else for(var l in k)console.debug("Esquire: About to load '"+k[l].src+"'"),c.insertBefore(k[l],a);return f.promise}if(!a.Esquire)throw new Error("Esquire not available");var g={},h={};a.addEventListener("error",e,!0);var i=a.document;a.Esquire||(a.Esquire={}),a.Esquire.load=f}(window);