forked from component/delegate
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
44 lines (38 loc) · 900 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module.exports = on;
module.exports.on = on;
module.exports.off = off;
/**
* Module dependencies.
*/
var matches = require('matches-dom-selector')
, on = require('dom-event');
/**
* Delegate event `type` to `selector`
* and invoke `fn(e)`. A callback function
* is returned which may be passed to `.unbind()`.
*
* @param {Element} el
* @param {String} selector
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @return {Function}
* @api public
*/
function on(el, selector, type, fn, capture){
return on(el, type, function(e){
if (matches(e.target || e.srcElement, selector)) fn.call(el, e);
}, capture);
};
/**
* Unbind event `type`'s callback `fn`.
*
* @param {Element} el
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @api public
*/
function off(el, type, fn, capture){
on.off(el, type, fn, capture);
};