´óÏó´«Ã½

Please turn on JavaScript. To find out how to do this visit the .

Native browser and custom events

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.

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 a listener created with addListener

Synopsis

glow.events.removeListener(ident);

Parameters

ident
Type

An identifier returned from glow.events.addListener.

Returns

Example

var listener = glow.events.addListener(...);
glow.events.removeListener(listener);

Classes

Event

Object passed into all events

Documentation generated by 2.1.0 on Mon Jul 20 2009 14:55:30 GMT+0100 (BST)

´óÏó´«Ã½ iD

´óÏó´«Ã½ navigation

´óÏó´«Ã½ © 2014 The ´óÏó´«Ã½ is not responsible for the content of external sites. Read more.

This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.