A Utility Class which executes functions one after another, with each function firing after completion of the previous. Its methods can be implemented with Class:implement into any Class, and it is currently implemented in Fx and Request. In Fx, for example, it is used to create custom, complex animations.
var MyClass = new Class({ Implements: Chain });
MyClass.implement(Chain);
var myChain = new Chain;
var Todo = new Class({ Implements: Chain, initialize: function(){ this.chain.apply(this, arguments); } }); var myTodoList = new Todo( function(){ alert('get groceries'); }, function(){ alert('go workout'); }, function(){ alert('code mootools documentation until eyes close involuntarily'); }, function(){ alert('sleep'); } );
Adds functions to the end of the call stack of the Chain instance.
myClass.chain(fn[, fn2[, fn3[, ...]]]);
//Fx.Tween has already implemented the Chain class because of inheritance of the Fx class. var myFx = new Fx.Tween('myElement', {property: 'opacity'}); myFx.start(1,0).chain( //Notice that "this" refers to the calling object (in this case, the myFx object). function(){ this.start(0,1); }, function(){ this.start(1,0); }, function(){ this.start(0,1); } ); //Will fade the Element out and in twice.
Removes the first function of the Chain instance stack and executes it. The next function will then become first in the array.
myClass.callChain([any arguments]);
var myChain = new Chain(); myChain.chain( function(){ alert('do dishes'); }, function(){ alert('put away clean dishes'); } ); myChain.callChain(); // alerts 'do dishes'. myChain.callChain(); // alerts 'put away clean dishes'.
Clears the stack of a Chain instance.
myClass.clearChain();
var myFx = Fx.Tween('myElement', 'color'); // Fx.Tween inherited Fx's implementation of Chain. myFx.chain(function(){ while(true) alert("D'oh!"); }); // chains an infinite loop of alerts. myFx.clearChain(); // cancels the infinite loop of alerts before allowing it to begin.
A Utility Class. Its methods can be implemented with Class:implement into any Class. In Fx, for example, this Class is used to allow any number of functions to be added to the Fx events, like 'complete', 'start', and 'cancel'. Events in a Class that implements Events must be either added as an option or with addEvent, not directly through .options.onEventName.
var MyClass = new Class({ Implements: Events });
MyClass.implement(Events);
var Widget = new Class({ Implements: Events, initialize: function(element){ // ... }, complete: function(){ this.fireEvent('complete'); } }); var myWidget = new Widget(); myWidget.addEvent('complete', myFunction);
Adds an event to the Class instance's event stack.
myClass.addEvent(type, fn[, internal]);
var myFx = new Fx.Tween('element', 'opacity'); myFx.addEvent('start', myStartFunction);
The same as addEvent, but accepts an object to add multiple events at once.
myClass.addEvents(events);
var myFx = new Fx.Tween('element', 'opacity'); myFx.addEvents({ start: myStartFunction, complete: function() { alert('Done.'); } });
Fires all events of the specified type in the Class instance.
myClass.fireEvent(type[, args[, delay]]);
var Widget = new Class({ Implements: Events, initialize: function(arg1, arg2){ //... this.fireEvent('initialize', [arg1, arg2], 50); } });
Removes an event from the stack of events of the Class instance.
myClass.removeEvent(type, fn);
Removes all events of the given type from the stack of events of a Class instance. If no type is specified, removes all events of all types.
myClass.removeEvents([events]);
var myFx = new Fx.Tween('myElement', 'opacity'); myFx.removeEvents('complete');
A Utility Class. Its methods can be implemented with Class:implement into any Class. Used to automate the setting of a Class instance's options. Will also add Class Events when the option property begins with 'on' and is followed by a capital letter (e.g. 'onComplete' adds a 'complete' event). You will need to call this.setOptions() for this to have an effect, however.
var MyClass = new Class({Implements: Options});
MyClass.implement(Options);
Merges the default options of the Class with the options passed in. Every value passed in to this method will be deep copied. Therefore other class instances or objects that are not intended for copying must be passed to a class in other ways.
myClass.setOptions([options]);
var Widget = new Class({ Implements: Options, options: { color: '#fff', size: { width: 100, height: 100 } }, initialize: function(options){ this.setOptions(options); } }); var myWidget = new Widget({ color: '#f00', size: { width: 200 } }); //myWidget.options is now: {color: #f00, size: {width: 200, height: 100}} // Deep copy example var mySize = { width: 50, height: 50 }; var myWidget = new Widget({ size: mySize }); (mySize == myWidget.options.size) // false! mySize was copied in the setOptions call.
If a Class has Events as well as Options implemented, every option beginning with 'on' and followed by a capital letter (e.g. 'onComplete') becomes a Class instance event, assuming the value of the option is a function.
var Widget = new Class({ Implements: [Options, Events], options: { color: '#fff', size: { width: 100, height: 100 } }, initialize: function(options){ this.setOptions(options); }, show: function(){ // Do some cool stuff this.fireEvent('show'); } }); var myWidget = new Widget({ color: '#f00', size: { width: 200 }, onShow: function(){ alert('Lets show it!'); } }); myWidget.show(); // fires the event and alerts 'Lets show it!'
© Linux.ria.ua, 2008-2024 |