Add reaction to the swipe events on touch devices

This commit is contained in:
mokhov
2015-07-10 20:21:02 +03:00
parent e748934c8a
commit 4c93a5598b
4 changed files with 2494 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ module.exports = function (bt) {
bt.match('chitalka-fb2*', function (ctx) { bt.match('chitalka-fb2*', function (ctx) {
ctx.setInitOption('keyboard', true); ctx.setInitOption('keyboard', true);
ctx.setInitOption('touch', true);
ctx.setInitOption('url', ctx.getParam('url')); ctx.setInitOption('url', ctx.getParam('url'));
ctx.enableAutoInit(); ctx.enableAutoInit();

View File

@@ -1,3 +1,4 @@
- hammer
- chitalka - chitalka
- unzip - unzip
- storage - storage

View File

@@ -6,6 +6,7 @@ modules.define(
'inherit', 'inherit',
'y-extend', 'y-extend',
'chitalka-ui', 'chitalka-ui',
'hammer',
'storage' 'storage'
], ],
function ( function (
@@ -15,6 +16,7 @@ modules.define(
inherit, inherit,
extend, extend,
ChitalkaUI, ChitalkaUI,
Hammer,
Storage Storage
) { ) {
@@ -24,6 +26,15 @@ modules.define(
throw new Error('UNIMPLEMENTED METHOD: ' + method); throw new Error('UNIMPLEMENTED METHOD: ' + method);
}; };
/**
* Detect if device is touch
* @see http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript
*/
var isTouch = function () {
return 'ontouchstart' in window // works on most browsers
|| 'onmsgesturechange' in window; // works on ie10
};
/** /**
* Расширение объекта Math для вычисления медианы массива * Расширение объекта Math для вычисления медианы массива
* *
@@ -117,7 +128,7 @@ modules.define(
} }
if (params.touch) { if (params.touch) {
this._initTouchEvents(); isTouch() && this._initTouchEvents();
} }
this._fontSizeLimits = params.fontSize; this._fontSizeLimits = params.fontSize;
@@ -158,6 +169,22 @@ modules.define(
* в функции выполняется навешивание соответствующих событий * в функции выполняется навешивание соответствующих событий
*/ */
_initTouchEvents: function () { _initTouchEvents: function () {
this._swiper = new Hammer(this.getDomNode()[0]);
this._swiper.on('swipe', function(e) {
var direction = (e.direction === 2)? 'left' : 'right';
switch (direction) {
case 'left':
this.nextPage();
break;
case 'right':
this.previousPage();
break;
}
}.bind(this));
}, },
_onKeyDown: function (e) { _onKeyDown: function (e) {

2464
client/core/hammer/hammer.js Normal file

File diff suppressed because it is too large Load Diff