CKFinder.Event
Mixed into
Creates an event class instance.
This is a base class for classes and objects that require event handling features.
The Event
class implements the internal event system used by CKFinder to fire API-related events.
Methods
Fires a specific event in the object. All registered listeners are called at this point.
someObject.on( 'someEvent', function() { ... } );
someObject.on( 'someEvent', function() { ... } );
someObject.fire( 'someEvent' ); // Both listeners are called.
someObject.on( 'someEvent', function( event ) {
alert( event.data ); // 'Example'
} );
someObject.fire( 'someEvent', 'Example' );
Parameters
- eventName : String
The name of the event to fire.
- data : Object (optional)
The data to be sent as the CKFinder.Event.EventInfo.data when calling the listeners.
- finder : CKFinder.Application (optional)
The finder instance to send as the CKFinder.Event.EventInfo.finder when calling the listener.
Returns
- Boolean|Object
A Boolean value indicating that the event is to be canceled, or the data returned by one of the listeners.
Fires a specific event in the object, releasing all listeners registered to that event. The same listeners are not called again on successive calls of it or of fire.
someObject.on( 'someEvent', function() { ... } );
someObject.fire( 'someEvent' ); // Above listener called.
someObject.fireOnce( 'someEvent' ); // Above listener called.
someObject.fire( 'someEvent' ); // No listeners called.
Parameters
- eventName : String
The event name to fire.
- data : Object (optional)
Data to be sent as CKFinder.Event.EventInfo.data when calling the listeners.
- finder : CKFinder.Application (optional)
The finder instance to send as CKFinder.Event.EventInfo.finder when calling the listener.
Returns
- Boolean/Object
A Boolean value indicating that the event is to be canceled, or the data returned by one of the listeners.
Checks if there is any listener registered to a given event.
var myListener = function() { ... };
someObject.on( 'someEvent', myListener );
alert( someObject.hasListeners( 'someEvent' ) ); // true
alert( someObject.hasListeners( 'noEvent' ) ); // false
Parameters
- eventName : String
The event name.
Returns
- Boolean
Registers a listener to a specific event in the current object.
someObject.on( 'someEvent', function() {
alert( this == someObject ); // true
} );
someObject.on( 'someEvent', function() {
alert( this == anotherObject ); // true
}, anotherObject );
someObject.on( 'someEvent', function( event ) {
alert( event.listenerData ); // 'Example'
}, null, 'Example' );
someObject.on( 'someEvent', function() { ... } ); // 2nd called
someObject.on( 'someEvent', function() { ... }, null, null, 100 ); // 3rd called
someObject.on( 'someEvent', function() { ... }, null, null, 1 ); // 1st called
Parameters
- eventName : String
The event name to which to listen.
- listenerFunction : Function
The function listening to the event. A single CKFinder.EventInfo object instanced is passed to this function containing all the event data.
- scopeObj : Object (optional)
The object used to scope the listener call (the
this
object). If omitted, the current object is used. - listenerData : Object (optional)
Data to be sent as the listener.
- priority : Number (optional)
The listener priority. Lower priority listeners are called first. Listeners with the same priority value are called in registration order.
Defaults to:
10
Returns
- Object
An object containing the
removeListener
function which can be used to remove the listener at any time.
Removes all existing listeners on this object for cleanup purposes.
Unregisters a listener function from being called at the specified event. No errors are thrown if the listener has not been registered previously.
var myListener = function() { ... };
someObject.on( 'someEvent', myListener );
someObject.fire( 'someEvent' ); // myListener called.
someObject.removeListener( 'someEvent', myListener );
someObject.fire( 'someEvent' ); // myListener not called.
Parameters
- eventName : String
The event name.
- listenerFunction : Function
The listener function to unregister.