forked from ghusse/jQRangeSlider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jQRangeSliderMouseTouch.js
102 lines (75 loc) · 2.31 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
/**
* 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, {
_mouseInit: function(){
var that = this;
$.ui.mouse.prototype._mouseInit.apply(this);
this._mouseDownEvent = false;
this.element.bind('touchstart.' + this.widgetName, function(event) {
return that._touchStart(event);
});
},
_mouseDestroy: function(){
$(document)
.unbind('touchmove.' + this.widgetName, this._touchMoveDelegate)
.unbind('touchend.' + this.widgetName, this._touchEndDelegate);
$.ui.mouse.prototype._mouseDestroy.apply(this);
},
destroy: function(){
this._mouseDestroy();
$.ui.mouse.prototype.destroy.apply(this);
this._mouseInit = null;
},
_touchStart: function(event){
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)
.bind('touchmove.' + this.widgetName, this._touchMoveDelegate)
.bind('touchend.' + this.widgetName, this._touchEndDelegate);
}
},
_touchEnd: function(event){
this._fillTouchEvent(event);
this._mouseUp(event);
$(document)
.unbind('touchmove.' + this.widgetName, this._touchMoveDelegate)
.unbind('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;
}
});
}(jQuery));