Created
October 25, 2011 16:45
-
-
Save arian/1313400 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // returns the ClickEmitter object (and creates a new ClickEmitter) | |
| // should return an error when the event type does not have a matched | |
| // emitter class (defined by defineEmitter) | |
| var emitter = myElement.on('click'); | |
| // Emitter methods: create, add, remove | |
| // returns a Listener object | |
| var listener = emitter.create(function(event){ | |
| event instanceof ClickEvent // true | |
| }); | |
| // creates a listener and attaches it | |
| emitter.add(function(event){ | |
| }); | |
| // remove. won't be used as public API, but listener.detach() will be | |
| // used usually | |
| emitter.remove(functionReference); | |
| // listener methods | |
| // listener is a instanceof Listener. A Emitter can choose to return a | |
| // ScrollListener which has some extra stuff | |
| listener.attach(); | |
| listener.detach(); | |
| listener.once(); | |
| listener.throttle(); | |
| // a Accessor for Emitters, where all event types are defined. | |
| // Emitter classes can decide how to bind the listeners to the actual | |
| // object | |
| var Emitter = new Class({ | |
| initialize: function(Object object); | |
| add: function(Function fn); | |
| remove: function(Function fn); | |
| trigger: function(Event event); | |
| }); | |
| Node.defineEmitter('click', new Class({ | |
| Extends: DOMEmitter, | |
| name: 'click' | |
| })); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment