Created
March 14, 2017 18:04
-
-
Save replete/87ae9e08cd3c38fa5129a365e5969e8e to your computer and use it in GitHub Desktop.
Browser support- alternative to modernizr
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
// Browser support | |
(function (d, h, w, n) { | |
//function hasProperties(properties, tagName) { | |
// var isStyle = !!!tagName; | |
// tagName = tagName || 'div'; | |
// var el = d.createElement(tagName); | |
// for (var prop in properties) { | |
// if ((isStyle ? el.style[properties[prop]] : el[properties[prop]]) !== undefined ) { | |
// return true; | |
// } | |
// } | |
// return false; | |
//} | |
var tests = { | |
'touch' : ('ontouchstart' in w) || w.DocumentTouch && d instanceof DocumentTouch | |
// 'formvalidation' : hasProperties(['checkValidity'],'form'), | |
// 'pushState' : !!history.pushState, | |
}, | |
htmlClasses = h.className, | |
ua = n.userAgent; | |
w.supports = tests; | |
htmlClasses = htmlClasses.replace('no-js','js'); | |
for (var i in tests) { | |
htmlClasses += (tests[i] ? ' ' : ' no-') + i; | |
} | |
IE = false; | |
var browserString = ua.match(/edge/i) | |
? 'edge' | |
: ua.match(/Trident|firefox|chrome|safari/i)[0]; | |
if (browserString === 'Trident') { | |
var version = ua.indexOf('rv: 11.0') > 0 || ua.indexOf('rv:11.0') > 0 | |
? 11 | |
: ua.substr(ua.indexOf('MSIE')+ 5,2).replace('.',''); | |
h.className += ' ie ie' + version; | |
IE = parseInt(version, 10); | |
} else { | |
h.className+=' ' + browserString.toLowerCase(); | |
w[browserString.toUpperCase()] = true; | |
} | |
h.setAttribute('ua', n.userAgent); | |
h.setAttribute('os', n.platform); | |
})(document,document.documentElement,window,navigator); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment