Created
July 25, 2013 20:28
-
-
Save cacheleocode/6083439 to your computer and use it in GitHub Desktop.
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
| //this code converts touch events to mouse events | |
| function touchHandler(event) { | |
| var touches = event.changedTouches, | |
| first = touches[0], | |
| type = ""; | |
| switch (event.type) { | |
| case "touchstart": type = "mousedown"; break; | |
| case "touchmove": type = "mousemove"; break; | |
| case "touchend": type = "mouseup"; break; | |
| default: return; | |
| } | |
| var simulatedEvent = document.createEvent("MouseEvent"); | |
| simulatedEvent.initMouseEvent(type, true, true, window, 1, | |
| first.screenX, first.screenY, | |
| first.clientX, first.clientY, false, | |
| false, false, false, 0/*left*/, null); | |
| first.target.dispatchEvent(simulatedEvent); | |
| event.preventDefault(); | |
| } | |
| //this code stops the I-beam appearing when dragging elements - it also prevents text selection | |
| window.addEventListener("dragstart", function(fEventObject){ CancelEvent(fEventObject); } ); | |
| window.addEventListener("selectstart", function(fEventObject){ CancelEvent(fEventObject); } ); | |
| function CancelEvent(fEventObject) | |
| { | |
| if (fEventObject.preventDefault) fEventObject.preventDefault(); | |
| if (fEventObject.cancel != null) fEventObject.cancel = true; | |
| }/**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment