-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink-min.js
1 lines (1 loc) · 2.45 KB
/
link-min.js
1
(function(){root=this;root.linkjs=function(a){function i(a){for(var b in a)if(a.hasOwnProperty(b))return false;return true}var b=a;b.context=b.context||this;if(!a||typeof b.funcs!=="object"||i(a.funcs))throw Error("you should specified funcs to work with");for(var c in a.funcs){if(typeof a.funcs[c]!=="function")throw Error('Your function for "'+c+'" is not really a function');if(c==="callback")throw Error('You are going to overide "callback", please use cb to start chaining');if(c==="cb")throw Error('You are going to overide "cb", please use callback to start chaining');if(c==="loop")throw Error('You are going to overide "loop", it won\'t be accessible anymore');if(c==="chain")throw Error('You are going to overide "chain", it won\'t be accessible anymore');if(c==="reverse")throw Error('You are going to overide "reverse", it won\'t be accessible anymore');if(c==="random")throw Error('You are going to overide "random", it won\'t be accessible anymore')}var d=[];var e=function(a){var c=-1;l=d.length;if(!l)return;for(;++c<l;){var e=d[c];e.func.apply(b.context||a,e.args)}};var f=function(a){var c=d.length;if(!c)return;for(;c--;){var e=d[c];e.func.apply(b.context||a,e.args)}};var g=function(a){var c=d.length+1;if(!c)return;for(;c-->1;){var e=Math.floor(Math.random()*c);var f=d.splice(e,1);f[0].func.apply(b.context||a,f[0].args)}};var h=function(a,c){var e=-1,f=d.length,g;if(!f)return;for(;++e<f;){if(g=d[e+1]){d[e].args[d[e].args.length]=function(){var c=g;var d=b.context;return function(){var b=-1,e=c.args.length;for(;++b<e;){arguments[arguments.length]=c.args[b];arguments.length++}c.func.apply(d||a,arguments)}}();d[e].args.length++}else if(c){g=d[0];d[e].args[d[e].args.length]=function(){var c=g;var d=b.context;return function(){var b=-1,e=c.args.length;for(;++b<e;){arguments[arguments.length]=c.args[b];arguments.length++}c.func.apply(d||a,c.args)}}();d[e].args.length++}}d[0].func.apply(b.context||a,d[0].args)};initCallback=function(a,c){h(c);d=[];b.context=a||b.context;return c};var j=function(){};j.prototype={callback:function(a){return initCallback(a,this)},cb:function(a){return initCallback(a,this)},loop:function(a){h(this,true);d=[];b.context=a||b.context;return this},chain:function(){e(this);d=[];return this},reverse:function(){f(this);d=[];return this},random:function(){g(this);d=[];return this}};for(var c in b.funcs){j.prototype[c]=function(){var a=c;return function(){d.push({func:b.funcs[a],args:arguments});return this}}()}return new j};return root}).call(this)