Skip to content

Instantly share code, notes, and snippets.

@mgimenez
Created April 24, 2014 19:11
Show Gist options
  • Save mgimenez/11265993 to your computer and use it in GitHub Desktop.
Save mgimenez/11265993 to your computer and use it in GitHub Desktop.
(function (win, doc) {
'use strict';
var bind = win.addEventListener ? 'addEventListener' : 'attachEvent',
unbind = win.removeEventListener ? 'removeEventListener' : 'detachEvent',
prefix = (bind !== 'addEventListener') ? 'on' : '',
cho = win.cho || {};
/**
* Created by https://github.com/component/event/blob/master/index.js
* @param {Element} el
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @return {Function}
* @see https://github.com/component/event/blob/master/index.js
*/
cho.bind = function (el, type, fn, capture) {
el[bind](prefix + type, fn, capture || false);
return fn;
};
/**
* Created by https://github.com/component/event/blob/master/index.js
* @param {Element} el
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @return {Function}
* @api public
*/
cho.unbind = function (el, type, fn, capture) {
el[unbind](prefix + type, fn, capture || false);
return fn;
};
}(this, this.document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment