forked from maccman/holla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.ios.js
More file actions
66 lines (54 loc) · 1.71 KB
/
Copy pathjquery.ios.js
File metadata and controls
66 lines (54 loc) · 1.71 KB
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
//= require <jquery>
(function($){
$.support.touch = (typeof Touch != "undefined");
var TouchDrag = function(element){
if ( !$.support.touch ) return;
this.element = $(element);
this.element.bind("touchstart", this.proxy(this.touchStart));
this.element.bind("touchmove", this.proxy(this.touchMove));
this.element.bind("touchend", this.proxy(this.touchEnd));
};
// Class helper functions
TouchDrag.fn = TouchDrag.prototype;
TouchDrag.fn.proxy = function(func){
var thisObject = this;
return(function(){
return func.apply(thisObject, arguments);
});
};
TouchDrag.fn.simulateEvent = function(type, e){
var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent(
type, true, true, window, 1,
e.screenX, e.screenY, e.clientX, e.clientY,
false, false, false, false, 0 /*left*/, null
);
e.target.dispatchEvent(simulatedEvent);
};
TouchDrag.fn.touchStart = function(e){
this.dragging = false;
e = e.originalEvent;
e.preventDefault();
this.simulateEvent("mousedown", e.changedTouches[0]);
};
TouchDrag.fn.touchMove = function(e){
this.dragging = true;
e = e.originalEvent;
// If two finger touch
if (e.touches.length == 2) {
e.preventDefault();
this.simulateEvent("mousemove", e.changedTouches[0]);
}
};
TouchDrag.fn.touchEnd = function(e){
e = e.originalEvent;
e.preventDefault();
this.simulateEvent("mouseup", e.changedTouches[0]);
if ( !this.dragging )
this.simulateEvent("click", e.changedTouches[0]);
};
$.fn.touchDrag = function(){
new TouchDrag(this);
return this;
}
})(jQuery);