working on it ...

Filters

Explore Public Snippets

Sort by

Found 359 snippets matching: client-side

    public by sTiLL-iLL @ SniPitz-KND  532543  3  8  21

    Ajax again?? Wrap it!! XHR Agent 4Ya

    XHR wrapper! object pooling and cueing!!! EveryOneZ dOing IT!
    
    var myXHR = {
           ESpec: function (wrap, evt) {
               return { xhrWrap: wrap, event: evt };
           },
           Agent: function(maxConnect) {
               var bCued = [], slf = this,
                   max = maxConnect || 3;
                   this.curCon = 0;
               function inCue() {
                   if (self.bCued < max) {
                       self.bCued++;
                       var itm = is.Readied.shift();
                       itm.evt.addEventListener(['EVENT_COMPLETE'], 
                         function (e) {
                             self.bCued--;
                             if (this.Readied.length !== 0) {
                               inCue();
                             }
                         });
                       itm.wrap.call(itm, args, itm.evt);
                    }
               }
               this.Readied = function (ESpec) {
                   bCued.push(ESpec);
                   inCue();
                   return ESpec.evt;
               };
            }
       };
    
                

    public by sTiLL-iLL @ SniPitz-KND  378509  6  9  29

    set.js... its my "Set", it runs this code-block

    Full on structure type implimentation of a Set
    
    // Set....   hut-1, hut-2, hike!
    
    function Set() {
       this.dStr = [];
       this.size = size;
       this.unionOf = unionOf;
       this.contains = contains;
       this.subSet = subSet;
       this.getDiff = getDiff;
       this.removeItem = removeItem;
       this.intersection = intersection;
       this.addItem = addItem;
       this.show = show;
    }
    
    function show() {
       return "[" + this.dStr + "]";
    }
    
    function size() {
       return this.dStr.length;
    }
    
    
    
    function addItem(dta) {
       if (this.dStr.indexOf(dta) < 0) {
          this.dStr.push(dta);
          return true;
       } 
       else {
          return false;
       }
    }
    
    function removeItem(dta) {
       var pstn = this.dStr.indexOf(dta);
       if (pstn > -1) {
          this.dStr.splice(pstn, 1);
          return true;
       }
       else {
          return false;
       }
    }
    
    function contains(dta) {
       if (this.dStr.indexOf(dta) > -1) {
          return true;
       }
       else {
          return false;
       }
    }
    
    function unionOf(set) {
       var tmp = new Set(),
           i = 0;
       for (;i < this.dStr.length; ++i) {
          tmp.add(this.dStr[i]);
       }
       i = 0;
       for (;i < set.dStr.length; ++i) {
          if (!tmp.contains(set.dStr[i])) {
             tmp.dStr.push(set.dStr[i]);
          }
       }
       return tmp;
    }
    
    function intersection(set) {
       var tSet = new Set();
       for (var i = 0; i < this.dStr.length; ++i) {
          if (set.contains(this.dStr[i])) {
             tSet.add(this.dStr[i]);
          }
       }
       return tmp;
    }
    
    function subSet(set) {
       if (this.size() > set.size()) {
          return false;
       }
       else {
          for each (var m in this.dStr) {
             if (!set.contains(m)) {
                return false;
             }
          }
       }
       return true;
    }
    i = 0;
    function difference(set) {
       var tmp = new Set();
       for (;i < this.dStor.length; ++i) {
          if (!set.contains(this.dStor[i])) {
             tmp.add(this.dStor[i]);
          }
       }
       return tmp;
    }  
    
    
    

    public by sTiLL-iLL @ SniPitz-KND  3599  4  8  25

    Enumerator.js... behind every enumeration you'll find a good Iterator. I guess.... LoL

    the future is now!
    // slick as snot Enumerable type!!!! yeah!
    
    var Enum = {
          create: function (collection) {
            var index=0;
            return {
              next: function() {
                if (index < collection.length) {
                  return ({ value: collection[index++], done: false });
                }
                else {
                  return ({ value: null, done: true});
                }
             }
          };
       }
    };
    
    // use it like this... (strings, bool, numbers, all gewd!)
    
    var arr=['rtJKvE', '!!@wrh', 433, 'yippe', 216,'PRdUrg', 3038, 'whaa?'],
      it = Enumerator.create(arr),
      primer = 0;
    
    while(primer !== null) {
      primer = it.next().value;
    	document.writeLine(primer);
    }
                

    public by sTiLL-iLL @ SniPitz-KND  2886  1  8  30

    Signals.js ... even more event insanity! ...

    Just another manifestation of my fixation on events.
    // Signals.js
    
    
    
    (function () {
    	
    	'use strict';
    	
    	function Signals () {};
    	var exports = this,
    		signalsMap = {},
    		_signalRtnVal_ = {},
    		signals = Signals.prototype;
      
    	function isAry(obj) {
    		return (obj.constructor === Array);
    	}
    	
    	function _setSignalOnceRV (val) {
    		_signalRtnVal_ = val;
    		return this;
    	}
    	
    	function _getSignalOnceRV () {
    		if (_signalRtnVal_) {
    			return _signalRtnVal_;
    		}
    		else {
    			return true;
    		}
    	}
    		
    	function wen(nam, func) {
    		if (!signalsMap) {
    			signalsMap = {};
    		}
    		if (!signalsMap[nam]) {
    			signalsMap[nam] = func;
    		} 
    		else if (isAry(signalsMap[nam])) {
    			signalsMap[nam].push(func);
    		} 
    		else {
    			signalsMap[nam] = [signalsMap[nam], func];
    		}	
    		return this;
    	}
      
    	signals.signaled = function(nam, func) {
    		return wen(nam, function(evnt){
    			return func(evnt);
    		});
    	};
    
    	signals.dropReceivers = function (nam) {
    		if (!nam) {
    			signalsMap = {};
    			return this;
    		}
    		if (signalsMap && signalsMap[nam]) {
    			signalsMap[nam] = null;
    		}
    		return this;
    	};
      
    	signals.receiverObjects = function (nam) {
    		var recvrLst = this.receivers(nam), rspns;	
    		if (isAry(recvrLst)) {
    			rspns = {};
    			rspns[nam] = recvrLst;
    		}	
    		return rspns || recvrLst;
    	};
     
    	signals.receivers = function (nam) {
    		if (!signalsMap) {
    			signalsMap = {};
    		}
    		if (!signalsMap[nam]) {
    			signalsMap[nam] = [];
    		}
    		if (!isAry(signalsMap[nam])) {
    			signalsMap[nam] = [signalsMap[nam]];
    		}
    		return signalsMap[nam];
    	};
    		
    	signals.addReceiver = function(nam, func) {
    		return wen(nam, function(evnt){
    			return func(evnt);
    		});
    	};
    	
    	signals.signaledOnce = function (nam, func) {
    		var slf = this;
    		function onit () {
    			slf.dropReceiver(nam, wen);
    			func.apply(this, args);
    		}
    		wen.receiver = func;
    		this.onit(nam, wen);	
    		return this;
    	};
    	
    	signals.receiveOnce = function(nam, func) {
    		return signaledOnce(nam, function(evnt) {
    			return func(evnt);
    		});
    	};
    
    	signals.dropReceiver = function (nam, func) {
    		if (signalsMap && signalsMap[nam]) {
    			var sigLst = signalsMap[nam];	
    			if (isAry(sigLst)) {
    				var idx = -1;
    				for (var i = 0, l = sigLst.length; i < l; i++) {
    					if (sigLst[i] === func || (sigLst[i].receiver && sigLst[i].receiver === func)) {
    						idx = i;
    						break;
    					}
    				}
    				if (idx < 0) {
    					return this;
    				}
    				sigLst.splice(idx, 1);
    				if (!sigLst.length) {
    					delete signalsMap[nam];
    				}
    			} 
    			else if (sigLst === func || (sigLst.receiver && sigLst.receiver === func)) {
    				delete signalsMap[nam];
    			}
    		}
    		return this;
    	};
    	 
    	signals.signal = function (nam, args) {
    		var recvrLst = this.receiverObjects(nam),
    		k, recvr, i, rspns;
    		for (k in recvrLst ) {
    			if (recvrLst.hasOwnProperty(k)) {
    				i = recvrLst[k].length;		
    				while (i--) {
    					recvr = recvrLst[k][i];
    					if (recvr.signaledOnce === true) {
    						this.dropReceiver(nam, recvr);
    					}	
    					rspns = recvr.call(this, args || []);
    					if (rspns === _getSignalOnceRV()) {
    						this.dropReceiver(nam, recvr);
    					}
    				}
    			}
    		}
    		return this;
    	};
    
    	if (typeof module === 'object' && module.exports){
    		module.exports = Signals;
    	}
    	else if (typeof define === 'function' && define.amd) {
    		define(function () {
    			return Signals;
    		});
    	}
    	else {
    		exports.Signals = Signals;
    	}
    	
    }.call(this));
                

    public by sTiLL-iLL @ SniPitz-KND  4100  1  8  21

    More EveNtIng MaDnEsS!

    A super fast and reliable eventbroker for the browser or server. Made it with Luv!
    
    (function () {
      
    	function Signals () {}
    	var exports = this,
    		signals = Signals.prototype;
      
    	function isAry(obj) {
    		return (obj.constructor === Array);
    	}
    		
    	signals.wen = function (nam, func) {
    		if (!this.sigsMap) {
    			this.sigsMap = {};
    		}
    		if (!this.sigsMap[nam]) {
    			this.sigsMap[nam] = func;
    		} 
    		else if (isAry(this.sigsMap[nam])) {
    			this.sigsMap[nam].push(func);
    		} 
    		else {
    			this.sigsMap[nam] = [this.sigsMap[nam], func];
    		}	
    		return this;
    	};
    	
    	signals.signaled = function(nam, func) {
    		return this.wen(nam, function(evnt){
    			return func(evnt);
    		});
    	};
    
    	signals.removeReceivers = function (nam) {
    		if (!nam) {
    			this.sigsMap = {};
    			return this;
    		}
    		if (this.sigsMap && this.sigsMap[nam]) {
    			this.sigsMap[nam] = null;
    		}
    		return this;
    	};
    	
    	signals.receiverObjects = function (nam) {
    		var recvrLst = this.receivers(nam), rspns;	
    		if (isAry(recvrLst)) {
    			rspns = {};
    			rspns[nam] = recvrLst;
    		}	
    		return rspns || recvrLst;
    	};
    	 
    	signals.receivers = function (nam) {
    		if (!this.sigsMap) {
    			this.sigsMap = {};
    		}
    		if (!this.sigsMap[nam]) {
    			this.sigsMap[nam] = [];
    		}
    		if (!isAry(this.sigsMap[nam])) {
    			this.sigsMap[nam] = [this.sigsMap[nam]];
    		}
    		return this.sigsMap[nam];
    	};
    		
    	signals.addReceiver = signals.wen;
    	signals.signaledOnce = function (nam, func) {
    		var slf = this;
    		function onit () {
    			slf.removeReceiver(nam, wen);
    			func.apply(this, args);
    		}
    		wen.receiver = func;
    		this.onit(nam, wen);	
    		return this;
    	};
    
    	signals.removeReceiver = function (nam, func) {
    		if (this.sigsMap && this.sigsMap[nam]) {
    			var sigLst = this.sigsMap[nam];	
    			if (isAry(sigLst)) {
    				var idx = -1;
    				for (var i = 0, l = sigLst.length; i < l; i++) {
    					if (sigLst[i] === func || (sigLst[i].receiver && sigLst[i].receiver === func)) {
    						idx = i;
    						break;
    					}
    				}
    				if (idx < 0) {
    					return this;
    				}
    				sigLst.splice(idx, 1);
    				if (!sigLst.length) {
    					delete this.sigsMap[nam];
    				}
    			} 
    			else if (sigLst === func || (sigLst.receiver && sigLst.receiver === func)) {
    				delete this.sigsMap[nam];
    			}
    		}
    		return this;
    	};
    	 
    	signals._setSignalOnceRV = function (val) {
    		this._signalRtnVal_ = val;
    		return this;
    	};
    
    	signals._getSignalOnceRV = function () {
    		if (this.hasOwnProperty('_signalRtnVal_')) {
    			return this._signalRtnVal_;
    		}
    		else {
    			return true;
    		}
    	};
    	 
    	signals.signal = function (nam, args) {
    		var recvrLst = this.receiverObjects(nam),
    		k, recvr, i, rspns;
    		for (k in recvrLst ) {
    			if (recvrLst.hasOwnProperty(k)) {
    				i = recvrLst[k].length;		
    				while (i--) {
    					recvr = recvrLst[k][i];
    					if (recvr.signaledOnce === true) {
    						this.removeReceiver(nam, recvr);
    					}	
    					rspns = recvr.call(this, args || []);
    					if (rspns === this._getSignalOnceRV()) {
    						this.removeReceiver(nam, recvr);
    					}
    				}
    			}
    		}
    		return this;
    	};
    
    	if (typeof module === 'object' && module.exports){
    		module.exports = Signals;
    	}
    	else if (typeof define === 'function' && define.amd) {
    		define(function () {
    			return Signals;
    		});
    	}
    	else {
    		exports.Signals = Signals;
    	}
    	
    }.call(this));
    
    
    var Signals = function () {
    	
    	'use strict';
    	
    	var sigCache = {};
    	
    	function isAry(obj) {
    		return (obj.constructor === Array);
    	}
    	
    	function receiverObjects(eventName) {
    		var recvrLst = receivers(eventName), rspns;	
    		if (isAry(recvrLst)) {
    			rspns = {};
    			rspns[eventName] = recvrLst;
    		}	
    		return rspns || recvrLst;
    	}
    	
    	function receivers(eventName) {
    		if (!sigCache) {
    			sigCache = {};
    		}
    		if (!sigCache[eventName]) {
    			sigCache[eventName] = [];
    		}
    		if (!isAry(sigCache[eventName])) {
    			sigCache[eventName] = [sigCache[eventName]];
    		}
    		return sigCache[eventName];
    	}
    	
    	function wen(eventName, func) {
    		if (!sigCache) {
    			sigCache = {};
    		}
    		if (!sigCache[eventName]) {
    			sigCache[eventName] = func;
    		} 
    		else if (isAry(sigCache[eventName])) {
    			sigCache[eventName].push(func);
    		} 
    		else {
    			sigCache[eventName] = [sigCache[eventName], func];
    		}
    		return this;
    	}
    	
    	var addReceiver = function(eventName, func) {
    		return wen(eventName, function(evnt){
    			return func(evnt);
    		});
    	},
    	signalReceived = function(eventName, func) {
    		return wen(eventName, function(evnt){
    			return func(evnt);
    		});
    	},
    	dropReceivers = function (eventName) {
    		if (!eventName) {
    			sigCache = {};
    			return this;
    		}
    		if (sigCache && sigCache[eventName]) {
    			sigCache[eventName] = null;
    		}
    		return this;
    	},    
    	signalOnce = function (eventName, func) {
    		var slf = this;
    		function onit () {
    			slf.dropReceiver(eventName, wen);
    			func.apply(this, args);
    		}
    		wen.receiver = func;
    		this.onit(eventName, wen);	
    		return this;
    	},
    	dropReceiver = function (eventName, func) {
    		if (sigCache && sigCache[eventName]) {
    			var sigLst = sigCache[eventName];	
    			if (isAry(sigLst)) {
    				var idx = -1;
    				for (var i = 0, l = sigLst.length; i < l; i++) {
    					if (sigLst[i] === func || (sigLst[i].receiver && sigLst[i].receiver === func)) {
    						idx = i;
    						break;
    					}
    				}
    			
    				if (idx < 0) {
    					return this;
    				}
    			
    				sigLst.splice(idx, 1);
    				if (!sigLst.length) {
    					delete sigCache[eventName];
    				}
    			} 
    			else if (sigLst === func || (sigLst.receiver && sigLst.receiver === func)) {
    				delete sigCache[eventName];
    			}
    		}
    		return this;
    	},  
    	setSingleRV = function (val) {
    		singleRtnVal = val;
    		return this;
    	},  
    	getSingleRV = function() {
    		if (sigCache.hasOwnProperty('singleRtnVal')) {
    			return singleRtnVal;
    		}
    		else {
    			return true;
    		}
    	},	 
    	castSignal = function(eventName, args) {
    		var recvrLst = receiverObjects(eventName),
    		k, recvr, i, rspns;
    		for (k in recvrLst ) {
    			if (recvrLst.hasOwnProperty(k)) {
    				i = recvrLst[k].length;		
    				while (i--) {
    					recvr = recvrLst[k][i];
    					if (recvr.signalOnce === true) {
    						dropReceiver(eventName, recvr);
    					}	
    					rspns = recvr.call(this, args || []);
    					if (rspns === getSingleRV()) {
    						dropReceiver(eventName, recvr);
    					}
    				}
    			}
    		}
    		return this;
       };
       return {
    		signal: castSignal,
    		signaled: signalReceived,
    		receive: addReceiver,
    		receivers: receivers,
    		receiveOnce: signalOnce,
    		dropReceiver: dropReceiver,
    		dropReceivers: dropReceivers
    	};
    };
    
    exports.Signals = Signals;
    
    

    public by sTiLL-iLL @ SniPitz-KND  3706  0  8  22

    Lazy Loaded...... Lazy.js

    load your images on demand...
    // another lazy  image loader thang.....
    
    var lazy=(function() {
        this.load=function(elem, res) {
          if (document.querySelectorAll) {
              res=document.querySelectorAll(elem);
          } else {
            var dok=document, 
              sheet=dok.styleSheets[0] ||
              dok.createStyleSheet();
              sheet.addRule(elem,'foo:idx');
            for(var ln=dok.all,idx=0,lst=[],f=l.length;idx<foo;idx++) {
              (ln[isx].currentStyle.foo&&lst.push(ln[idx]));
            }
            sheet.removeRule(0);
            res=clst;
          }
          return res;
        }; 
        var receive=function(evt,func) {
          window.addEventListener?this.addEventListener(evt,func,false) :
            (window.attachEvent)?this.attachEvent('on'+evt,func):
            (this['on'+evt]=func);
        };
        var itHaz=function(k,object) {
          return Object.prototype.hasOwnProperty.call(k,object);
        };
        this.getLoaded=function(elem,func) {
          var img=new Image(),
          prnt=elem.parent;
          img.src=elem.getAttribute('data-src');
          img.addEventListener("load",function(evt) {
          if (!elem.parent) {
            prnt.replaceChild(img, elem)
          } else {
            elem.src=src;
          }
          (func)?func(): null;
        });
        img.src=src;
      };
      function inView(elem){
        var r=elem.getBoundingClientRect();
        return(r.top>=0&&r.left>=0&&
          r.top<=(window.innerHeight||
            document.documentElement.clientHeight)
          );
      }
      function cBak(pix, idx){
        return (pix.splice(idx,idx));
      }
      var pix=[],qry=layzee('img.lazy');
      this.doWork=function(){
        for (var idx=0;idx<images.length;idx++) {
          if (inView(pix[idx])){
            return getLoaded(pix[idx],cBak(pix,idx));
          }
        }
      };
      for (var idx=0;idx<qry.length;idx++) {
        pix.push(qry[idx]);
      }
      doWork();
      receive('scroll',dowork);
    }(this));                      

    public by sTiLL-iLL @ SniPitz-KND  3517  0  7  19

    KachingFetch.js get it boy! woof! good dog....

    I modeled it after jquery's "getScript" only better.... cause it caches!!!
    
    // caching script fetcher  //
     
    var futrs = {};
     
     var ajaxFetch = function( url, cBak ) {
         if ( !futrs[ url ] ) {
             futrs[ url ] = $.Deferred(function( defer ) {
                 $.getScript( url )
                     .then( defer.resolve, defer.reject );
                 }).promise();
           }
         return futrs[ url ].done( cBak );
     };
     
    /*-----------------------------------------------------------------------*/
     
        // <<  use it! >>
      ajaxFetch('//totalPorn247.com/freeVideos/Tits+Ass?=199BOOBzInVIEW.js', cBak);
     
      function cBak(resp) {
          if(resp.length > 0) {
              var dd = document.querySelector('#resultDiv');
              dd.innerHTML = renderDirtyWords(a, z, 125);                        
          }  
      }
            
                

    public by sTiLL-iLL @ SniPitz-KND  3101  1  7  19

    Promise-Defer..... then-bindsTo (100% working)

    highly performant async transmission agent. functional units are expressed with a declarative syntax. Just try and break this promise,
    // deferred execution!!!
    
    this.Promise = function () {
    		return {
    			status: 'pending',
    			error: null,
    			posCBKs: [],
    			negCBKs: [],
    			then: function (posCBK, negCBK) {
    				var defer = new Deferred();
    				posCBK = (!posCBK)? function(d){d = (d || true); return d;}:posCBK;
    				negCBK = (!negCBK)? function(d){d = (d || true); return d;}:negCBK;
    				this.posCBKs.push({
    					func: posCBK,
    					deferred: defer
    				});				
    				this.negCBKs.push({
    					func: negCBK,
    					deferred: defer
    				});
    				if (status === 'resolved') {
    					this.execAction({
    						func: posCBK,
    						deferred: defer
    					}, this.data);
    				}
    				else if (status === 'rejected') {
    					this.execAction({
    						func: negCBK,
    						deferred: defer
    					}, this.error);
    				}
    				return defer.promise;
    			},
    			execAction: function (callbackData, result) {
    				wdw.setTimeout(function () {
    					var res = callbackData.func(result);
    					if (res instanceof Promise) {
    						callbackData.deferred.bind(res);
    					}
    					else {
    						callbackData.deferred.resolve(res);
    					}
    				}, 0);
    			}
    		};
    	};
    	this.Deferred = function () {
    		return {
    			promise: new Promise(),
    			resolve: function (data) {
    				var pms = this.promise;
    				pms.data = data;
    				pms.status = 'resolved';
    				if (pms.posCBKs) {
    					pms.posCBKs.forEach(function (dta) {
    						pms.execAction(dta, data);
    					});
    				}
    			},
    			reject: function (err) {
    				var pms = this.promise;
    				pms.error = err;
    				pms.status = 'rejected';
    				if (pms.negCBks) {
    					pms.negCBKs.forEach(function (dta) {
    						pms.execAction(dta, err);
    					});
    				}
    			},
    			bind: function (promise) {
    				var slf = this;
    				promise.then(function (dta) {
    					slf.resolve(dta);
    				}, function (err) {
    					slf.reject(err);
    				});
    			}
    		};
    	};

    public by sTiLL-iLL @ SniPitz-KND  2921  1  7  16

    PromDuffuhrd.js wuhrkz gouuwd. eY PruMISe!

    best yet....
    
    (function (GlOb) {
        function isItArray(ary) {
            return (ary.prototype ===  Array);
        }
    
        function foreach(ary, cBak) {
            if (isItArray(ary)) {
                for (var i = 0; i < ary.length; i++) {
                    cBak(ary[i]);
                }
            }
            else {
                cBak(ary);
            }
        }
    
        function stoopiD(fn) {
            var status = 'pending', dunMemberz = [], failedMemberz = [],
                proggyMemberz = [], nArgz = null,
    		    promise = {
    		        done: function () {
    		          for (var i = 0; i < arguments.length; i++) {
    		            if (!arguments[i]) {
    		                continue;
    		            }
    
    		            if (isItArray(arguments[i])) {
    		                var ary = arguments[i], j = 0,
                                ln = ary.length;
    		                for (; j < ln; j++) {
    		                    if (status === 'resolved') {
    		                        ary[j].apply(this, nArgz);
    		                    }
    		                    dunMemberz.push(ary[j]);
    		                }
    		            }
    		            else {
    		                if (status === 'resolved') {
    		                    arguments[i].apply(this, nArgz);
    		                }
    		                dunMemberz.push(arguments[i]);
    		            }
    		        }
    
    		        return this;
    		    },
    
    		    fail: function () {
    		        for (var i = 0; i < arguments.length; i++) {
    		            if (!arguments[i]) {
    		                continue;
    		            }
    
    		            if (isItArray(arguments[i])) {
    		                var ary = arguments[i],
                                j = 0, ln = ary.length;
    		                for (; j < ln; j++) {
    		                    if (status === 'rejected') {
    		                        ary[j].apply(this, nArgz);
    		                    }
    
    		                    failedMemberz.push(ary[j]);
    		                }
    		            }
    		            else {
    		                if (status === 'rejected') {
    		                    arguments[i].apply(this, nArgz);
    		                }
    
    		                failedMemberz.push(arguments[i]);
    		            }
    		        }
    		        return this;
    		    },
    
    		    always: function () {
    		        return this.done.apply(this, arguments).fail.apply(this, arguments);
    		    },
    
    		    progress: function () {
    		        var i = 0, ln = ary.length;
    		        for (; i < ln; i++) {
    		            if (!arguments[i]) {
    		                continue;
    		            }
    
    		            if (isItArray(arguments[i])) {
    		                var ary = arguments[i],
                                j = 0, ln = ary.length;
    		                for (; j < ln; j++) {
    		                    if (status === 'pending') {
    		                        proggyMemberz.push(ary[j]);
    		                    }
    		                }
    		            }
    		            else {
    		                if (status === 'pending') {
    		                    proggyMemberz.push(arguments[i]);
    		                }
    		            }
    		        }
    
    		        return this;
    		    },
    
    		    then: function () {
    		        if (arguments.length > 1 && arguments[1]) {
    		            this.fail(arguments[1]);
    		        }
    		        if (arguments.length > 0 && arguments[0]) {
    		            this.done(arguments[0]);
    		        }
    		        if (arguments.length > 2 && arguments[2]) {
    		            this.progress(arguments[2]);
    		        }
    		    },
    
    		    promise: function (objkt) {
    		        if (objkt == null) {
    		            return promise;
    		        } else {
    		            for (var i in promise) {
    		                objkt[i] = promise[i];
    		            }
    		            return objkt;
    		        }
    		    },
    
    		    state: function () {
    		        return status;
    		    },
    
    		    isRejected: function () {
    		        return status === 'rejected';
    		    },
    
    		    isResolved: function () {
    		        return status === 'resolved';
    		    },
    
    		    pipe: function (done, fail, progress) {
    		        return stoopiD(function (def) {
    		            foreach(done, function (func) {
    		                if (typeof func === 'function') {
    		                    deferred.done(function () {
    		                        var returnval = func.apply(this, arguments);
    		                        if (returnval && typeof returnval === 'function') {
    		                            returnval.promise().then(def.resolve, def.reject, def.notify);
    		                        }
    		                        else {
    		                            def.resolve(returnval);
    		                        }
    		                    });
    		                }
    		                else {
    		                    deferred.done(def.resolve);
    		                }
    		            });
    
    		            foreach(fail, function (func) {
    		                if (typeof func === 'function') {
    		                    deferred.fail(function () {
    		                        var returnval = func.apply(this, arguments);
    
    		                        if (returnval && typeof returnval === 'function') {
    		                            returnval.promise().then(def.resolve, def.reject, def.notify);
    		                        } else {
    		                            def.reject(returnval);
    		                        }
    		                    });
    		                }
    		                else {
    		                    deferred.fail(def.reject);
    		                }
    		            });
    		        }).promise();
    		    }
    		},
    
    		deferred = {
    		    resolveWith: function (context) {
    		        if (status === 'pending') {
    		            status = 'resolved';
    		            var argz = (nArgz = (arguments.length > 1) ? arguments[1] : []);
    		            for (var i = 0; i < dunMemberz.length; i++) {
    		                dunMemberz[i].apply(context, argz);
    		            }
    		        }
    		        return this;
    		    },
    
    		    rejectWith: function (context) {
    		        if (status === 'pending') {
    		            status = 'rejected';
    		            var argz = (nArgz = (arguments.length > 1) ? arguments[1] : []);
    		            for (var i = 0; i < failedMemberz.length; i++) {
    		                failedMemberz[i].apply(context, argz);
    		            }
    		        }
    		        return this;
    		    },
    
    		    notifyWith: function (context) {
    		        if (status === 'pending') {
    		            var argz = (nArgz = (arguments.length > 1) ? arguments[1] : []);
    		            for (var i = 0; i < proggyMemberz.length; i++) {
    		                proggyMemberz[i].apply(context, argz);
    		            }
    		        }
    		        return this;
    		    },
    
    		    resolve: function () {
    		        return this.resolveWith(this, arguments);
    		    },
    
    		    reject: function () {
    		        return this.rejectWith(this, arguments);
    		    },
    
    		    notify: function () {
    		        return this.notifyWith(this, arguments);
    		    }
    		};
    
            var objkt = promise.promise(deferred);
    
            if (fn) {
                fn.call(objkt, objkt);
            }
    
            return objkt;
        }
    
        stoopiD.when = function () {
            if (arguments.length < 2) {
                var objkt = arguments.length ? arguments[0] : undefined;
                if (objkt && (typeof objkt.isResolved === 'function' && typeof objkt.isRejected === 'function')) {
                    return objkt.promise();
                }
                else {
                    return stoopiD().resolve(objkt).promise();
                }
            }
            else {
                return (function (argz) {
                    var dufurd = stoopiD(),
    					size = argz.length,
    					done = 0, fuk = new Array(size);
                    var i = 0, ln = ary.length;
                    for (; i < ln; i++) {
                        (function (j) {
                            var objkt = null;
                            if (argz[j].done) {
                                argz[j].done(function () {
                                    fuk[j] = (arguments.length < 2) ? arguments[0] : arguments;
                                    if (++done == size) {
                                        dufurd.resolve.apply(dufurd, fuk);
                                    }
                                })
                                .fail(function () {
                                    dufurd.reject(arguments);
                                });
                            } else {
                                objkt = argz[j];
                                argz[j] = new Deferred();
                                argz[j].done(function () {
                                    fuk[j] = (arguments.length < 2) ? arguments[0] : arguments;
                                    if (++done == size) {
                                        dufurd.resolve.apply(dufurd, fuk);
                                    }
                                })
                                .fail(function () {
                                    dufurd.reject(arguments);
                                }).resolve(objkt);
                            }
                        })(i);
                    }
                    return dufurd.promise();
                })(arguments);
            }
        };
        GlOb.Deferred = stoopiD;
    })(window);            

    public by sTiLL-iLL @ SniPitz-KND  2230  0  7  18

    ArRAy heLPEr-OuTER.... yeah....

    find the index of an object by the value of one of its properties... pretty effn kewel!
      // Array helper OutEr
    
    var getIDXByProp = function (arr, prop, val) {
            var a = arr, p = prop, v = val;
            if(a && p && v) {
              return getIndex(a,p,v);
            }
            function getIndex(a, p, v) {
              var i = 0;
              for (;i < a.length; i++) {
                  if (a[i] == v) {
                      return i;
                  }
                  else if (pathGet(a[i], p) == v) {
                      return i;
                  }
              }
              return -1;
            };
              
            function pthGet (o, k, lft) {
                  if ( lft === undefined ) {
                      lft = k.split('.');
                  }
                  var cur = lft.shift();
                  if ( typeof(o) == 'object' && o[cur] !== undefined ) {
                      if ( lft.length === 0 ) {
                          return o[cur];
                      } 
                      else if ( typeof(o[cur]) == 'object' ) {
                          return arguments.callee(o[cur], undefined, lft);
                      }
                  }
                return null;
            }
      };
    
    • Public Snippets
    • Channels Snippets