Last active
August 29, 2015 14:12
-
-
Save zxqx/b2871659ab54c351b68d to your computer and use it in GitHub Desktop.
This file contains 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
module.exports = Eventable; | |
/** | |
* Provide a mixin-able interface for registering DOM events | |
*/ | |
function Eventable() | |
{ | |
} | |
/** | |
* Register a DOM event on an element and set up callback | |
*/ | |
Eventable.prototype.registerEvent = function(event, callback) | |
{ | |
var eventOnElement = event.split(/ (.+)?/); | |
var eventType = 'on' + eventOnElement[0]; | |
var el = eventOnElement[1]; | |
var _this = this; | |
this.el.querySelector(el)[eventType] = function(e) { | |
callback.call(_this, e); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment