blob: e0519e61f3a5fffdd4bc4fe0b32048cfa75b4979 (
plain)
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
|
/* Touch events */
(function(exports) {
var PM_TOUCH_SENSITIVITY = 15;
var touchDX;
var touchDY;
var touchStartX;
var touchStartY;
function TouchManager(deck) {
this.deck_ = deck;
/* Add swiping */
document.body.addEventListener('touchstart', this.handleTouchStart.bind(this), false);
document.body.addEventListener('touchmove', this.handleTouchMove.bind(this), false);
document.body.addEventListener('touchend', this.handleTouchEnd.bind(this), false);
}
TouchManager.prototype.handleTouchStart = function(e) {
if (e.touches.length == 1) {
touchDX = 0;
touchDY = 0;
touchStartX = e.touches[0].pageX;
touchStartY = e.touches[0].pageY;
}
};
TouchManager.prototype.handleTouchMove = function(e) {
if (e.touches.length > 1) {
//this.cancelTouch();
} else {
touchDX = e.touches[0].pageX - touchStartX;
touchDY = e.touches[0].pageY - touchStartY;
}
};
TouchManager.prototype.handleTouchEnd = function(e) {
var dx = Math.abs(touchDX);
var dy = Math.abs(touchDY);
if ((dx > PM_TOUCH_SENSITIVITY) && (dy < (dx * 2 / 3))) {
if (touchDX > 0) {
this.deck_.prevSlide();
} else {
this.deck_.nextSlide();
}
}
//this.cancelTouch();
};
// TouchManager.prototype.cancelTouch = function() {
// console.log(touchDX)
// document.body.removeEventListener('touchmove', this.handleTouchMove.bind(this), false);
// document.body.removeEventListener('touchend', this.handleTouchMove.bind(this), false);
// };
exports.TouchManager = TouchManager;
})(window);
|