6 description: Contains Utility Classes that can be implemented into your own Classes to ease the execution of many common tasks.
8 license: MIT-style license.
12 provides: [Class.Extras, Chain, Events, Options]
19 this.Chain = new Class({
24 this.$chain.append(Array.flatten(arguments));
28 callChain: function(){
29 return (this.$chain.length) ? this.$chain.shift().apply(this, arguments) : false;
32 clearChain: function(){
39 var removeOn = function(string){
40 return string.replace(/^on([A-Z])/, function(full, first){
41 return first.toLowerCase();
45 this.Events = new Class({
49 addEvent: function(type, fn, internal){
50 type = removeOn(type);
53 if (fn == $empty) return this;
56 this.$events[type] = (this.$events[type] || []).include(fn);
57 if (internal) fn.internal = true;
61 addEvents: function(events){
62 for (var type in events) this.addEvent(type, events[type]);
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);
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];
88 removeEvents: function(events){
90 if (typeOf(events) == 'object'){
91 for (type in events) this.removeEvent(type, events[type]);
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]);
107 this.Options = new Class({
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];