Skip to content

Instantly share code, notes, and snippets.

@alvincrespo
Created December 4, 2012 17:45
Show Gist options
  • Save alvincrespo/4206761 to your computer and use it in GitHub Desktop.
Save alvincrespo/4206761 to your computer and use it in GitHub Desktop.
Touch event detection
/**
@class
@description Checks for touch events and returns the appropriate supported touchevent
*/
(function(){
var TouchEvent = (function() {
// Mapping of Events, for easier reference
var events = {
'START': 'ontouchstart',
'MOVE': 'ontouchmove',
'END': 'ontouchend'
};
// Run through all events
for (var evt in events) {
var currEvt;
// Check if the event is a property
if (events.hasOwnProperty(evt)) {
// Cache the current event
currEvt = events[evt];
// If the event doesn't exist, just return false
if (!(currEvt in window)) {
return false;
}
// We need the actual event we can listen to later on
events[evt] = currEvt.substr(2, currEvt.length);
}
}
return events;
}());
window.TouchEvent = TouchEvent;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment