From 5940ff92251c8f9743a10ffc977fb88bcc7c003a Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 4 Apr 2019 19:49:54 +0200 Subject: [PATCH] wip #2657 @3 --- js/libs/fluidbook/fluidbook.touch.js | 30 ++++++++++++++++++---------- style/mobilefirst.less | 10 ++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.touch.js b/js/libs/fluidbook/fluidbook.touch.js index 9dce2ddf..fa968b91 100644 --- a/js/libs/fluidbook/fluidbook.touch.js +++ b/js/libs/fluidbook/fluidbook.touch.js @@ -40,7 +40,14 @@ FluidbookTouch.prototype = { initInteract: function () { var $this = this; - var hm = new Hammer.Manager(document.getElementById('main'), {domEvents: false}); + var options = { + domEvents: this.fluidbook.mobilefirst.enabled, + touchAction: 'compute' + }; + Hammer.defaults.domEvents = options.domEvents; + Hammer.defaults.touchAction = options.touchAction; + + var hm = new Hammer.Manager(document.getElementById('main'), options); hm.add(new Hammer.Tap({event: 'doubletap', taps: 2, interval: 500})); hm.add(new Hammer.Pinch({threshold: 0})); hm.get('pinch').set({enable: true}); @@ -84,11 +91,12 @@ FluidbookTouch.prototype = { event.preventDefault(); }); - var hmf = new Hammer.Manager(document.getElementById('fluidbook'), {domEvents: false}); + var hmf = new Hammer.Manager(document.getElementById('fluidbook'), options); hmf.add(new Hammer.Pan({threshold: 0})); hmf.on('panmove', function (event) { console.log('panmove'); if ($this.drag(event)) { + console.log('prevent scroll') event.preventDefault(); } }); @@ -128,17 +136,17 @@ FluidbookTouch.prototype = { if (end == undefined) { end = false; } - if (this.fluidbook.zoom.zoom == 1) { - if (this.startX == -1) { + if (this.fluidbook.zoom.zoom === 1) { + if (this.startX === -1) { this.startX = e.center.x; } - if (this.startY == -1) { + if (this.startY === -1) { this.startY = e.center.y; } this.offsetX = (e.center.x - this.startX) / this.fluidbook.resize.ww; this.offsetY = (e.center.y - this.startY) / this.fluidbook.resize.hh; - this.testSlideOffset(); + return this.testSlideOffset(); } else { this.resetSlide(); if (end) { @@ -148,6 +156,7 @@ FluidbookTouch.prototype = { } else { this.dragZoom(e, end); } + return true; } }, @@ -178,8 +187,9 @@ FluidbookTouch.prototype = { if (Math.abs(this.offsetX) < Math.abs(this.offsetY)) { return false; } + var ltr = this.fluidbook.l10n.dir === 'ltr'; if (this.offsetX < -this.triggerOffset) { - if (this.fluidbook.l10n.dir == 'ltr') { + if (ltr) { this.fluidbook.goNextPage(); this.resetSlide(); } else { @@ -189,7 +199,7 @@ FluidbookTouch.prototype = { return true; } else if (this.offsetX > this.triggerOffset) { - if (this.fluidbook.l10n.dir == 'ltr') { + if (ltr) { this.fluidbook.goPreviousPage(); this.resetSlide(); } else { @@ -213,7 +223,7 @@ FluidbookTouch.prototype = { } if (offset < -this.triggerOffset) { - if (way == 'x') { + if (way === 'x') { this.fluidbook.goNextChapter(); this.resetSlide(); } else { @@ -221,7 +231,7 @@ FluidbookTouch.prototype = { this.resetSlide(); } } else { - if (way == 'x') { + if (way === 'x') { this.fluidbook.goPreviousChapter(); this.resetSlide(); } else { diff --git a/style/mobilefirst.less b/style/mobilefirst.less index acb337ec..f487a348 100644 --- a/style/mobilefirst.less +++ b/style/mobilefirst.less @@ -11,6 +11,16 @@ opacity: @shadow-opacity*0.25; } } + + #fluidbook, #main { + touch-action: auto !important; + } + + .zoomed { + #fluidbook, #main { + touch-action: none !important; + } + } } .mf-nav { -- 2.39.5