@@ -6,6 +6,7 @@ modules.define(
6
6
'inherit' ,
7
7
'y-extend' ,
8
8
'chitalka-ui' ,
9
+ 'hammer' ,
9
10
'storage'
10
11
] ,
11
12
function (
@@ -15,6 +16,7 @@ modules.define(
15
16
inherit ,
16
17
extend ,
17
18
ChitalkaUI ,
19
+ Hammer ,
18
20
Storage
19
21
) {
20
22
@@ -24,6 +26,15 @@ modules.define(
24
26
throw new Error ( 'UNIMPLEMENTED METHOD: ' + method ) ;
25
27
} ;
26
28
29
+ /**
30
+ * Detect if device is touch
31
+ * @see http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript
32
+ */
33
+ var isTouch = function ( ) {
34
+ return 'ontouchstart' in window // works on most browsers
35
+ || 'onmsgesturechange' in window ; // works on ie10
36
+ } ;
37
+
27
38
/**
28
39
* Расширение объекта Math для вычисления медианы массива
29
40
*
@@ -117,7 +128,7 @@ modules.define(
117
128
}
118
129
119
130
if ( params . touch ) {
120
- this . _initTouchEvents ( ) ;
131
+ isTouch ( ) && this . _initTouchEvents ( ) ;
121
132
}
122
133
123
134
this . _fontSizeLimits = params . fontSize ;
@@ -158,6 +169,22 @@ modules.define(
158
169
* в функции выполняется навешивание соответствующих событий
159
170
*/
160
171
_initTouchEvents : function ( ) {
172
+ this . _swiper = new Hammer ( this . getDomNode ( ) [ 0 ] ) ;
173
+
174
+ this . _swiper . on ( 'swipe' , function ( e ) {
175
+ var direction = ( e . direction === 2 ) ? 'left' : 'right' ;
176
+
177
+ switch ( direction ) {
178
+ case 'left' :
179
+ this . nextPage ( ) ;
180
+ break ;
181
+
182
+ case 'right' :
183
+ this . previousPage ( ) ;
184
+ break ;
185
+ }
186
+ } . bind ( this ) ) ;
187
+
161
188
} ,
162
189
163
190
_onKeyDown : function ( e ) {
0 commit comments