jquery-idlecat icon indicating copy to clipboard operation
jquery-idlecat copied to clipboard

Touch activity for mobile browsers

Open rhiller opened this issue 7 years ago • 4 comments

Nice work! I forked it and added touchstart detection for mobile browsers.

rhiller avatar Oct 16 '18 18:10 rhiller

Hi there... I wanted to detect touchstart too... @rhiller could you kindly tell me which lines you modify to make it work on cellphones?

Thanks... Stay safe

inglesuniversal avatar Apr 27 '20 01:04 inglesuniversal

Wow, I completely forgot about that! My (minor) changes in https://github.com/rhiller/jquery-idlecat

--- a/src/jquery.idleCat.js
+++ b/src/jquery.idleCat.js
@@ -131,7 +131,16 @@
                jqDocument.one("mousemove", function (event) {
                        mouseX = event.pageX;
                        mouseY = event.pageY;
+                       // console.log("mouse x: " + mouseX + " y: " + mouseY);
                });
+
+               jqDocument.one("touchstart", function (event) {
+                       var touchobj = event.originalEvent.changedTouches[0];
+                       mouseX = parseInt(touchobj.pageX);
+                       mouseY = parseInt(touchobj.pageY);
+                       // console.log("touch x: " + mouseX + " y: " + mouseY);
+               });
+

                //console.log(mouseX, mouseY);
                var movement = (mouseX != oldMouseX) || (mouseY != oldMouseY);

rhiller avatar Apr 27 '20 02:04 rhiller

Worked like a charm!!! Thanks so much!!!

inglesuniversal avatar Apr 27 '20 04:04 inglesuniversal

Now, my dear friend... I would like to share the keyboard detection snippet... which I just figured out... Thanks so much!

jqDocument.one("keypress", function (event) { mouseX = event.which; mouseY = event.which; console.log("key pressed: " + mouseX); });

inglesuniversal avatar Apr 27 '20 04:04 inglesuniversal