Skip to content

Commit add4a83

Browse files
committed
Release v0.2.3
1 parent 54ce8ff commit add4a83

File tree

3 files changed

+57
-29
lines changed

3 files changed

+57
-29
lines changed

dist/react-input-range.js

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,8 @@ var _react2 = _interopRequireDefault(_react);
477477

478478
var _InputRangeUtil = require('InputRangeUtil');
479479

480+
_react2['default'].initializeTouchEvents(true);
481+
480482
var InputRangeSlider = (function (_React$Component) {
481483
_inherits(InputRangeSlider, _React$Component);
482484

@@ -487,7 +489,7 @@ var InputRangeSlider = (function (_React$Component) {
487489

488490
this.state = {};
489491

490-
(0, _InputRangeUtil.autobind)(['handleClick', 'handleMouseDown', 'handleMouseUp', 'handleMouseMove', 'handleKeyDown'], this);
492+
(0, _InputRangeUtil.autobind)(['handleClick', 'handleMouseDown', 'handleMouseUp', 'handleMouseMove', 'handleTouchStart', 'handleTouchEnd', 'handleTouchMove', 'handleKeyDown'], this);
491493
}
492494

493495
_createClass(InputRangeSlider, [{
@@ -513,6 +515,11 @@ var InputRangeSlider = (function (_React$Component) {
513515

514516
this.setState({ style: style });
515517
}
518+
}, {
519+
key: 'handleClick',
520+
value: function handleClick(event) {
521+
event.preventDefault();
522+
}
516523
}, {
517524
key: 'handleMouseDown',
518525
value: function handleMouseDown() {
@@ -530,15 +537,35 @@ var InputRangeSlider = (function (_React$Component) {
530537
document.removeEventListener('mouseup', this.handleMouseUp);
531538
}
532539
}, {
533-
key: 'handleClick',
534-
value: function handleClick(event) {
540+
key: 'handleMouseMove',
541+
value: function handleMouseMove(event) {
542+
this.props.onSliderMouseMove(this, event);
543+
}
544+
}, {
545+
key: 'handleTouchStart',
546+
value: function handleTouchStart(event) {
547+
var document = this.document;
548+
535549
event.preventDefault();
550+
551+
document.addEventListener('touchmove', this.handleTouchMove);
552+
document.addEventListener('touchend', this.handleTouchEnd);
536553
}
537554
}, {
538-
key: 'handleMouseMove',
539-
value: function handleMouseMove(event) {
555+
key: 'handleTouchMove',
556+
value: function handleTouchMove(event) {
540557
this.props.onSliderMouseMove(this, event);
541558
}
559+
}, {
560+
key: 'handleTouchEnd',
561+
value: function handleTouchEnd() {
562+
var document = this.document;
563+
564+
event.preventDefault();
565+
566+
document.removeEventListener('touchmove', this.handleTouchMove);
567+
document.removeEventListener('touchend', this.handleTouchEnd);
568+
}
542569
}, {
543570
key: 'handleKeyDown',
544571
value: function handleKeyDown(event) {
@@ -572,6 +599,7 @@ var InputRangeSlider = (function (_React$Component) {
572599
onClick: this.handleClick,
573600
onKeyDown: this.handleKeyDown,
574601
onMouseDown: this.handleMouseDown,
602+
onTouchStart: this.handleTouchStart,
575603
role: 'slider' })
576604
);
577605
}
@@ -627,6 +655,8 @@ var _react2 = _interopRequireDefault(_react);
627655

628656
var _InputRangeUtil = require('InputRangeUtil');
629657

658+
_react2['default'].initializeTouchEvents(true);
659+
630660
var InputRangeTrack = (function (_React$Component) {
631661
_inherits(InputRangeTrack, _React$Component);
632662

@@ -637,7 +667,7 @@ var InputRangeTrack = (function (_React$Component) {
637667

638668
this.state = {};
639669

640-
(0, _InputRangeUtil.autobind)(['handleMouseDown'], this);
670+
(0, _InputRangeUtil.autobind)(['handleMouseDown', 'handleTouchStart'], this);
641671
}
642672

643673
_createClass(InputRangeTrack, [{
@@ -669,7 +699,10 @@ var InputRangeTrack = (function (_React$Component) {
669699
key: 'handleMouseDown',
670700
value: function handleMouseDown(event) {
671701
var trackClientRect = this.clientRect;
672-
var clientX = event.clientX;
702+
703+
var _ref = event.touches ? event.touches[0] : event;
704+
705+
var clientX = _ref.clientX;
673706

674707
var position = {
675708
x: clientX - trackClientRect.left,
@@ -678,6 +711,13 @@ var InputRangeTrack = (function (_React$Component) {
678711

679712
this.props.onTrackMouseDown(this, position);
680713
}
714+
}, {
715+
key: 'handleTouchStart',
716+
value: function handleTouchStart(event) {
717+
event.preventDefault();
718+
719+
this.handleMouseDown(event);
720+
}
681721
}, {
682722
key: 'render',
683723
value: function render() {
@@ -687,6 +727,7 @@ var InputRangeTrack = (function (_React$Component) {
687727
'div',
688728
{
689729
onMouseDown: this.handleMouseDown,
730+
onTouchStart: this.handleTouchStart,
690731
className: 'InputRange-track InputRange-track--container' },
691732
_react2['default'].createElement('div', {
692733
style: activeTrackStyle,
@@ -727,26 +768,8 @@ function clamp(value, min, max) {
727768
return Math.min(Math.max(value, min), max);
728769
}
729770

730-
function assign(target) {
731-
var sources = Array.prototype.slice.call(arguments, 1);
732-
733-
sources.forEach(function (source) {
734-
if (!source) {
735-
return;
736-
}
737-
738-
var keys = Object.keys(source);
739-
740-
keys.forEach(function (key) {
741-
target[key] = source[key];
742-
});
743-
});
744-
745-
return target;
746-
}
747-
748771
function extend() {
749-
return assign.apply(Object, arguments);
772+
return Object.assign.apply(Object, arguments);
750773
}
751774

752775
function captialize(string) {
@@ -859,8 +882,13 @@ var InputRangeValueTransformer = (function () {
859882
value: function positionFromEvent(event) {
860883
var trackClientRect = this.component.trackClientRect;
861884
var length = trackClientRect.width;
885+
886+
var _ref = event.touches ? event.touches[0] : event;
887+
888+
var clientX = _ref.clientX;
889+
862890
var position = {
863-
x: (0, _InputRangeUtil.clamp)(event.clientX - trackClientRect.left, 0, length),
891+
x: (0, _InputRangeUtil.clamp)(clientX - trackClientRect.left, 0, length),
864892
y: 0
865893
};
866894

0 commit comments

Comments
 (0)