component-event
Advanced tools
Comparing version 0.1.4 to 0.2.0
@@ -5,3 +5,3 @@ { | ||
"description": "Event binding component", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "browser", |
@@ -0,2 +1,6 @@ | ||
0.2.0 / 2016-09-22 | ||
================== | ||
* [[`f1c2c3d2b1`](https://github.com/component/component-event/commit/f1c2c3d2b1)] - make requireable without `window` (Nathan Rajlich) | ||
0.1.4 / 2014-05-27 | ||
@@ -3,0 +7,0 @@ ================== |
14
index.js
@@ -1,5 +0,9 @@ | ||
var bind = window.addEventListener ? 'addEventListener' : 'attachEvent', | ||
unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent', | ||
prefix = bind !== 'addEventListener' ? 'on' : ''; | ||
var bind, unbind, prefix; | ||
function detect () { | ||
bind = window.addEventListener ? 'addEventListener' : 'attachEvent'; | ||
unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent'; | ||
prefix = bind !== 'addEventListener' ? 'on' : ''; | ||
} | ||
/** | ||
@@ -17,2 +21,3 @@ * Bind `el` event `type` to `fn`. | ||
exports.bind = function(el, type, fn, capture){ | ||
if (!bind) detect(); | ||
el[bind](prefix + type, fn, capture || false); | ||
@@ -34,4 +39,5 @@ return fn; | ||
exports.unbind = function(el, type, fn, capture){ | ||
if (!unbind) detect(); | ||
el[unbind](prefix + type, fn, capture || false); | ||
return fn; | ||
}; | ||
}; |
{ | ||
"name": "component-event", | ||
"description": "Event binding component", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "browser", |
3600
50