Skip to content

Instantly share code, notes, and snippets.

@mobz
Created September 11, 2013 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mobz/6522629 to your computer and use it in GitHub Desktop.
Save mobz/6522629 to your computer and use it in GitHub Desktop.
Generating touch events for hammerjs tests
// === 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