Skip to content

Instantly share code, notes, and snippets.

@tilap
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tilap/8d0bda50a84b0a0fb8c8 to your computer and use it in GitHub Desktop.
Save tilap/8d0bda50a84b0a0fb8c8 to your computer and use it in GitHub Desktop.
Add a class to <body> depending on the screen touchable capability.
/*
* Add a class to <body> depending on the screen touchable capability
* Usage: require('script')();
*/
/* global document, window, navigator */
module.exports = function() {
var notTouchableClassname = 'not-touchable',
touchableClassname= 'touchable',
isTouch = false;
try {
isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));
} catch (e) {
isTouch=false;
}
document.getElementsByTagName('body')[0].className+= ' ' + (isTouch ? touchableClassname : notTouchableClassname);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment