Skip to content

Instantly share code, notes, and snippets.

@13twelve
Created October 26, 2016 16:29
Show Gist options
  • Save 13twelve/fc9c96390c868e074e089c013bc4397c to your computer and use it in GitHub Desktop.
Save 13twelve/fc9c96390c868e074e089c013bc4397c to your computer and use it in GitHub Desktop.
head.js - to be inlined in the head of a document
// set up a master object
var A17 = window.A17 || {},
d = document,
de = d.documentElement,
w = window;
// test for HTML5 vs HTML4 support, cutting the mustard. Caution: IE9 will pass this..
A17.browserSpec = (typeof d.querySelectorAll && 'addEventListener' in w && A17.svgSupport) ? 'html5' : 'html4 ';
// test for SVG support
A17.svgSupport = d.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#BasicStructure', '1.1');
// test for touch support. Caution: this is dangerous: https://hacks.mozilla.org/2013/04/detecting-touch-its-the-why-not-the-how/
A17.touch = (('ontouchstart' in w) || w.documentTouch && d instanceof DocumentTouch) ? true : false;
// testing for object fit support
A17.objectFit = ('objectFit' in de.style);
// test for form placeholders supported (show labels if not)
A17.placeholder = (d.createElement('input').placeholder !== undefined);
// test for iOS devices
A17.ios = /iphone|ipod|ipad/.test(w.navigator.userAgent.toLowerCase());
// go go
(function(d,de,lb) {
de.className = de.className.replace(/\bno-js\b/,' js '+A17.browserSpec+(A17.touch ? ' touch' : ' no-touch')+(A17.svgSupport ? ' svg' : ' no-svg')+(A17.objectFit ? ' objectFit' : ' no-objectFit')+(A17.placeholder ? ' placeholder' : ' no-placeholder')+(A17.ios ? ' ios' : ' no-ios'));
})(d,de);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment