Created
December 4, 2012 17:45
-
-
Save alvincrespo/4206761 to your computer and use it in GitHub Desktop.
Touch event detection
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
/** | |
@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