-
Notifications
You must be signed in to change notification settings - Fork 146
/
jQRangeSliderMouseTouch.js
121 lines (88 loc) · 2.53 KB
/
jQRangeSliderMouseTouch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* jQRangeSlider
* A javascript slider selector that supports dates
*
* Copyright (C) Guillaume Gautreau 2012
* Dual licensed under the MIT or GPL Version 2 licenses.
*/
(function($, undefined){
"use strict";
$.widget("ui.rangeSliderMouseTouch", $.ui.mouse, {
enabled: true,
_mouseInit: function(){
var that = this;
this._super();
this._mouseDownEvent = false;
this.element.on('touchstart.' + this.widgetName, function(event) {
return that._touchStart(event);
});
},
_mouseDestroy: function(){
$(document)
.off('touchmove.' + this.widgetName, this._touchMoveDelegate)
.off('touchend.' + this.widgetName, this._touchEndDelegate);
this._super();
},
enable: function(){
this.enabled = true;
},
disable: function(){
this.enabled = false;
},
destroy: function(){
this._mouseDestroy();
this._super();
this._mouseInit = null;
},
_touchStart: function(event){
if (!this.enabled) return false;
event.which = 1;
event.preventDefault();
this._fillTouchEvent(event);
var that = this,
downEvent = this._mouseDownEvent;
this._mouseDown(event);
if (downEvent !== this._mouseDownEvent){
this._touchEndDelegate = function(event){
that._touchEnd(event);
}
this._touchMoveDelegate = function(event){
that._touchMove(event);
}
$(document)
.on('touchmove.' + this.widgetName, this._touchMoveDelegate)
.on('touchend.' + this.widgetName, this._touchEndDelegate);
}
},
_mouseDown: function(event){
if (!this.enabled) return false;
return this._super(event);
},
_touchEnd: function(event){
this._fillTouchEvent(event);
this._mouseUp(event);
$(document)
.off('touchmove.' + this.widgetName, this._touchMoveDelegate)
.off('touchend.' + this.widgetName, this._touchEndDelegate);
this._mouseDownEvent = false;
// No other choice to reinitialize mouseHandled
$(document).trigger("mouseup");
},
_touchMove: function(event){
event.preventDefault();
this._fillTouchEvent(event);
return this._mouseMove(event);
},
_fillTouchEvent: function(event){
var touch;
if (typeof event.targetTouches === "undefined" && typeof event.changedTouches === "undefined"){
touch = event.originalEvent.targetTouches[0] || event.originalEvent.changedTouches[0];
} else {
touch = event.targetTouches[0] || event.changedTouches[0];
}
event.pageX = touch.pageX;
event.pageY = touch.pageY;
event.which = 1; // [~] fixes touch events for jquery-ui.1.11.x.mouse
}
});
}(jQuery));