From bebfea73f68d448e71b6c1e6a77ed4e957e3bb9b Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 25 Mar 2019 13:55:23 +0100 Subject: [PATCH] wait #2636 @1 --- js/libs/fluidbook/fluidbook.input.js | 45 +++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.input.js b/js/libs/fluidbook/fluidbook.input.js index f47571e2..0c4145d1 100644 --- a/js/libs/fluidbook/fluidbook.input.js +++ b/js/libs/fluidbook/fluidbook.input.js @@ -11,32 +11,69 @@ function FluidbookInput(fluidbook) { FluidbookInput.prototype = { init: function () { + var $this = this; if (Modernizr.ftouch) { this.hasTouch = true; } else { this.usingMouse = this.hasMouse = this.forceMouse = true; this.usingTouch = this.hasTouch = this.forceTouch = false; + this.setMouseClasses(); return; } if (Modernizr.iOS || Modernizr.android) { this.usingTouch = this.hasTouch = this.forceTouch = true; this.usingMouse = this.hasMouse = this.forceMouse = false; + this.setTouchClasses(); return; } this.forceTouch = this.forceMouse = false; $(document).on('mousemove', function () { - this.hasMouse = this.usingMouse = true; - this.usingTouch = false; + $this.useMouse(); return true; }); $(document).on('touchstart touchmove touchend', function () { - this.hasTouch = this.usingTouch = true; - this.usingMouse = false; + $this.useTouch(); return true; }); }, + + isUsingTouch: function () { + return this.usingTouch; + }, + + isUsingMouse: function () { + return this.usingMouse; + }, + + useTouch: function () { + if (!this.usingTouch) { + this.hasTouch = this.usingTouch = true; + this.usingMouse = false; + this.setTouchClasses(); + } + }, + useMouse: function () { + if (!this.usingMouse) { + this.hasMouse = this.usingMouse = true; + this.usingTouch = false; + this.setMouseClasses(); + } + }, + + setTouchClasses: function () { + $('html').removeClass('using-mouse') + .removeClass('no-using-touch') + .addClass('no-using-mouse') + .addClass('using-touch'); + }, + setMouseClasses: function () { + $('html').addClass('using-mouse') + .addClass('no-using-touch') + .removeClass('no-using-mouse') + .removeClass('using-touch'); + } }; \ No newline at end of file -- 2.39.5