function FluidbookTouch(fluidbook) {
- this.fluidbook = fluidbook;
- this.scale = 1;
+ this.fluidbook = fluidbook;
+ this.scale = 1;
- this.startX = 0;
- this.startY = 0;
- this.offsetX = 0;
- this.offsetY = 0;
+ this.startX = 0;
+ this.startY = 0;
+ this.offsetX = 0;
+ this.offsetY = 0;
- this.triggerOffset = 0.05;
- this.triggered = false;
- this.gesturing = false;
+ this.triggerOffset = 0.05;
+ this.triggered = false;
+ this.gesturing = false;
- this.init();
+ 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());
- },
- reset: function() {
- this.startX = 0;
- this.startY = 0;
- this.offsetX = 0;
- this.offsetY = 0;
- this.triggered = false;
- },
- gesturestart: function(event) {
- if (this.fluidbook.pad.enabled) {
- return false;
- }
- var e = event.originalEvent;
- this.enableUserScale();
- this.gesturing = true;
- return true;
- },
- gesturechange: function(event) {
- if (this.fluidbook.pad.enabled) {
- return false;
- }
- var e = event.originalEvent;
- this.gesturing = true;
- 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');
- }
- 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;
- },
- 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.pad.enabled) {
- this.fluidbook.viewport.maxScale = 1;
- this.fluidbook.viewport.userScalable = false;
- } else {
- this.fluidbook.viewport.maxScale = 3;
- this.fluidbook.viewport.userScalable = true;
- }
- this.fluidbook.viewport.updateViewport();
- }
+ 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());
+ },
+ reset: function () {
+ this.startX = 0;
+ this.startY = 0;
+ this.offsetX = 0;
+ this.offsetY = 0;
+ this.triggered = false;
+ },
+ gesturestart: function (event) {
+ if (this.fluidbook.pad.enabled) {
+ return false;
+ }
+ var e = event.originalEvent;
+ this.enableUserScale();
+ this.gesturing = true;
+ return true;
+ },
+ gesturechange: function (event) {
+ if (this.fluidbook.pad.enabled) {
+ return false;
+ }
+ var e = event.originalEvent;
+ this.gesturing = true;
+ 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');
+ }
+ 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;
+ },
+ 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.pad.enabled) {
+ this.fluidbook.viewport.maxScale = 1;
+ this.fluidbook.viewport.userScalable = false;
+ } else {
+ this.fluidbook.viewport.maxScale = 3;
+ this.fluidbook.viewport.userScalable = true;
+ }
+ this.fluidbook.viewport.updateViewport();
+ }
};