-
-
Save ibolmo/817709 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
// Element Listener Mixin | |
(function(){ | |
// Prototype.. doesn't actually work.. | |
this.Listener = new Class(function(){ | |
var listener = new Events, removeEvent = listener.removeEvent; | |
listener.removeEvent = function(key, value){ | |
removeEvent(key, value); | |
element.removeEvent(key, value); | |
}; | |
return { | |
attach: function(key, value){ | |
listener.addEvent(key, value); | |
this.toElement().addEvent(key, value); | |
}.overloadSetter(), | |
detach: function(key, value){ | |
if (typeof key == 'string') listener.removeEvent(key, value); | |
else listener.removeEvents(key); | |
return this; | |
}, | |
toElement: function(){ | |
return this.element; | |
} | |
}; | |
}); | |
}).call(this); | |
// Implementation | |
var MyClass = new Class({ | |
Implements: [Listener, Class.Binds], | |
initialize: function(){ | |
this.element = new Element('div'); | |
this.attach({ | |
click: this.bound('onClick'), | |
'keyup:relay(:input)': this.bound('onKeyUp') | |
}); | |
} | |
}); | |
// Use | |
var myInstance = new MyClass(); | |
myInstance.detach(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment