Repository navigation
Expand file tree
/
Copy pathevents.js
More file actions
62 lines (53 loc) · 1.29 KB
/
Copy pathevents.js
File metadata and controls
62 lines (53 loc) · 1.29 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Module Dependencies
*/
<
6555
div id="LC4" class="react-file-line html-div" data-testid="code-cell" data-line-number="4" style="position:relative">
var events = require('event');
var delegate = require('delegate');
/**
* Bind to `event` and invoke `fn(e)`. When
* a `selector` is given then events are delegated.
*
* @param {String} event
* @param {String} [selector]
* @param {Function} fn
* @param {Boolean} capture
* @return {List}
* @api public
*/
exports.on = function(event, selector, fn, capture){
if ('string' == typeof selector) {
return this.forEach(function (el) {
fn._delegate = delegate.bind(el, selector, event, fn, capture);
});
}
capture = fn;
fn = selector;
return this.forEach(function (el) {
events.bind(el, event, fn, capture);
});
};
/**
* Unbind to `event` and invoke `fn(e)`. When
* a `selector` is given then delegated event
* handlers are unbound.
*
* @param {String} event
* @param {String} [selector]
* @param {Function} fn
* @param {Boolean} capture
* @return {List}
* @api public
*/
exports.off = function(event, selector, fn, capture){
if ('string' == typeof selector) {
return this.forEach(function (el) {
// TODO: add selector support back
delegate.unbind(el, event, fn._delegate, capture);
});
}
capture = fn;
fn = selector;
return this.forEach(function (el) {
events.unbind(el, event, fn, capture);
});
};