-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
41 lines (36 loc) · 908 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
var bind, unbind, prefix;
function detect () {
bind = window.addEventListener ? 'addEventListener' : 'attachEvent';
unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent';
prefix = bind !== 'addEventListener' ? 'on' : '';
}
/**
* Bind `el` event `type` to `fn`.
*
* @param {Element} el
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @return {Function}
* @api public
*/
exports.bind = function(el, type, fn, capture){
if (!bind) detect();
el[bind](prefix + type, fn, capture || false);
return fn;
};
/**
* Unbind `el` event `type`'s callback `fn`.
*
* @param {Element} el
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @return {Function}
* @api public
*/
exports.unbind = function(el, type, fn, capture){
if (!unbind) detect();
el[unbind](prefix + type, fn, capture || false);
return fn;
};