},
initInteract: function () {
+ var pinchEnabled = true;
+ var doubletapEnabled = true;
+ var panEnabled = true;
+ var touchAction = 'compute';
+
+ if (this.fluidbook.mobilefirst.enabled) {
+ touchAction = 'auto';
+ }
+
var $this = this;
+ if (!doubletapEnabled && !panEnabled && !pinchEnabled) {
+ return;
+ }
+
var options = {
domEvents: this.fluidbook.mobilefirst.enabled,
- touchAction: 'compute'
+ touchAction: touchAction
};
Hammer.defaults.domEvents = options.domEvents;
Hammer.defaults.touchAction = options.touchAction;
var hm = new Hammer.Manager(document.getElementById('main'), options);
- hm.add(new Hammer.Tap({event: 'doubletap', taps: 2, interval: 500}));
- hm.add(new Hammer.Pinch({threshold: 0}));
- hm.get('pinch').set({enable: true});
-
- // Double tap
- hm.on('doubletap', function (event) {
- console.log('doubletap');
- if ($this.fluidbook.zoom.enabled) {
- if ($this.fluidbook.zoom.zoom > 1) {
- $this.fluidbook.zoom.setTransition(true);
- $this.fluidbook.zoom.resetZoom();
- } else {
- $this.setZoomOriginFromEvent(event.srcEvent);
- $this.fluidbook.zoom.setTransition(true);
- $this.fluidbook.zoom.setZoom($this.fluidbook.datas.zoom / 100, 1)
- }
- }
- event.preventDefault();
- });
- // Pinch
- hm.on('pinchstart', function (event) {
- if ($this.fluidbook.zoom.enabled) {
- if ($this.fluidbook.zoom.zoom === 1) {
- $this.setZoomOriginFromEvent({'pageX': event.center.x, 'pageY': event.center.y});
+ if (doubletapEnabled) {
+ hm.add(new Hammer.Tap({event: 'doubletap', taps: 2, interval: 500}));
+ }
+
+ if (pinchEnabled) {
+ hm.add(new Hammer.Pinch({threshold: 0}));
+ hm.get('pinch').set({enable: true});
+ }
+
+ if (doubletapEnabled) {
+ // Double tap
+ hm.on('doubletap', function (event) {
+ console.log('doubletap');
+ if ($this.fluidbook.zoom.enabled) {
+ if ($this.fluidbook.zoom.zoom > 1) {
+ $this.fluidbook.zoom.setTransition(true);
+ $this.fluidbook.zoom.resetZoom();
+ } else {
+ $this.setZoomOriginFromEvent(event.srcEvent);
+ $this.fluidbook.zoom.setTransition(true);
+ $this.fluidbook.zoom.setZoom($this.fluidbook.datas.zoom / 100, 1)
+ }
}
- $this.zoomAtPinchStart = $this.fluidbook.zoom.zoom;
- $this.pinchZoom(event.scale, false);
- }
- event.preventDefault();
- });
+ event.preventDefault();
+ });
+ }
+
+ if (pinchEnabled) {
- hm.on('pinch', function (event) {
- if ($this.fluidbook.zoom.enabled) {
- console.log('pinch');
- if ($this.zoomAtPinchStart !== 0) {
+ // Pinch
+ hm.on('pinchstart', function (event) {
+ if ($this.fluidbook.zoom.enabled) {
+ if ($this.fluidbook.zoom.zoom === 1) {
+ $this.setZoomOriginFromEvent({'pageX': event.center.x, 'pageY': event.center.y});
+ }
+ $this.zoomAtPinchStart = $this.fluidbook.zoom.zoom;
$this.pinchZoom(event.scale, false);
- event.preventDefault();
}
- }
- });
- hm.on('pinchend pinchcancel', function (event) {
- if ($this.fluidbook.zoom.enabled) {
- console.log('pinchend');
- $this.pinchZoom(event.scale, true);
- $this.zoomAtPinchStart = $this.fluidbook.zoom.zoom;
- }
- event.preventDefault();
- });
-
- var hmf = new Hammer.Manager(document.getElementById('fluidbook'), options);
- hmf.add(new Hammer.Pan({threshold: 0}));
- hmf.on('panmove', function (event) {
- if ($this.drag(event)) {
- console.log('prevent scroll')
event.preventDefault();
- }
- });
- hmf.on('panend', function (event) {
- var prevent = $this.drag(event, true);
- $this.startX = $this.startY = -1;
- $this.panX = $this.panY = 0;
- if (prevent) {
+ });
+
+ hm.on('pinch', function (event) {
+ if ($this.fluidbook.zoom.enabled) {
+ console.log('pinch');
+ if ($this.zoomAtPinchStart !== 0) {
+ $this.pinchZoom(event.scale, false);
+ event.preventDefault();
+ }
+ }
+ });
+ hm.on('pinchend pinchcancel', function (event) {
+ if ($this.fluidbook.zoom.enabled) {
+ console.log('pinchend');
+ $this.pinchZoom(event.scale, true);
+ $this.zoomAtPinchStart = $this.fluidbook.zoom.zoom;
+ }
event.preventDefault();
- }
- });
+ });
+ }
+
+ if (panEnabled) {
+ var hmf = new Hammer.Manager(document.getElementById('fluidbook'), options);
+ hmf.add(new Hammer.Pan({threshold: 0}));
+ hmf.on('panmove', function (event) {
+ if ($this.drag(event)) {
+ console.log('prevent scroll')
+ event.preventDefault();
+ }
+ });
+ hmf.on('panend', function (event) {
+ var prevent = $this.drag(event, true);
+ $this.startX = $this.startY = -1;
+ $this.panX = $this.panY = 0;
+ if (prevent) {
+ event.preventDefault();
+ }
+ });
+ }
},
pinchZoom: function (s, end) {