Skip to content

Commit 3670091

Browse files
committed
add touch event support for mobile interaction
1 parent aafc5a8 commit 3670091

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

ui/widgets/slider.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
7878
this._handleIndex = null;
7979
this._detectOrientation();
8080
this._mouseInit();
81+
this._setupTouchEvents();
8182
this._calculateNewMax();
8283

8384
this._addClass( "ui-slider ui-slider-" + this.orientation,
@@ -304,6 +305,51 @@ return $.widget( "ui.slider", $.ui.mouse, {
304305
return this._trimAlignValue( valueMouse );
305306
},
306307

308+
_setupTouchEvents: function() {
309+
var that = this;
310+
311+
that.element
312+
.on( 'touchstart.slider', function( event ) {
313+
if ( ! event.cancelable ) {
314+
return;
315+
}
316+
317+
var touch = event.originalEvent.touches[0];
318+
that._mouseCapture({
319+
pageX: touch.pageX,
320+
pageY: touch.pageY,
321+
target: touch.target
322+
});
323+
324+
event.preventDefault();
325+
})
326+
.on( 'touchmove.slider', function( event ) {
327+
if ( ! that._mouseSliding || ! event.cancelable ) {
328+
return;
329+
}
330+
331+
var touch = event.originalEvent.touches[0];
332+
333+
that._mouseDrag({
334+
pageX: touch.pageX,
335+
pageY: touch.pageY,
336+
target: touch.target
337+
});
338+
339+
// Prevent page scrolling
340+
event.preventDefault();
341+
event.stopPropagation();
342+
})
343+
.on( 'touchend.slider', function( event ) {
344+
if ( ! that._mouseSliding || ! event.cancelable ) {
345+
return;
346+
}
347+
348+
that._mouseStop( event );
349+
event.preventDefault();
350+
});
351+
},
352+
307353
_uiHash: function( index, value, values ) {
308354
var uiHash = {
309355
handle: this.handles[ index ],

0 commit comments

Comments
 (0)