From 760ab1d4ca5a9ab85dd78d01fe96d6b758cba132 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 12 Apr 2017 19:05:02 +0200 Subject: [PATCH] #1344 --- js/libs/fluidbook/fluidbook.interact.js | 16 ++ js/libs/fluidbook/fluidbook.js | 4 +- js/libs/fluidbook/fluidbook.touch.js | 250 ------------------------ 3 files changed, 17 insertions(+), 253 deletions(-) create mode 100644 js/libs/fluidbook/fluidbook.interact.js delete mode 100644 js/libs/fluidbook/fluidbook.touch.js diff --git a/js/libs/fluidbook/fluidbook.interact.js b/js/libs/fluidbook/fluidbook.interact.js new file mode 100644 index 00000000..0db6e720 --- /dev/null +++ b/js/libs/fluidbook/fluidbook.interact.js @@ -0,0 +1,16 @@ +function FluidbookInteract(fluidbook) { + this.fluidbook = fluidbook; + this.init(); +} + +FluidbookInteract.prototype = { + init: function () { + var $this = this; + interact(document).on('move', function (e) { + $this.move(e); + }); + }, + move: function (e) { + console.log(e); + } +} \ No newline at end of file diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index 6f79b0e4..99aa67f8 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -34,9 +34,7 @@ Fluidbook.prototype = { this.waiters = []; this.viewport = new FluidbookViewport(this); this.viewport.updateViewport(); - if (Modernizr.ftouch && this.support.transitions2d && this.datas.mobileTransitions != 'none') { - this.touch = new FluidbookTouch(this); - } + this.interact=new FluidbookInteract(this); this.background = new FluidbookBackground(this); this.l10n = new FluidbookL10N(this, $_GET['lang']); this.video = new FluidbookVideo(this); diff --git a/js/libs/fluidbook/fluidbook.touch.js b/js/libs/fluidbook/fluidbook.touch.js deleted file mode 100644 index 345d26ee..00000000 --- a/js/libs/fluidbook/fluidbook.touch.js +++ /dev/null @@ -1,250 +0,0 @@ -function FluidbookTouch(fluidbook) { - this.fluidbook = fluidbook; - this.scale = 1; - - this.startX = 0; - this.startY = 0; - this.offsetX = 0; - this.offsetY = 0; - - this.triggerOffset = 0.05; - this.triggered = false; - this.gesturing = false; - - this.externalgesture = false; - - this.init(); -} - - -FluidbookTouch.prototype = { - init: function () { - this.reset(); - - $(document).on('touchstart', $.proxy(this.start, this)); - $(document).on('touchend', $.proxy(this.end, this)); - $(document).on('touchmove', $.proxy(this.move, this)); - $(document).on('touchcancel', $.proxy(this.cancel, this)); - $(document).on('gesturestart', $.proxy(this.gesturestart, this)); - $(document).on('gesturechange', $.proxy(this.gesturechange, this)); - $(document).on('gestureend', $.proxy(this.gestureend, this)); - - $(document).on('MSPointerDown', $.proxy(this.msdown, this)); - $(document).on('MSPointerUp', $.proxy(this.msup, this)); - $(document).on('MSPointerMove', $.proxy(this.msmove, this)); - }, - msdown: function (event) { - var e = event.originalEvent; - if (e.pointerType != e.MSPOINTER_TYPE_TOUCH) { - return true; - } - this._start(e.screenX, e.screenY); - return true; - }, - msup: function (event) { - var e = event.originalEvent; - if (e.pointerType != e.MSPOINTER_TYPE_TOUCH) { - return true; - } - this._end(); - }, - msmove: function (event) { - var e = event.originalEvent; - if (e.pointerType != e.MSPOINTER_TYPE_TOUCH) { - return true; - } - return this._move(e.screenX, e.screenY); - }, - allowMove: function () { - return !(this.fluidbook.support.getZoomLevel() <= 1 && !this.fluidbook.viewMode()); - }, - allowSlide: function () { - return !(this.gesturing || this.fluidbook.support.getZoomLevel() > 1 || this.fluidbook.viewMode() || this.fluidbook.help.isVisible() || this.externalgesture); - }, - reset: function () { - this.startX = 0; - this.startY = 0; - this.offsetX = 0; - this.offsetY = 0; - this.triggered = false; - this.updateZoom(); - }, - gesturestart: function (event) { - if (this.fluidbook.pad.enabled) { - return false; - } - var e = event.originalEvent; - this.enableUserScale(); - this.gesturing = true; - this.updateZoom(); - return true; - }, - gesturechange: function (event) { - if (this.fluidbook.pad.enabled) { - return false; - } - var e = event.originalEvent; - this.gesturing = true; - this.updateZoom(); - return true; - }, - gestureend: function (event) { - if (this.fluidbook.pad.enabled) { - return false; - } - - var e = event.originalEvent; - this.gesturing = false; - - if (DetectZoom.zoom() > 1) { - $('html').addClass('nopan'); - } else { - $('html').removeClass('nopan'); - } - this.updateZoom(); - return true; - }, - start: function (event) { - var e = event.originalEvent; - var touches = e.touches; - - if (touches.length > 1) { - this.enableUserScale(); - return true; - } - - this._start(touches[0].pageX, touches[0].pageY); - return true; - }, - end: function (event) { - var e = event.originalEvent; - var touches = e.touches; - - if (touches.length == 0) { - this._end(); - } - return true; - }, - updateZoom: function () { - var currentZoom = $('body').data('zoom'); - var newZoom = DetectZoom.zoom(); - if (currentZoom != newZoom) { - $(window).trigger('fluidbookzoom', newZoom); - } - }, - testOffset: function () { - if (this.triggered) { - return false; - } - if (this.allowMove()) { - return false; - } - if (!this.fluidbook.pad.enabled) { - if (Math.abs(this.offsetX) < Math.abs(this.offsetY)) { - return false; - } - if (this.allowSlide()) { - if (this.offsetX < -this.triggerOffset) { - if (this.fluidbook.l10n.dir == 'ltr') { - this.fluidbook.goNextPage(); - } else { - this.fluidbook.goPreviousPage(); - } - - return true; - } else if (this.offsetX > this.triggerOffset) { - if (this.fluidbook.l10n.dir == 'ltr') { - this.fluidbook.goPreviousPage(); - } else { - this.fluidbook.goNextPage(); - } - return true; - } - } - } else { - // Mode mag pad - if (this.allowSlide()) { - var offset = this.offsetX; - var way = 'x'; - if (Math.abs(this.offsetX) < Math.abs(this.offsetY)) { - offset = this.offsetY; - way = 'y'; - } - - if (Math.abs(offset) < this.triggerOffset) { - return false; - } - - if (offset < -this.triggerOffset) { - if (way == 'x') { - this.fluidbook.goNextChapter(); - } else { - this.fluidbook.goNextChapterPage(); - } - } else { - if (way == 'x') { - this.fluidbook.goPreviousChapter(); - } else { - this.fluidbook.goPreviousChapterPage(); - } - } - return true; - } - } - return false; - }, - cancel: function (event) { - this.end(event); - return true; - }, - move: function (event) { - var e = event.originalEvent; - - var touches = e.touches; - - if (touches.length > 1) { - return true; - } - - return this._move(touches[0].pageX, touches[0].pageY); - }, - _start: function (x, y) { - this.startX = x; - this.startY = y; - }, - _move: function (x, y) { - if (!isNaN(this.startX)) { - this.offsetX = (x - this.startX) / $(window).width(); - } - - if (!isNaN(this.startY)) { - this.offsetY = (y - this.startY) / $(window).height(); - } - - this.testOffset(); - return this.allowMove(); - }, - _end: function () { - this.testOffset(); - this.reset(); - }, - enableUserScale: function () { - if (this.fluidbook.viewport === undefined) { - return; - } - if (this.fluidbook.pad.enabled) { - this.fluidbook.viewport.maxScale = 1; - this.fluidbook.viewport.userScalable = false; - } else { - this.fluidbook.viewport.maxScale = 5; - this.fluidbook.viewport.userScalable = true; - if (this.fluidbook.support.iOS) { - this.fluidbook.viewport.initialScale = 3; - } - } - - - this.fluidbook.viewport.updateViewport(); - } -}; - -- 2.39.5