Last active
August 29, 2015 14:15
-
-
Save tilap/8d0bda50a84b0a0fb8c8 to your computer and use it in GitHub Desktop.
Add a class to <body> depending on the screen touchable capability.
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
/* | |
* 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