Yahoo! UI Library

event  3.0.0pr2

Yahoo! UI Library > event > Event.Custom
Search:
 
Filters

Class Event.Custom

The Event.Custom class lets you define events for your application that can be subscribed to by one or more independent component.

Constructor

Event.Custom ( type , o )
Parameters:
type <String> The type of event, which is passed to the callback when the event fires
o <object> configuration object

Properties

afters - Event.Subscriber{}

'After' subscribers

broadcast - int

If 0, this event does not broadcast. If 1, the YUI instance is notified every time this event fires. If 2, the YUI instance and the YUI global (if event is enabled on the global) are notified every time this event fires.

bubbles - boolean

Specifies whether or not a subscriber can stop the event propagation via stopPropagation(), stopImmediatePropagation(), or halt()
Default Value: true

context - object

The context the the event will fire from by default. Defaults to the YUI instance.

defaultFn - Function

The default function to execute after event listeners have fire, but only if the default action was not prevented.

emitFacade - boolean

If set to true, the custom event will deliver an Event.Facade object that is similar to a DOM event object.
Default Value: false

fired - boolean

This event has fired if true
Default Value: false;

fireOnce - boolean

This event should only fire one time if true, and if it has fired, any new subscribers should be notified immediately.
Default Value: false;

host - Event.Target

Specifies the host for this custom event. This is used to enable event bubbling

preventable - boolean

Specifies whether or not this event's default function can be cancelled by a subscriber by executing preventDefault() on the event facade
Default Value: true

prevented - int

Flag for preventDefault that is modified during fire(). if it is not 0, the default behavior for this event

preventedFn - Function

The function to execute if a subscriber calls preventDefault

signature - int

Supports multiple options for listener signatures in order to port YUI 2 apps.
Default Value: 9

silent - boolean

By default all custom events are logged in the debug build, set silent to true to disable debug outpu for this event.

stopped - int

Flag for stopPropagation that is modified during fire() 1 means to stop propagation to bubble targets. 2 means to also stop additional subscribers on this target.

stoppedFn - Function

The function to execute if a subscriber calls stopPropagation or stopImmediatePropagation

subscribers - Event.Subscriber{}

The subscribers to this event

type - string

The type of event, returned to subscribers when the event fires

Methods

_delete

private void _delete ( subscriber )
Parameters:
subscriber <object> object
Returns: void

_notify

private void _notify ( s , args )
Notify a single subscriber
Parameters:
s <Event.Subscriber> the subscriber
args <Array> the arguments array to apply to the listener
Returns: void

after

Event.Handle after ( fn , obj , args* )
Listen for this event after the normal subscribers have been notified and the default behavior has been applied. If a normal subscriber prevents the default behavior, it also prevents after listeners from firing.
Parameters:
fn <Function> The function to execute
obj <Object> An object to be passed along when the event fires
args* <object> 1..n params to provide to the listener
Returns: Event.Handle
unsubscribe handle

applyConfig

void applyConfig ( o , force )
Apply configuration properties. Only applies the CONFIG whitelist
Parameters:
o <object> hash of properties to apply
force <boolean> if true, properties that exist on the event will be overwritten.
Returns: void

fire

boolean fire ( arguments )
Notifies the subscribers. The callback functions will be executed from the context specified when the event was created, and with the following parameters:
  • The type of event
  • All of the arguments fire() was executed with as an array
  • The custom object (if any) that was passed into the subscribe() method
Parameters:
arguments <Object*> an arbitrary set of parameters to pass to the handler.
Returns: boolean
false if one of the subscribers returned false, true otherwise

log

void log ( msg , cat )
Logger abstraction to centralize the application of the silent flag
Parameters:
msg <string> message to log
cat <string> log category
Returns: void

preventDefault

void preventDefault ( )
Prevents the execution of this event's defaultFn
Returns: void

stopImmediatePropagation

void stopImmediatePropagation ( )
Stops propagation to bubble targets, and prevents any remaining subscribers on the current target from executing.
Returns: void

stopPropagation

void stopPropagation ( )
Stop propagation to bubble targets
Returns: void

subscribe

Event.Handle subscribe ( fn , obj , args* )
Listen for this event
Parameters:
fn <Function> The function to execute
obj <Object> An object to be passed along when the event fires
args* <object> 1..n params to provide to the listener
Returns: Event.Handle
unsubscribe handle

toString

void toString ( )
Returns: void

unsubscribe

boolean unsubscribe ( fn , obj )
Unsubscribes subscribers.
Parameters:
fn <Function> The subscribed function to remove, if not supplied all will be removed
obj <Object> The custom object passed to subscribe. This is optional, but if supplied will be used to disambiguate multiple listeners that are the same (e.g., you subscribe many object using a function that lives on the prototype)
Returns: boolean
True if the subscriber was found and detached.

unsubscribeAll

int unsubscribeAll ( )
Removes all listeners
Returns: int
The number of listeners unsubscribed

Events

subscribeEvent

subscribeEvent ( fn , obj , override )
Custom events provide a custom event that fires whenever there is a new subscriber to the event. This provides an opportunity to handle the case where there is a non-repeating event that has already fired has a new subscriber.
Parameters:
fn <Function> The function to execute
obj <Object> An object to be passed along when the event fires
override <boolean|Object> If true, the obj passed in becomes the execution context of the listener. if an object, that object becomes the the execution context.


Copyright © 2008 Yahoo! Inc. All rights reserved.