Skip to content

Instantly share code, notes, and snippets.

@weisjohn
Created March 19, 2012 14:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weisjohn/2114726 to your computer and use it in GitHub Desktop.
Save weisjohn/2114726 to your computer and use it in GitHub Desktop.
basic touch/mouse events + munging
// feature detection
isTouch = "ontouchstart" in window;
InputHandler = {
startEventType : isTouch ? "touchstart" : "mousedown",
moveEventType : isTouch ? "touchmove" : "mousemove",
endEventType : isTouch ? "touchend" : "mouseup",
isTouchDevice : isTouch,
// normalize an event object generated by a select
mungeEvent : function(evnt) {
return isTouch ? evnt.originalEvent.touches[0] || evnt.originalEvent.changedTouches[0] : evnt;
}
};
// that allows you to do things like
// handle any mouseup events in the designer area
$(".designer").bind(InputHandler.endEventType, function(evnt) {
var end_evnt = InputHandler.mungeEvent(evnt);
console.log( 'target ' + end_evnt.target);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment