|
213 | 213 | return Theme[key] === value; |
214 | 214 | }); |
215 | 215 | }, |
| 216 | + getTouchDirection: function(x, width) { |
| 217 | + if (!x || !width) { |
| 218 | + return null; |
| 219 | + } |
| 220 | + if (x > width * 2 / 3) { |
| 221 | + return TouchDirection.RIGHT; |
| 222 | + } else if (x > width / 2) { |
| 223 | + return TouchDirection.CENTER; |
| 224 | + } else { |
| 225 | + return TouchDirection.LEFT; |
| 226 | + } |
| 227 | + }, |
| 228 | + getTouchType: function() { |
| 229 | + if (!state.touch.start) { |
| 230 | + return null; |
| 231 | + } |
| 232 | + var elapsedTime = Date.now() - state.touch.start; |
| 233 | + if (elapsedTime > 500) { |
| 234 | + return TouchType.HOLD; |
| 235 | + } else if (elapsedTime > 250) { |
| 236 | + return TouchType.PRESS; |
| 237 | + } else { |
| 238 | + return TouchType.TAP; |
| 239 | + } |
| 240 | + }, |
216 | 241 | loadSlides: function(url) { |
217 | 242 | return m.request({method: 'GET', url: url}). |
218 | 243 | then(state.setSlides). |
|
230 | 255 | nextTheme: function() { |
231 | 256 | state.setTheme((state.theme + 1) % Object.keys(Theme).length); |
232 | 257 | }, |
233 | | - touchType: function() { |
234 | | - if (!state.touch.start) { |
235 | | - return null; |
236 | | - } |
237 | | - var elapsedTime = Date.now() - state.touch.start; |
238 | | - if (elapsedTime > 500) { |
239 | | - return TouchType.HOLD; |
240 | | - } else if (elapsedTime > 250) { |
241 | | - return TouchType.PRESS; |
242 | | - } else { |
243 | | - return TouchType.TAP; |
244 | | - } |
245 | | - }, |
246 | 258 | togglePointer: function() { |
247 | 259 | state.pointer = !state.pointer; |
248 | 260 | }, |
|
287 | 299 | return; |
288 | 300 | } |
289 | 301 | var touch = event.touches[0]; |
290 | | - var pageCenter = document.body.clientWidth / 2; |
291 | | - state.setTouch( |
292 | | - touch.pageX < pageCenter ? TouchDirection.LEFT : TouchDirection.RIGHT |
293 | | - ); |
| 302 | + var direction = state.getTouchDirection(touch.pageX, document.body.clientWidth); |
| 303 | + state.setTouch(direction); |
294 | 304 | }, |
295 | 305 | handleTouchmove: function(event) { |
296 | 306 | event.preventDefault(); |
|
301 | 311 | if (event.touches.length > 0) { |
302 | 312 | return; |
303 | 313 | } |
304 | | - var type = state.touchType(); |
| 314 | + var type = state.getTouchType(); |
305 | 315 | var direction = state.touch.direction; |
306 | 316 | if (type === TouchType.HOLD) { |
307 | 317 | state.nextTheme(); |
|
0 commit comments