Created
February 11, 2013 23:15
-
-
Save nmcv/4758518 to your computer and use it in GitHub Desktop.
Determine input (interaction) method in IE10. Has to fire an event first.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Globals = {}; | |
| function handleIE10TouchEvent(event) | |
| // Determines which input method is available | |
| // in IE10 - mouse, pen or a touch cap. device | |
| { | |
| switch (event.pointerType) | |
| // Refactor to if-then-else for a faster | |
| // and more compatible solution | |
| { | |
| case event.MSPOINTER_TYPE_TOUCH: | |
| Globals.ie10_hasTouch = true; | |
| break; | |
| case event.MSPOINTER_TYPE_PEN: | |
| Globals.ie10_hasPen = true; | |
| break; | |
| case event.MSPOINTER_TYPE_MOUSE: | |
| Globals.ie10_hasMouse = true; | |
| break; | |
| } | |
| } | |
| function readyDocument() | |
| // Handler for window.onload | |
| { | |
| // Event listener args | |
| var args = | |
| [ | |
| 'MSPointerMove', // That magic event of IE10 | |
| handleIE10TouchEvent, // Handler | |
| false // Phase | |
| ]; | |
| // Set IE10 input event listener | |
| document | |
| .addEventListener | |
| .apply(document, args); | |
| } | |
| // Do something when document is ready | |
| window.onload = readyDocument; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment