text: (function(z){function k(a,b){this.chain=a;this.active=b||!1;this.completed=!0;this.state="";this.dfds=[];this.failCallbacks=[];this.nextLevel=null}function A(a,b,e,d,l){function q(){for(var a=0;a<c.length&&k&&!m&&0!==c[a].s;a++)null!==c[a].args&&n.args.push.apply(n.args,c[a].args),c.splice(a,1),a--;0!==c.length||m||(m=!0,e("resolved",n))}this.args=[];this.promise=new h;var n=this,f=this.promise,c=[],m=!1,k=!1,t;a=0;for(t=b.length;a<t;a++){if(b[a]===p)throw Error("Undefined sent to push/add. Did you forget to return a deferred?");
  c.push({d:b[a],s:0,args:null})}a=0;for(t=c.length;a<t&&!m;a++)if("function"===typeof c[a].d)c[a].s=1,this.promise.done(c[a].d);else{if("function"!==typeof c[a].d.then)throw Error("Invalid deferred sent to chain");(function(a){a.d.then(function(){a.args=g.call(arguments);a.s=1;var b=this;f.done(function(){l.set(b);for(var a=0;a<d.length;a++)b===d[a].d&&(f.done(d[a].func),d.splice(a,1),a--)});q()},function(){n.args=g.call(arguments);var a=this;f.fail(function(){l.set(a);for(var b=0;b<d.length;b++)a===
  d[b].d&&(f.fail(d[b].func),d.splice(b,1),b--)});m||(m=!0,e("rejected",n))})})(c[a])}k=!0;q()}function h(a){this.ctx=a||this;this.s="pending";this.args=null;this.callbacks=[]}function w(){}function u(){function a(){for(var a=0;a<n.length;a++)n[a].call(d),n.splice(a,1),a--}function b(b,v){var e=c!==p,r;if(e&&"rejected"===c.state)return new w;r=new k(d,!e||c.completed);r.addFailCallback(a);e&&(c.nextLevel=r);c=r;return r[b](v,l,q)}function e(b,v){c===p&&(c=new k(this,!0),c.addFailCallback(a));return c[b](v,
  l,q)}var d=this,l=[],q=new x,n=[],f,c,m;this.push=this.next=function(){return b("requireDeferreds",g.call(arguments))};this.add=function(){return e("requireDeferreds",g.call(arguments))};this.pushIgnoreFail=this.nextIgnoreFail=function(){return b("optionalDeferreds",g.call(arguments))};this.addIgnoreFail=function(){return e("optionalDeferreds",g.call(arguments))};this.done=this.after=this.then=function(a,b){b?this.add(a):this.push(a);return this};this.then=function(a,b){var c,d;if("function"===typeof a)this.done(a);
  else if(null!=a)for(c=0,d=a.length;c<d;c++)this.done(a[c]);if("function"===typeof b)this.fail(b);else if(null!=b)for(c=0,d=b.length;c<d;c++)this.fail(b[c]);return this};this.fail=this["catch"]=function(a){c===p?n.push(a):c.addFailCallback(a);return this};var s=function(a,b,c){return function(){var e;e=c===p?function(){a.apply(b,g.call(arguments))}:function(){a.apply(b,c.concat(g.call(arguments)));c.length=0};this===d||this instanceof h||q.has(this)?e.apply(this,g.call(arguments)):l.push({d:this,func:e,
  s:this.state()})}};this.bind=function(a,b){return 3>arguments.length?s(a,b):s(a,b,g.call(arguments,2))};this.applyArgs=function(a,b){if(3>arguments.length)return f===p&&(f=[]),s(a,b,f);var c=g.call(arguments,2);return function(){var d=(f||[]).splice(0,f.length).concat(c).concat(g.call(arguments));s(a,b,d).call(this)}};this.storeArgs=function(){var a=g.call(arguments),b=function(){f===p&&(f=[]);f.push.apply(f,a)};if(this===d)return b;this instanceof h||q.has(this)?b():l.push({d:this,func:b,s:this.state()})};
  this.always=function(a){return this.fail(a).done(a)};this.fork=function(){var a=new u;a.push(this);return a};this.state=function(){return c===p?"pending":("ignored"===c.state?"rejected":c.state)||"pending"};this.promise=function(){if(m===p){var a=function(a,b){return function(c,d,e){return a.call(b,c,d,e)}};m={state:this.state,done:a(this.done,this),fail:a(this.fail,this),always:a(this.always,this),then:a(this.then,this)}}return m}}var x=z.WeakMap,g=[].slice,B=function(){return this},p;x===p&&(x=
  function(){var a=[];this.has=function(b){var e=-1;for(null!=b&&(e=a.length-1);0<=e&&a[e]!==b;)e--;return-1<e};this.set=function(b){a.push(b)}});k.prototype.newGroup=function(a,b,e,d){""===this.state&&(this.completed=!1);var l={s:0,r:this.active};this.dfds.push(l);return new A(this.chain,a,function(a,d){l.g=d;l.s=1;b(a,l.r)},e,d)};k.prototype.requireDeferreds=function(a,b,e){var d=this;return this.newGroup(a,function(a,b){switch(a){case "resolved":""===d.state&&(d.state="resolved");break;case "rejected":d.state=
  "rejected"}b&&d.complete()},b,e).promise};k.prototype.optionalDeferreds=function(a,b,e){var d=this;return this.newGroup(a,function(a,b){switch(a){case "resolved":""===d.state&&(d.state="resolved");break;case "rejected":d.state="ignored"}b&&d.complete()},b,e).promise};k.prototype.addFailCallback=function(a){"ignored"===this.state||"rejected"===this.state?a.call(this.chain):this.completed&&""!==this.state||this.failCallbacks.push(a)};k.prototype.complete=function(){this.active=!0;for(var a=0;a<this.dfds.length;a++){if("function"===
  typeof this.dfds[a])this.dfds[a]();else{this.dfds[a].r=!0;if(0===this.dfds[a].s)break;this.dfds[a].g.complete(this.state)}this.dfds.splice(a,1);a--}0===this.dfds.length&&(this.completed=!0);!0===this.completed&&("rejected"===this.state?this.failed():(this.cleanup(!0),null!==this.nextLevel&&this.nextLevel.complete()))};k.prototype.failed=function(){for(var a=0;a<this.failCallbacks.length;a++)this.failCallbacks[a].call(this.chain),this.failCallbacks.splice(a,1),a--;this.cleanup(!0);null!==this.nextLevel&&
  this.nextLevel.failed()};k.prototype.cleanup=function(a){var b,e;for(b=0;b<this.dfds.length;b++)this.dfds[b].r=!1,this.dfds.splice(b,1),b--;b=0;for(e=this.failCallbacks.length;b<e;b++)this.failCallbacks.shift();null!==this.nextLevel&&!0!==a&&this.nextLevel.cleanup()};A.prototype.complete=function(a){var b=this.promise.callbacks;"pending"===this.promise.s&&(this.promise.s="ignored"===a?"rejected":a,this.promise.args=this.args);for(a=0;a<b.length;a++)b[a].s===this.promise.s&&b[a].f.apply(this.promise.ctx,
  this.promise.args),b.splice(a,1),a--};h.prototype.done=function(){var a,b;if("resolved"===this.s)for(a=0,b=arguments.length;a<b;a++)arguments[a].apply(this.ctx,this.args);else if("pending"===this.s)for(a=0,b=arguments.length;a<b;a++){if("function"!==typeof arguments[a])throw Error("Invalid function sent to done "+typeof arguments[a]);this.callbacks.push({s:"resolved",f:arguments[a]})}return this};h.prototype.then=function(a,b){"function"===typeof a?this.done(a):null!=a&&this.done.apply(this,a);"function"===
  typeof b?this.fail(b):null!=b&&this.fail.apply(this,b);return this};h.prototype.fail=function(){var a,b;if("rejected"===this.s)for(a=0,b=arguments.length;a<b;a++)arguments[a].apply(this.ctx,this.args);else if("pending"===this.s)for(a=0,b=arguments.length;a<b;a++){if("function"!==typeof arguments[a])throw Error("Invalid function sent to fail "+typeof arguments[a]);this.callbacks.push({s:"rejected",f:arguments[a]})}return this};h.prototype["catch"]=h.prototype.fail;h.prototype.always=function(){var a=
  g.call(arguments);return this.fail.apply(this,a).done.apply(this,a)};h.prototype.state=function(){return this.s};for(var y in h.prototype)h.prototype.hasOwnProperty(y)&&"function"===typeof h.prototype[y]&&(w.prototype[y]=B);w.prototype.state=function(){return"pending"};"undefined"!==typeof module?module.exports=u:(z.ChainLoading=u,"function"===typeof define&&"object"===typeof define.amd&&define.amd&&define("ChainLoading",function(){return u}))})(this);
  