Version 1.7 glow.events
API Quick Reference
JavaScript is required to use the quick reference
Native browser and custom events
Further Info & Examples
Methods
- addListener
-
Adds an event listener to an object (e.g. a DOM Element or Glow widget).
Synopsis
glow.events.addListener(attachTo, name, callback, context);
Parameters
- attachTo
-
- Type
- | NodeList |
The object to attach the event listener to.
If the parameter is a string, then it is treated as a CSS selector and the listener is attached to all matching elements.
If the parameter is a glow.dom.NodeList, then the listener is attached to all elements in the NodeList.
- name
-
- Type
The event name.
Listeners for DOM events should not begin with 'on' (i.e. 'click' rather than 'onclick')
- callback
-
- Type
The function to be called when the event fires.
- context
-
- Type
- Optional
- Yes
The execution scope of the callback.
If this parameter is not passed then the attachTo object will be the scope of the callback.
Returns
| Undefined
A unique identifier for the event suitable for passing to glow.events.removeListener. If an empty NodeList or CSS selector that returns no elements is passed, then undefined is returned.
Description
Some non-standard dom events are available:
- mouseenter
- Fires when the mouse enters this element specifically, does not bubble
- mouseleave
- Fires when the mouse leaves this element specifically, does not bubble
Example
glow.events.addListener('#nav', 'click', function () { alert('nav clicked'); }); glow.events.addListener(myLightBox, 'close', this.showSurvey, this);
- fire
-
Fires an event on an object.
Synopsis
glow.events.fire(attachedTo, name, event);
Parameters
- attachedTo
-
- Type
The object that the event is associated with.
- name
-
- Type
The name of the event.
Event names should not start with the word 'on'.
- event
-
- Type
- | glow.events.Event
- Optional
- Yes
An event object or properties to add to a default event object
If not specified, a generic event object is created. If you provide a simple object, a default Event will be created with the properties from the provided object.
Returns
The event object.
Example
// firing a custom event Ball.prototype.move = function () { // move the ball... // check its position if (this._height == 0) { var event = glow.events.fire(this, 'bounce', { bounceCount: this._bounceCount }); // handle what to do if a listener returned false if ( event.defaultPrevented() ) { this.stopMoving(); } } };
// listening to a custom event var myBall = new Ball(); glow.events.addListener(myBall, "bounce", function(event) { if (event.bounceCount == 3) { // stop bouncing after 3 bounces return false; } });
- removeAllListeners
-
Removes all listeners attached to a given object
Synopsis
glow.events.removeAllListeners(detachFrom);
Parameters
- detachFrom
-
- Type
- | glow.dom.NodeList | |
The object(s) to remove listeners from.
If the parameter is a string, then it is treated as a CSS selector, listeners are removed from all nodes.
Returns
glow.events
Example
glow.events.removeAllListeners("#myDiv");
- removeListener
-
Removes listener(s) created with addListener
Synopsis
glow.events.removeListener(ident);
Parameters
- ident
-
- Type
- |
An identifier or array of identifiers. Idenftifiers are returned from glow.events.addListener.
If array of identifiers is provided, each listener specified will be removed.
Returns
Example
var listener = glow.events.addListener(...); glow.events.removeListener(listener);
Classes
- Event
-
Object passed into all events