Skip to content
Create a gist now

Instantly share code, notes, and snippets.

// Element Listener Mixin
var setup = function(element){
var listener = new Events, removeEvent = listener.removeEvent;
listener.removeEvent = function(key, value){
removeEvent(key, value);
element.removeEvent(key, value);
return listener;
this.Listener = new Class({
attach: function(key, value){
if (!this.$listener) this.$listener = setup(this.toElement());
this.$listener.addEvent(key, value);
this.toElement().addEvent(key, value);
detach: function(key, value){
if (this.$listener){
if (typeof key == 'string') this.$listener.removeEvent(key, value);
else this.$listener.removeEvents(key);
return this;
toElement: function(){
return this.element;
// Implementation
var MyClass = new Class({
Implements: [Listener, Class.Binds],
initialize: function(){
this.element = new Element('div');
click: this.bound('onClick'),
'keyup:relay(:input)': this.bound('onKeyUp')
// Use
var myInstance = new MyClass();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.