]> _ Git - fluidbook-html5.git/commitdiff
#1344
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 12 Apr 2017 17:05:02 +0000 (19:05 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 12 Apr 2017 17:05:02 +0000 (19:05 +0200)
js/libs/fluidbook/fluidbook.interact.js [new file with mode: 0644]
js/libs/fluidbook/fluidbook.js
js/libs/fluidbook/fluidbook.touch.js [deleted file]

diff --git a/js/libs/fluidbook/fluidbook.interact.js b/js/libs/fluidbook/fluidbook.interact.js
new file mode 100644 (file)
index 0000000..0db6e72
--- /dev/null
@@ -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
index 6f79b0e4275df4f12aecc356c49a80708ebdc0da..99aa67f8e150794fdce5fd40cab562fcb88862e4 100644 (file)
@@ -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 (file)
index 345d26e..0000000
+++ /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();
-    }
-};
-