1/* 2--- 3 4name: Class.Extras 5 6description: Contains Utility Classes that can be implemented into your own Classes to ease the execution of many common tasks. 7 8license: MIT-style license. 9 10requires: Class 11 12provides: [Class.Extras, Chain, Events, Options] 13 14... 15*/ 16 17(function(){ 18 19this.Chain = new Class({ 20 21 $chain: [], 22 23 chain: function(){ 24 this.$chain.append(Array.flatten(arguments)); 25 return this; 26 }, 27 28 callChain: function(){ 29 return (this.$chain.length) ? this.$chain.shift().apply(this, arguments) : false; 30 }, 31 32 clearChain: function(){ 33 this.$chain.empty(); 34 return this; 35 } 36 37}); 38 39var removeOn = function(string){ 40 return string.replace(/^on([A-Z])/, function(full, first){ 41 return first.toLowerCase(); 42 }); 43}; 44 45this.Events = new Class({ 46 47 $events: {}, 48 49 addEvent: function(type, fn, internal){ 50 type = removeOn(type); 51 52 /*<1.2compat>*/ 53 if (fn == $empty) return this; 54 /*</1.2compat>*/ 55 56 this.$events[type] = (this.$events[type] || []).include(fn); 57 if (internal) fn.internal = true; 58 return this; 59 }, 60 61 addEvents: function(events){ 62 for (var type in events) this.addEvent(type, events[type]); 63 return this; 64 }, 65 66 fireEvent: function(type, args, delay){ 67 type = removeOn(type); 68 var events = this.$events[type]; 69 if (!events) return this; 70 args = Array.from(args); 71 events.each(function(fn){ 72 if (delay) fn.delay(delay, this, args); 73 else fn.apply(this, args); 74 }, this); 75 return this; 76 }, 77 78 removeEvent: function(type, fn){ 79 type = removeOn(type); 80 var events = this.$events[type]; 81 if (events && !fn.internal){ 82 var index = events.indexOf(fn); 83 if (index != -1) delete events[index]; 84 } 85 return this; 86 }, 87 88 removeEvents: function(events){ 89 var type; 90 if (typeOf(events) == 'object'){ 91 for (type in events) this.removeEvent(type, events[type]); 92 return this; 93 } 94 if (events) events = removeOn(events); 95 for (type in this.$events){ 96 if (events && events != type) continue; 97 var fns = this.$events[type]; 98 for (var i = fns.length; i--;) if (i in fns){ 99 this.removeEvent(type, fns[i]); 100 } 101 } 102 return this; 103 } 104 105}); 106 107this.Options = new Class({ 108 109 setOptions: function(){ 110 var options = this.options = Object.merge.apply(null, [{}, this.options].append(arguments)); 111 if (this.addEvent) for (var option in options){ 112 if (typeOf(options[option]) != 'function' || !(/^on[A-Z]/).test(option)) continue; 113 this.addEvent(option, options[option]); 114 delete options[option]; 115 } 116 return this; 117 } 118 119}); 120 121})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.