add rc-util

This commit is contained in:
simaQ
2015-04-23 10:23:30 +08:00
parent 9138dff872
commit 8645e8dc68
3 changed files with 10 additions and 63 deletions
-56
View File
@@ -1,56 +0,0 @@
/**
* Copyright 2013-2014 Facebook, Inc.
*
* This file contains a modified version of:
* https://github.com/facebook/react/blob/v0.12.0/src/vendor/stubs/EventListener.js
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* TODO: remove in favour of solution provided by:
* https://github.com/facebook/react/issues/285
*/
/**
* Does not take into account specific nature of platform.
*/
'use strict';
var EventListener = {
/**
* Listen to DOM events during the bubble phase.
*
* @param {DOMEventTarget} target DOM element to register listener on.
* @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
* @param {function} callback Callback function.
* @return {object} Object with a `remove` method.
*/
listen: function listen(target, eventType, callback) {
if (target.addEventListener) {
target.addEventListener(eventType, callback, false);
return {
remove: function remove() {
target.removeEventListener(eventType, callback, false);
}
};
} else if (target.attachEvent) {
target.attachEvent('on' + eventType, callback);
return {
remove: function remove() {
target.detachEvent('on' + eventType, callback);
}
};
}
}
};
module.exports = EventListener;
+4 -4
View File
@@ -1,6 +1,6 @@
/** @jsx React.DOM */
var React = require('react');
var EventListener = require('./EventListener');
var DomUtils = require('rc-util').Dom;
function pauseEvent(e) {
if (e.stopPropagation) {
@@ -72,7 +72,7 @@ var Slider = React.createClass({
},
componentDidMount: function() {
this._onHandleResizeListener = EventListener.listen(window, 'resize', this.handleResize);
this._onHandleResizeListener = DomUtils.addEventListener(window, 'resize', this.handleResize);
this.handleResize();
},
@@ -150,8 +150,8 @@ var Slider = React.createClass({
},
_addEventHandles: function() {
this._onMouseMoveListener = EventListener.listen(document, 'mousemove', this._onMouseMove);
this._onMouseUpListener = EventListener.listen(document, 'mouseup', this._onMouseUp);
this._onMouseMoveListener = DomUtils.addEventListener(document, 'mousemove', this._onMouseMove);
this._onMouseUpListener = DomUtils.addEventListener(document, 'mouseup', this._onMouseUp);
},
_removeEventHandles: function () {
+6 -3
View File
@@ -23,7 +23,7 @@
"react": "*"
}
},
"config":{
"config": {
"port": 8000
},
"scripts": {
@@ -45,12 +45,15 @@
"rc-server": "2.x",
"rc-tools": "2.x",
"react": "0.13.x",
"node-dev":"2.x",
"node-dev": "2.x",
"jquery": "^1.11.2",
"css-loader": "^0.9.1"
},
"precommit": [
"lint",
"less"
]
],
"dependencies": {
"rc-util": "^2.0.2"
}
}