Class. Extras.js

Contains common implementations for custom classes.  In Mootools is implemented in Ajax, XHR and Fx.Base and many more.

License

MIT-style license.

Summary
Class. Extras.jsContains common implementations for custom classes.
ChainAn “Utility” Class.
Properties
chainadds a function to the Chain instance stack.
callChainExecutes the first function of the Chain instance stack, then removes it.
clearChainClears the stack of a Chain instance.
EventsAn “Utility” Class.
Properties
addEventadds an event to the stack of events of the Class instance.
fireEventfires all events of the specified type in the Class instance.
removeEventremoves an event from the stack of events of the Class instance.
OptionsAn “Utility” Class.
Properties
setOptionssets this.options

Chain

An “Utility” Class.  Its methods can be implemented with Class.implement into any Class.  Currently implemented in Fx.Base, XHR and Ajax.  In Fx.Base for example, is used to execute a list of function, one after another, once the effect is completed.  The functions will not be fired all togheter, but one every completion, to create custom complex animations.

Example

var myFx = new Fx.Style('element', 'opacity');
 
myFx.start(1,0).chain(function(){
    myFx.start(0,1);
}).chain(function(){
    myFx.start(1,0);
}).chain(function(){
    myFx.start(0,1);
});
//the element will appear and disappear three times
Summary
Properties
chainadds a function to the Chain instance stack.
callChainExecutes the first function of the Chain instance stack, then removes it.
clearChainClears the stack of a Chain instance.

Properties

chain

adds a function to the Chain instance stack.

Arguments

fnthe function to append.

callChain

Executes the first function of the Chain instance stack, then removes it.  The first function will then become the second.

clearChain

Clears the stack of a Chain instance.

Events

An “Utility” Class.  Its methods can be implemented with Class.implement into any Class.  In Fx.Base Class, for example, is used to give the possibility add any number of functions to the Effects events, like onComplete, onStart, onCancel.  Events in a Class that implements Events can be either added as an option, or with addEvent.  Never with .options.onEventName.

Example

var myFx = new Fx.Style('element', 'opacity').addEvent('onComplete', function(){
    alert('the effect is completed');
}).addEvent('onComplete', function(){
    alert('I told you the effect is completed');
});
 
myFx.start(0,1);
//upon completion it will display the 2 alerts, in order.

Implementing

This class can be implemented into other classes to add the functionality to them.  Goes well with the Options class.

Example

var Widget = new Class({
    initialize: function(){},
    finish: function(){
        this.fireEvent('onComplete');
    }
});
Widget.implement(new Events);
//later...
var myWidget = new Widget();
myWidget.addEvent('onComplete', myfunction);
Summary
Properties
addEventadds an event to the stack of events of the Class instance.
fireEventfires all events of the specified type in the Class instance.
removeEventremoves an event from the stack of events of the Class instance.

Properties

addEvent

adds an event to the stack of events of the Class instance.

Arguments

typestring; the event name (e.g.  ‘onComplete’)
fnfunction to execute

fireEvent

fires all events of the specified type in the Class instance.

Arguments

typestring; the event name (e.g.  ‘onComplete’)
argsarray or single object; arguments to pass to the function; if more than one argument, must be an array
delay(integer) delay (in ms) to wait to execute the event

Example

var Widget = new Class({
    initialize: function(arg1, arg2){
        ...
        this.fireEvent("onInitialize", [arg1, arg2], 50);
    }
});
Widget.implement(new Events);

removeEvent

removes an event from the stack of events of the Class instance.

Arguments

typestring; the event name (e.g.  ‘onComplete’)
fnfunction that was added

Options

An “Utility” Class.  Its methods can be implemented with Class.implement into any Class.  Used to automate the options settings, also adding Class Events when the option begins with on.

Example

var Widget = new Class({
    options: {
        color: '#fff',
        size: {
            width: 100
            height: 100
        }
    },
    initialize: function(options){
        this.setOptions(options);
    }
});
Widget.implement(new Options);
//later...
var myWidget = new Widget({
    color: '#f00',
    size: {
        width: 200
    }
});
//myWidget.options = {color: #f00, size: {width: 200, height: 100}}
Summary
Properties
setOptionssets this.options

Properties

setOptions

sets this.options

Arguments

defaultsobject; the default set of options
optionsobject; the user entered options. can be empty too.

Note

if your Class has Events implemented, every option beginning with on, followed by a capital letter (onComplete) becomes an Class instance event.

An Ajax class, For all your asynchronous needs.
Basic XMLHttpRequest Wrapper.
Base class for the Effects.
Implements the passed in properties to the base Class prototypes, altering the base class, unlike Class.extend.
The base class object of the http://mootools.net framework.
An “Utility” Class.
An “Utility” Class.

Documentation by Aaron Newton & Mootools Developers, generated by NaturalDocs and GeSHi