diff options
author | Pacien TRAN-GIRARD | 2014-08-10 17:28:37 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-08-10 17:28:37 +0200 |
commit | e7bf5952d0729b37e677168b6e8fbd1ce58ed1a2 (patch) | |
tree | 189988e3e272b806262d1df6b87f1da089ef4af8 /point/binding/touch.js | |
parent | a32e898c8d7ad3774f5654e88bb24d5c26482137 (diff) | |
download | whatsthepoint-master.tar.gz |
Diffstat (limited to 'point/binding/touch.js')
-rw-r--r-- | point/binding/touch.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/point/binding/touch.js b/point/binding/touch.js new file mode 100644 index 0000000..a09d5fd --- /dev/null +++ b/point/binding/touch.js | |||
@@ -0,0 +1,93 @@ | |||
1 | /* | ||
2 | * This file is part of "What's The Point" <https://github.com/Pacien/WhatsThePoint> | ||
3 | * Copyright (C) 2014 Pacien TRAN-GIRARD | ||
4 | * | ||
5 | * "What's The Point" is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU Affero General Public License as | ||
7 | * published by the Free Software Foundation, either version 3 of the | ||
8 | * License, or (at your option) any later version. | ||
9 | * | ||
10 | * "What's The Point" is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | define(["libs/hammerjs/hammer.min", "control/control"], function (hammer, control) { | ||
20 | |||
21 | var touch = { | ||
22 | |||
23 | ACTION: { | ||
24 | SWIPE: "swipe", | ||
25 | DOUBLETAP: "doubletap", | ||
26 | TOUCHMOVE: "touchmove", | ||
27 | DRAG: "drag", | ||
28 | }, | ||
29 | |||
30 | DIRECTION: { | ||
31 | DOWN: "down", | ||
32 | LEFT: "left", | ||
33 | UP: "up", | ||
34 | RIGHT: "right", | ||
35 | }, | ||
36 | |||
37 | init: function (settings) { | ||
38 | this.touchZone = document.body; | ||
39 | |||
40 | this.hammerElement = hammer(this.touchZone); | ||
41 | |||
42 | this.hammerElement.options.drag = true; | ||
43 | this.hammerElement.options.dragBlockHorizontal = true; | ||
44 | this.hammerElement.options.dragBlockVertical = true; | ||
45 | this.hammerElement.options.dragLockMinDistance = 20; | ||
46 | |||
47 | this.disableSelect(); | ||
48 | this.bindEvent(); | ||
49 | }, | ||
50 | |||
51 | disableSelect: function () { | ||
52 | this.touchZone.style.WebkitTouchCallout = "none"; | ||
53 | this.touchZone.style.WebkitUserSelect = "none"; | ||
54 | this.touchZone.style.KhtmlUserSelect = "none"; | ||
55 | this.touchZone.style.MozUserSelect = "none"; | ||
56 | this.touchZone.style.msUserSelect = "none"; | ||
57 | this.touchZone.style.userSelect = "none"; | ||
58 | }, | ||
59 | |||
60 | translateSwipe: function (swipeDirection) { | ||
61 | switch (swipeDirection) { | ||
62 | case this.DIRECTION.LEFT: | ||
63 | return control.dispatchEvent(control.EVENT.GOTO, control.GOTO.NEXT_SLIDE); | ||
64 | |||
65 | case this.DIRECTION.RIGHT: | ||
66 | return control.dispatchEvent(control.EVENT.GOTO, control.GOTO.PREVIOUS_SLIDE); | ||
67 | |||
68 | case this.DIRECTION.UP: | ||
69 | return control.dispatchEvent(control.EVENT.SHOW, control.SHOW.NOTES); | ||
70 | |||
71 | case this.DIRECTION.DOWN: | ||
72 | return control.dispatchEvent(control.EVENT.SHOW, control.SHOW.SLIDES); | ||
73 | } | ||
74 | }, | ||
75 | |||
76 | handleDoubletap: function () { | ||
77 | control.dispatchEvent(control.EVENT.TOGGLE, control.TOGGLE.FULLSCREEN); | ||
78 | }, | ||
79 | |||
80 | bindEvent: function () { | ||
81 | this.hammerElement.on(this.ACTION.SWIPE, function (swipeEvent) { | ||
82 | touch.translateSwipe(swipeEvent.gesture.direction); | ||
83 | }); | ||
84 | |||
85 | this.hammerElement.on(this.ACTION.DOUBLETAP, function (doubletapEvent) { | ||
86 | touch.handleDoubletap(); | ||
87 | }); | ||
88 | }, | ||
89 | }; | ||
90 | |||
91 | return touch; | ||
92 | |||
93 | }); | ||