Skip to content

Instantly share code, notes, and snippets.

@jakearchibald
Created November 16, 2009 14:59
Show Gist options
  • Save jakearchibald/236031 to your computer and use it in GitHub Desktop.
Save jakearchibald/236031 to your computer and use it in GitHub Desktop.
// adding a show listener to an overlay:
myOverlay.on('show', function(event) {
// ...
});
// adding and removing a show listener to an overlay
function showListener() {
// ...
}
// adding
myOverlay.on('show', showListener);
// removing
myOverlay.removeListener('show', showListener);
// downside: you need a named reference to your callback to be able to remove it as a listener
// making your class support custom events...
// Ball is our constructor
function Ball() {
// ...
}
// make Ball inherit from Target
glow.lang.extend(Ball, glow.events.Target);
// making Ball fire an event
Ball.prototype._directionChange = function() {
this.fire('bounce', {
previousDirection: 45,
newDirection: 135
});
}
// how the user would add an event to a ball
var ball = new Ball()
ball.on('bounce', function(event) {
alert(event.newDirection);
// ...
});
// how the user would add custom events to a singleton
var mySingleton = {};
glow.events.Target.extend(mySingleton);
// mySingleton now has 'on', 'fire' and 'removeListener' methods
mySingleton.fire('whatever');
// what about DOM events?
glow.dom.get('a').on('click', function(domEvent) {
// domEvent is an instance of glow.dom.DomEvent (extends glow.events.Event)
// this is yet to be documented
// All dom handling code for events will be in glow.dom
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment