From: Vincent Vanwaelscappel Date: Wed, 12 Jul 2017 16:31:01 +0000 (+0200) Subject: wip #1487 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=d2ca89fb7fc8f8139f2f000874055a096c96ce59;p=fluidbook-html5.git wip #1487 @2 --- diff --git a/js/libs/fluidbook/fluidbook.touch.js b/js/libs/fluidbook/fluidbook.touch.js index c10e06d6..be7bf333 100644 --- a/js/libs/fluidbook/fluidbook.touch.js +++ b/js/libs/fluidbook/fluidbook.touch.js @@ -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) { diff --git a/js/libs/fluidbook/fluidbook.zoom.js b/js/libs/fluidbook/fluidbook.zoom.js index 341efd33..c54dd513 100644 --- a/js/libs/fluidbook/fluidbook.zoom.js +++ b/js/libs/fluidbook/fluidbook.zoom.js @@ -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;