]> _ Git - fluidbook-html5.git/commitdiff
wip #1487 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 14 Aug 2017 16:07:09 +0000 (18:07 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 14 Aug 2017 16:07:09 +0000 (18:07 +0200)
js/libs/fluidbook/fluidbook.desktop.js
js/libs/fluidbook/fluidbook.touch.js
js/libs/fluidbook/fluidbook.zoom.js

index 5d95e0c8feb2cb3ddb6a14b7940fc47197762740..7778a0e59c3b5b9dc1c4ca2d0c25b661ebd8377a 100644 (file)
@@ -33,7 +33,7 @@ FluidbookDesktop.prototype = {
         var x = e.pageX / this.fluidbook.resize.ww;
         var y = e.pageY / this.fluidbook.resize.hh;
 
-        this.fluidbook.zoom.setOrigin(x, y, force)
+        this.fluidbook.zoom.setOriginPct(x, y, force)
     },
     clickZoom: function (e, way) {
         if (way == undefined) {
index 32ddd580dfaef9a9d264507c7a085bf626154afb..a8112d8928ea629baafa386735531bbc46a133c4 100644 (file)
@@ -148,18 +148,12 @@ FluidbookTouch.prototype = {
             return;
         }
 
-        var diffx = this.fluidbook.resize.ww * (this.fluidbook.zoom.zoom - 1);
-        var diffy = this.fluidbook.resize.hh * (this.fluidbook.zoom.zoom - 1);
-
-        var currentX = this.fluidbook.zoom.origin[0] * diffx;
-        var currentY = this.fluidbook.zoom.origin[1] * diffy;
+        var currentX = this.fluidbook.zoom.originpx[0];
+        var currentY = this.fluidbook.zoom.originpx[1];
 
         var x = currentX - e.dx;
         var y = currentY - e.dy;
 
-        x /= diffx;
-        y /= diffy;
-
         this.fluidbook.zoom.setOrigin(x, y, true, inertia);
 
         return false;
@@ -242,13 +236,6 @@ FluidbookTouch.prototype = {
         var ox = (cx - zrect.left) / z;
         var oy = (cy - zrect.top) / z;
 
-        ox = ox / this.fluidbook.resize.ww;
-        oy = oy / this.fluidbook.resize.hh;
-
-        // touch pos in % of screen
-        var tx = cx / this.fluidbook.resize.ww;
-        var ty = cy / this.fluidbook.resize.hh;
-
         this.fluidbook.zoom.setOrigin(ox, oy, true);
     },
 };
index e5866d33ad05e6017c0d3b4ce7e6391c297344bb..542d451eda2ae1828d9489be3b1edb62baa293c3 100644 (file)
@@ -1,7 +1,8 @@
 function FluidbookZoom(fluidbook) {
     this.fluidbook = fluidbook;
     this.zoom = 0;
-    this.origin = ['0%', '0%'];
+    this.originpct = ['0%', '0%'];
+    this.originpx = ['0px', '0px'];
     this.max = this.fluidbook.datas.zoomw / 100;
     this.transition = true;
     this.hideInterfaceTimeout;
@@ -91,7 +92,7 @@ FluidbookZoom.prototype = {
         this.setZoom(1, -1);
     },
 
-    setOrigin: function (x, y, force, inertia) {
+    setOriginPct: function (x, y, force, inertia) {
         if (force == undefined) {
             force = false;
         }
@@ -100,7 +101,7 @@ FluidbookZoom.prototype = {
         }
         x = Math.min(1, Math.max(0, x));
         y = Math.min(1, Math.max(0, y));
-        this.origin = [x, y];
+        this.originpct = [x, y];
         if (!force && this.fluidbook.zoom.zoom == 1) {
             return;
         } else {
@@ -110,7 +111,34 @@ FluidbookZoom.prototype = {
                 $("#z").removeClass('transition-inertia');
             }
             $("#z").transform({
-                origin: [this.origin[0] * 100 + '%', this.origin[1] * 100 + '%']
+                origin: [this.originpct[0] * 100 + '%', this.originpct[1] * 100 + '%']
+            }, {
+                preserve: true
+            });
+        }
+    },
+
+    setOrigin: function (x, y, force, inertia) {
+        if (force == undefined) {
+            force = false;
+        }
+        if (inertia == undefined) {
+            inertia = false;
+        }
+        x = Math.max(0, Math.min(x, this.fluidbook.resize.ww));
+        y = Math.max(0, Math.min(y, this.fluidbook.resize.hh));
+
+        this.originpx = [x, y];
+        if (!force && this.fluidbook.zoom.zoom == 1) {
+            return;
+        } else {
+            if (inertia) {
+                $("#z").addClass('transition-inertia');
+            } else {
+                $("#z").removeClass('transition-inertia');
+            }
+            $("#z").transform({
+                origin: [this.originpx[0] + 'px', this.originpx[1] + 'px']
             }, {
                 preserve: true
             });
@@ -130,8 +158,6 @@ FluidbookZoom.prototype = {
 
         if (this.desktopScale == 1) {
             animation.origin = ['50%', '50%'];
-        } else {
-            animation.origin = [this.origin[0] * 100 + '%', this.origin[1] * 100 + '%'];
         }
 
         var hiddenElements = $("header,footer,#interface");
@@ -147,7 +173,7 @@ FluidbookZoom.prototype = {
             clearTimeout(this.hideInterfaceTimeout);
             $(hiddenElements).show().removeClass('hidden');
         }
-        $("#z").transform(animation);
+        $("#z").transform(animation, {preserve: true});
         $this.triggerEvent(((this.zoom == 1) ? 'out' : 'in') + '.start');
 
         if (!this.transition) {