Skip to content

Instantly share code, notes, and snippets.

@akoppela
Created April 24, 2011 13:25
Show Gist options
  • Save akoppela/939547 to your computer and use it in GitHub Desktop.
Save akoppela/939547 to your computer and use it in GitHub Desktop.
if(!Browser.ie){
Browser.Features.Touch = (function(){
try {
document.createEvent('TouchEvent').initTouchEvent('touchstart');
return true;
} catch (exception){}
return false;
})();
// Chrome 5 thinks it is touchy!
// Android doesn't have a touch delay and dispatchEvent does not fire the handler
Browser.Features.iOSTouch = (function(){
var name = 'cantouch', // Name does not matter
html = document.html,
hasTouch = false;
var handler = function(){
html.removeEventListener(name, handler, true);
hasTouch = true;
};
try {
html.addEventListener(name, handler, true);
var event = document.createEvent('TouchEvent');
event.initTouchEvent(name);
html.dispatchEvent(event);
return hasTouch;
} catch (exception){}
handler(); // Remove listener
return false;
})();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment