Created
September 11, 2013 12:02
-
-
Save mobz/6522629 to your computer and use it in GitHub Desktop.
Generating touch events for hammerjs tests
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
// === Generated Events === // | |
function customEvent( el, type ) { | |
var evt = document.createEvent("UIEvent"); | |
evt.initUIEvent( type , true, true ); | |
evt.touches = [ {} ]; | |
el.dispatchEvent( evt ); | |
} | |
function mouseEvent( el, type ) { | |
var evt = document.createEvent("MouseEvents"); | |
evt.initMouseEvent( type, true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null ); | |
el.dispatchEvent( evt ); | |
} | |
function pointerClick( el ) { | |
if ( 'ontouchstart' in window ) { | |
customEvent( el, "touchstart" ); | |
customEvent( el, "touchend" ); | |
} else { | |
mouseEvent( el, "mousedown" ); | |
mouseEvent( el, "mouseup" ); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment