]> _ Git - fluidbook-html5.git/commitdiff
wip #1487 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 12 Jul 2017 16:31:01 +0000 (18:31 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 12 Jul 2017 16:31:01 +0000 (18:31 +0200)
js/libs/fluidbook/fluidbook.touch.js
js/libs/fluidbook/fluidbook.zoom.js

index c10e06d6148c3778e746b2e83249c2bd690af865..be7bf333cf8119147de968fa0325908542928165 100644 (file)
@@ -6,6 +6,8 @@ function FluidbookTouch(fluidbook) {
     this.offsetX = 0;
     this.offsetY = 0;
 
+    this.zoomAtPinchStart = 0;
+
     this.triggerOffset = 0.05;
 
     this.init();
@@ -51,8 +53,23 @@ FluidbookTouch.prototype = {
             }
             event.preventDefault();
         });
+        hm.on('pinchstart', function (event) {
+            console.log('start');
+            $this.zoomAtPinchStart = $this.fluidbook.zoom.zoom;
+            $this.pinchZoom(event.scale, true);
+            event.preventDefault();
+        });
         hm.on('pinch', function (event) {
-            console.log(event);
+            console.log('pinch');
+            if ($this.zoomAtPinchStart != 0) {
+                $this.pinchZoom(event.scale, false);
+                event.preventDefault();
+            }
+        })
+        hm.on('pinchend pinchcancel', function (event) {
+            console.log('end');
+            $this.pinchZoom(event.scale, true);
+            $this.zoomAtPinchStart = 0;
             event.preventDefault();
         });
 
@@ -99,9 +116,21 @@ FluidbookTouch.prototype = {
      });
      },*/
 
-    pinchZoom: function (s) {
+    pinchZoom: function (s, end) {
         this.fluidbook.zoom.setTransition(false);
-        this.fluidbook.zoom.setZoom(s, undefined);
+        var amplitudeRegulation = 0.25;
+        var dir;
+        if (s > 1) {
+            s = 1 + ((s - 1) * amplitudeRegulation);
+            dir = 1;
+        } else if (s < 1) {
+            var amplitude = (1 - s) * amplitudeRegulation;
+            s = 1 - amplitude;
+            dir = -1;
+        }
+
+
+        this.fluidbook.zoom.setZoom(this.zoomAtPinchStart * s, dir, end);
     },
 
     dragzoom: function (e) {
index 341efd336556ff0475bbfb749fdb046c586c7973..c54dd513a3ab8f5d2924590ddafdbba40da7dc64 100644 (file)
@@ -33,7 +33,12 @@ FluidbookZoom.prototype = {
      * @param zoom Zoom level
      * @param direction Zoom direction (1=zoom in, -1=zoom out)
      */
-    setZoom: function (zoom, direction) {
+
+
+    setZoom: function (zoom, direction, end) {
+        if (end == undefined) {
+            end = false;
+        }
         if (direction == undefined) {
             if (this.zoom > zoom) {
                 direction = -1;
@@ -49,7 +54,8 @@ FluidbookZoom.prototype = {
         if (this.zoom == zoom) {
             return;
         }
-        if (!this.transition) {
+        if (!this.transition && end == true) {
+
             if (direction == 1) {
                 if (zoom < 1.25) {
                     zoom = 2;
@@ -61,6 +67,7 @@ FluidbookZoom.prototype = {
                     this.setTransition(true);
                 }
             }
+
         }
         if (this.zoom == zoom) {
             return;