-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
minwe
committed
Apr 14, 2016
1 parent
49f51fd
commit 082c00f
Showing
4 changed files
with
66 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,68 @@ | ||
'use strict'; | ||
|
||
const bind = 'addEventListener'; | ||
const unbind = 'removeEventListener'; | ||
import canUseDOM from './canUseDOM'; | ||
|
||
const noop = function() {}; | ||
let Events = { | ||
one: function(node, eventNames, eventListener) { | ||
var typeArray = eventNames.split(' '); | ||
var recursiveFunction = function(e) { | ||
e.target.removeEventListener(e.type, recursiveFunction); | ||
return eventListener(e); | ||
}; | ||
|
||
for (var i = typeArray.length - 1; i >= 0; i--) { | ||
this.on(node, typeArray[i], recursiveFunction); | ||
} | ||
}, | ||
|
||
|
||
/** | ||
* Bind `node` event `eventName` to `eventListener`. | ||
* | ||
* @param {Element} node | ||
* @param {String} eventName | ||
* @param {Function} eventListener | ||
* @param {Boolean} capture | ||
* @return {Obejct} | ||
* @api public | ||
*/ | ||
|
||
on: function(node, eventName, eventListener, capture) { | ||
node[bind](eventName, eventListener, capture || false); | ||
|
||
return { | ||
off: function() { | ||
node[unbind](eventName, eventListener, capture || false); | ||
} | ||
}; | ||
}, | ||
|
||
|
||
/** | ||
* Unbind `node` event `eventName`'s callback `eventListener`. | ||
* | ||
* @param {Element} node | ||
* @param {String} eventName | ||
* @param {Function} eventListener | ||
* @param {Boolean} capture | ||
* @return {Function} | ||
* @api public | ||
*/ | ||
|
||
off: function(node, eventName, eventListener, capture) { | ||
node[unbind](eventName, eventListener, capture || false); | ||
return eventListener; | ||
} | ||
one: noop, | ||
on: noop, | ||
off: noop, | ||
}; | ||
|
||
if (canUseDOM) { | ||
const bind = 'addEventListener'; | ||
const unbind = 'removeEventListener'; | ||
|
||
Events = { | ||
one: function(node, eventNames, eventListener) { | ||
var typeArray = eventNames.split(' '); | ||
var recursiveFunction = function(e) { | ||
e.target.removeEventListener(e.type, recursiveFunction); | ||
return eventListener(e); | ||
}; | ||
|
||
for (var i = typeArray.length - 1; i >= 0; i--) { | ||
this.on(node, typeArray[i], recursiveFunction, false); | ||
} | ||
}, | ||
|
||
|
||
/** | ||
* Bind `node` event `eventName` to `eventListener`. | ||
* | ||
* @param {Element} node | ||
* @param {String} eventName | ||
* @param {Function} eventListener | ||
* @param {Boolean} capture | ||
* @return {Obejct} | ||
* @api public | ||
*/ | ||
|
||
on: function(node, eventName, eventListener, capture) { | ||
node[bind](eventName, eventListener, capture || false); | ||
|
||
return { | ||
off: function() { | ||
node[unbind](eventName, eventListener, capture || false); | ||
} | ||
}; | ||
}, | ||
|
||
|
||
/** | ||
* Unbind `node` event `eventName`'s callback `eventListener`. | ||
* | ||
* @param {Element} node | ||
* @param {String} eventName | ||
* @param {Function} eventListener | ||
* @param {Boolean} capture | ||
* @return {Function} | ||
* @api public | ||
*/ | ||
|
||
off: function(node, eventName, eventListener, capture) { | ||
node[unbind](eventName, eventListener, capture || false); | ||
return eventListener; | ||
} | ||
}; | ||
} | ||
|
||
export default Events; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default !!(typeof window !== 'undefined' && window.document && window.document.createElement); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
let supportTouch = !!(('ontouchstart' in global) || | ||
const supportTouch = !!(('ontouchstart' in global) || | ||
global.DocumentTouch && document instanceof DocumentTouch); | ||
|
||
export default supportTouch; |