Simple Feature Detection Library to check JS, SVG and Touch support. Replaces no-js class on html element with js, adds no-svg if no support for SVG and touch or no-touch depending on the used device.
Last active
August 19, 2018 21:52
-
-
Save npostulart/ad21c3133771a1860074 to your computer and use it in GitHub Desktop.
Simple Feature Detection Library
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
window.Detection = ((window, document) -> | |
html = document.documentElement | |
# Replace "no-js" class name as JS is active | |
className = html.className.replace "no-js", "js" | |
detectSVG = -> | |
!!document.createElement("svg").getAttributeNS | |
Detection = | |
svg: detectSVG() | |
className += if Detection.svg then " svg" else " no-svg" | |
html.className = className | |
Detection | |
)(window, document) |
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
window.Detection = (function(window, document) { | |
var Detection, className, detectSVG, html; | |
html = document.documentElement; | |
className = html.className.replace("no-js", "js"); | |
detectSVG = function() { | |
return !!document.createElement("svg").getAttributeNS; | |
}; | |
Detection = { | |
svg: detectSVG() | |
}; | |
className += Detection.svg ? " svg" : " no-svg"; | |
html.className = className; | |
return Detection; | |
})(window, document); |
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
window.Detection=function(e,n){var t,s,c,o;return o=n.documentElement,s=o.className.replace("no-js","js"),c=function(){return!!n.createElement("svg").getAttributeNS},t={svg:c()},s+=t.svg?" svg":" no-svg",o.className=s,t}(window,document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment