Created
March 19, 2012 14:42
-
-
Save weisjohn/2114726 to your computer and use it in GitHub Desktop.
basic touch/mouse events + munging
This file contains 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
// 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