Skip to content

Commit

Permalink
preparing for backend rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
minwe committed Apr 14, 2016
1 parent 49f51fd commit 082c00f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 58 deletions.
117 changes: 63 additions & 54 deletions src/js/utils/Events.js
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;
4 changes: 1 addition & 3 deletions src/js/utils/TransitionEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
*/

import CSSCore from './CSSCore';

let canUseDOM = !!(typeof window !== 'undefined' &&
window.document && window.document.createElement);
import canUseDOM from './canUseDOM';

/**
* EVENT_NAME_MAP is used to determine which event fired when a
Expand Down
1 change: 1 addition & 0 deletions src/js/utils/canUseDOM.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default !!(typeof window !== 'undefined' && window.document && window.document.createElement);
2 changes: 1 addition & 1 deletion src/js/utils/isTouchSupported.js
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;

0 comments on commit 082c00f

Please sign in to comment.