]> _ Git - fluidbook-html5.git/commitdiff
wait #2636 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 25 Mar 2019 12:55:23 +0000 (13:55 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 25 Mar 2019 12:55:23 +0000 (13:55 +0100)
js/libs/fluidbook/fluidbook.input.js

index f47571e27febce6cfe78e0e40e17f6ddf26ff996..0c4145d1cc8ece3d1811031a86c193994314b8a2 100644 (file)
@@ -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