-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.Defertial.min.js
12 lines (12 loc) · 1.81 KB
/
jquery.Defertial.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/*!
* Defertial v0.1.2
* Doron Horwitz
* https://github.com/doronhorwitz/Defertial
* Date: 2014-03-12
*
* Copyright 2014 Doron Horwitz
* Released under the BSD New License
* https://raw.github.com/doronhorwitz/Defertial/master/LICENSE
*
*/
(function(b,d,f){var c="0.1.2";function g(h,k,l,j,i){return{isPreviousRejected:h,isGlobalRejected:k,previousArgs:l,deferred:j,previousReturnVal:i,isInDefertialQueue:true};}function e(m,l,k,i,h,j){m.done(function(){var n=g(false,false,d.makeArray(arguments),l,h.previousReturnVal);if(i===null){k.resolve(n);}else{h.previousReturnVal=i.func.apply(n,i.args);}}).fail(function(){if(j){var n=g(true,true,d.makeArray(arguments),l,h.previousReturnVal);k.reject(n);}else{var n=g(true,false,d.makeArray(arguments),l,h.previousReturnVal);if(i===null){k.reject(n);}else{h.previousReturnVal=i.func.apply(n,i.args);}}});}d.extend({Defertial:(function(){var h=[],m=0;function j(){if(this instanceof j){this._instID=m++;h[this._instID]=[];}else{return new j();}}d.extend(j.prototype,{add:function l(n){var o=d.makeArray(arguments).slice(1);if(d.isFunction(n)){h[this._instID].push({func:n,args:o});}return this;},run:function k(o,p){if(d.type(o)!=="boolean"){o=false;}if(arguments.length<2){p=[];}else{if(!d.isArray(p)){p=[p];}}var s=d.Deferred(),r=s.resolve.apply(s,p),q=d.Deferred(),n={previousReturnVal:null};d.each(h[this._instID],function(t,u){var v=d.Deferred();e(r,v,q,u,n,o);r=v;});e(r,null,q,null,n,o);return q;},loop:function i(r,p,n,o){var q=this;d.each(r,function(s,t){q.add(p,s,t);});return this.run(n,o);}});return j;})()});d.fn.extend({defertialEach:function(k,h,i){var j=new d.Defertial();return j.loop(d.makeArray(this),k,h,i);}});d.extend(d.Defertial,{version:c,isInDefertialQueue:function a(h){return(d.isPlainObject(h)&&("isInDefertialQueue" in h)&&(h.isInDefertialQueue==true));}});}(window,jQuery));