Skip to content

Instantly share code, notes, and snippets.

@zxqx
Last active August 29, 2015 14:12
Show Gist options
  • Save zxqx/b2871659ab54c351b68d to your computer and use it in GitHub Desktop.
Save zxqx/b2871659ab54c351b68d to your computer and use it in GitHub Desktop.
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