Skip to content

Instantly share code, notes, and snippets.

@npostulart
Last active August 19, 2018 21:52
Show Gist options
  • Save npostulart/ad21c3133771a1860074 to your computer and use it in GitHub Desktop.
Save npostulart/ad21c3133771a1860074 to your computer and use it in GitHub Desktop.
Simple Feature Detection Library

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.

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)
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);
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