Print Friendly

Class YAHOO.util.EventProvider

Package:YAHOO.util
Class:EventProvider
Extends:Object
Defined In:event.js
EventProvider is designed to be used with YAHOO.augment to wrap CustomEvents in an interface that allows events to be subscribed to and fired by name. This makes it possible for implementing code to subscribe to an event that either has not been created yet, or will not be created at all.

Public Properties

This class has no public properties.

Public Methods

Method Defined By
  createEvent(p_type {string}, p_config {object}) : CustomEvent EventProvider
Creates a new custom event of the specified type. If a custom event by that name already exists, it will not be re-c...
  fireEvent(p_type {string}, arguments {Object*}) : boolean EventProvider
Fire a custom event by name. The callback functions will be executed from the scope specified when the event was cre...
  hasEvent(type {string}) : void EventProvider
Returns true if the custom event of the provided type has been created with createEvent.
  subscribe(p_type {string}, p_fn {function}, p_obj , p_obj {Object}, p_override {boolean}) : void EventProvider
Subscribe to a CustomEvent by event type
  unsubscribe(p_type {string}, p_fn {Function}, [p_obj {Object}]) : boolean EventProvider
Unsubscribes the from the specified event

Public Events

This class has no public events.

Method Details

createEvent

public function createEvent(p_type {string}, p_config {object})
Creates a new custom event of the specified type. If a custom event by that name already exists, it will not be re-created. In either case the custom event is returned.
Parameters:
  • {string} : p_type
    the type, or name of the event
  • {object} : p_config
    optional config params. Valid properties are:
    • scope: defines the default execution scope. If not defined the default scope will be this instance.
    • silent: if true, the custom event will not generate log messages. This is false by default.
    • onSubscribeCallback: specifies a callback to execute when the event has a new subscriber. This will fire immediately for each queued subscriber if any exist prior to the creation of the event.
Returns:
  • CustomEvent
    the custom event
This method is defined by EventProvider.

fireEvent

public function fireEvent(p_type {string}, arguments {Object*})
Fire a custom event by name. The callback functions will be executed from the scope specified when the event was created, and with the following parameters:
  • The first argument fire() was executed with
  • The custom object (if any) that was passed into the subscribe() method
Parameters:
  • {string} : p_type
    the type, or name of the event
  • {Object*} : arguments
    an arbitrary set of parameters to pass to the handler.
Returns:
  • boolean
    the return value from CustomEvent.fire, or null if the custom event does not exist.
This method is defined by EventProvider.

hasEvent

public function hasEvent(type {string})
Returns true if the custom event of the provided type has been created with createEvent.
Parameters:
  • {string} : type
    the type, or name of the event
Returns:
  • void
This method is defined by EventProvider.

subscribe

public function subscribe(p_type {string}, p_fn {function}, p_obj , p_obj {Object}, p_override {boolean})
Subscribe to a CustomEvent by event type
Parameters:
  • {string} : p_type
    the type, or name of the event
  • {function} : p_fn
    the function to exectute when the event fires
  • : p_obj
  • {Object} : p_obj
    An object to be passed along when the event fires
  • {boolean} : p_override
    If true, the obj passed in becomes the execution scope of the listener
Returns:
  • void
This method is defined by EventProvider.

unsubscribe

public function unsubscribe(p_type {string}, p_fn {Function}, [p_obj {Object}])
Unsubscribes the from the specified event
Parameters:
  • {string} : p_type
    The type, or name of the event
  • {Function} : p_fn
    The function to execute
  • {Object} : p_obj
    The custom object passed to subscribe (optional)
Returns:
  • boolean
    true if the subscriber was found and detached.
This method is defined by EventProvider.

yui-ext - Copyright © 2006 Jack Slocum. | Yahoo! UI - Copyright © 2006 Yahoo! Inc.
All rights reserved.