democracyos-javve-events
Version:
Event binding component with support for single elements as well as NodeLists, HTMLCollections and Arrays
37 lines (32 loc) • 792 B
JavaScript
var events = require('event'),
toArray = require('to-array');
/**
* Bind `el` event `type` to `fn`.
*
* @param {Element} el, NodeList, HTMLCollection or Array
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @api public
*/
exports.bind = function(el, type, fn, capture){
el = toArray(el);
for ( var i = 0; i < el.length; i++ ) {
events.bind(el[i], type, fn, capture);
}
};
/**
* Unbind `el` event `type`'s callback `fn`.
*
* @param {Element} el, NodeList, HTMLCollection or Array
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @api public
*/
exports.unbind = function(el, type, fn, capture){
el = toArray(el);
for ( var i = 0; i < el.length; i++ ) {
events.unbind(el[i], type, fn, capture);
}
};