From 029b31e988a905347af116c496a36b4ad4f3c7fc Mon Sep 17 00:00:00 2001 From: hashchange Date: Fri, 3 Mar 2017 01:09:59 +0100 Subject: [PATCH 1/5] Add .idea directory to ignored files --- .gitignore | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index da23d0d..106ffc1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,25 +1,26 @@ -# Logs -logs -*.log - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directory -# Deployed apps should consider commenting this line out: -# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git -node_modules +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Deployed apps should consider commenting this line out: +# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git +node_modules +.idea/ From ca8b3a11805e7bb0dcf9b980dce7605f0a988262 Mon Sep 17 00:00:00 2001 From: hashchange Date: Fri, 3 Mar 2017 11:18:59 +0100 Subject: [PATCH 2/5] Change tests to new API, using .start() --- tests/manual/events.html | 4 ++-- tests/manual/googlemaps.html | 2 +- tests/manual/hammer.html | 2 +- tests/manual/img.html | 2 +- tests/manual/leaflet.html | 2 +- tests/manual/modernizr.html | 2 +- .../touch-events/create-touch-touchlist.html | 2 +- .../touch-events/multi-touch-interactions-manual.html | 2 +- .../touch-events/multi-touch-interfaces-manual.html | 2 +- .../web-platform-tests/touch-events/single-touch-manual.html | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/manual/events.html b/tests/manual/events.html index a8ba17a..cf51970 100644 --- a/tests/manual/events.html +++ b/tests/manual/events.html @@ -5,12 +5,12 @@ - +
- Check the console. No mouseevents should be fired, only touchevents. Click events are allowed. + Check the console. No mouse events should be fired, only touch events. Click events are allowed.
- + - + diff --git a/tests/manual/img.html b/tests/manual/img.html index f7b2bba..510a3a6 100644 --- a/tests/manual/img.html +++ b/tests/manual/img.html @@ -5,7 +5,7 @@ - + no dragging of images;
diff --git a/tests/manual/leaflet.html b/tests/manual/leaflet.html index 9f4de80..5bccf35 100644 --- a/tests/manual/leaflet.html +++ b/tests/manual/leaflet.html @@ -6,7 +6,7 @@ - + diff --git a/tests/manual/modernizr.html b/tests/manual/modernizr.html index 683566a..2826e07 100644 --- a/tests/manual/modernizr.html +++ b/tests/manual/modernizr.html @@ -8,7 +8,7 @@

Can we trick Modernizr?

- + - + diff --git a/tests/web-platform-tests/touch-events/multi-touch-interactions-manual.html b/tests/web-platform-tests/touch-events/multi-touch-interactions-manual.html index f339c53..b3377ec 100644 --- a/tests/web-platform-tests/touch-events/multi-touch-interactions-manual.html +++ b/tests/web-platform-tests/touch-events/multi-touch-interactions-manual.html @@ -19,7 +19,7 @@ - + diff --git a/tests/web-platform-tests/touch-events/multi-touch-interfaces-manual.html b/tests/web-platform-tests/touch-events/multi-touch-interfaces-manual.html index da6f2ac..ec4f1dd 100644 --- a/tests/web-platform-tests/touch-events/multi-touch-interfaces-manual.html +++ b/tests/web-platform-tests/touch-events/multi-touch-interfaces-manual.html @@ -20,7 +20,7 @@ - + - + + + + + +
+ Check the console. No mouse events should be fired, only touch events. Click events are allowed. +
+ + + + diff --git a/tests/manual/events-stopped.html b/tests/manual/events-stopped.html new file mode 100644 index 0000000..11b8b46 --- /dev/null +++ b/tests/manual/events-stopped.html @@ -0,0 +1,36 @@ + + + + + + + + + + + +
+ Check the console. No touch events should be fired, only mouse events. Click events are allowed, too. +
+ + + + From 2e8469fd21be00538de042d21f6566235d2710e3 Mon Sep 17 00:00:00 2001 From: hashchange Date: Fri, 3 Mar 2017 11:36:03 +0100 Subject: [PATCH 4/5] Add ability to stop and restart the emulator Fixes #11 --- touch-emulator.js | 74 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 13 deletions(-) diff --git a/touch-emulator.js b/touch-emulator.js index 6d8b2dd..2bcda06 100644 --- a/touch-emulator.js +++ b/touch-emulator.js @@ -1,10 +1,13 @@ (function(window, document, exportName, undefined) { "use strict"; + var isRunning = false; var isMultiTouch = false; var multiTouchStartPos; var eventTarget; var touchElements = {}; + var fakedProps = []; + var handlers = []; // polyfills if(!document.createTouch) { @@ -94,11 +97,23 @@ for(var p=0; p Date: Fri, 3 Mar 2017 11:38:11 +0100 Subject: [PATCH 5/5] Update readme Also covers #9 --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 595fdd3..5d1b571 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,12 @@ npm install hammer-touchemulator ``` ## How to use -Include the javascript file, and call the `Emulator()` function before any other libraries that do something with the +Include the javascript file, and call `TouchEmulator.start()` before any other libraries that do something with the touch input. It will set some fake properties to spoof the touch detection of some libraries, and triggers `touchstart`, `touchmove` and `touchend` events on the mouse target. ````html - + ```` ````js @@ -42,6 +42,9 @@ document.body.addEventListener('touchend', log, false); Also, the script includes polyfills for `document.createTouch` and `document.createTouchList`. +You can stop the touch emulator with `TouchEmulator.stop()` and restart it with another call to `TouchEmulator.start()`. +In previous versions, the emulator was started by calling `TouchEmulator()`; that continues to work, too. + ## How it works It listens to the `mousedown`, `mousemove` and `mouseup` events, and translates them to touch events. If the mouseevent has the `shiftKey` property to `true`, it enables multi-touch.