-
-
Save maddesigns/7385008 to your computer and use it in GitHub Desktop.
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
env = (function() { | |
var flags = {}, ua = navigator.userAgent, el = document.createElement('div'), video = document.createElement('video'), audio = document.createElement('audio'), root = document.documentElement, i | |
function flag(names) { | |
names = names.split(' ') | |
for (i = 0; i < names.length; i++) | |
flags[names[i]] = true | |
} | |
function classnames() { | |
var names = [], name | |
for(name in flags) if (flags.hasOwnProperty(name)) | |
names.push(name) | |
root.className += (root.className ? ' ' : '') + names.join(' ') | |
} | |
if (ua.indexOf('WebKit/') > -1) flag('webkit') | |
if (ua.indexOf('MSIE ') > -1) flag('msie') | |
if (flags.msie) | |
if (parseInt(ua.substr(ua.indexOf('MSIE ') + 5, 2), 10) < 9) flag('msielt9') | |
if (ua.indexOf('Firefox') > -1) flag('firefox') | |
if (ua.indexOf('(iPad') > -1) flag('ios ipad') | |
if (ua.indexOf('(iPhone') > -1 || ua.indexOf('(iPod') > -1) flag('ios iphone') | |
if (flags.ios && ua.indexOf('Version/7.') > -1) flag('ios7') | |
if (ua.indexOf('Chrome/') > -1) flag('chrome') | |
if (!flags.chrome && ua.indexOf('Safari/')) flag('safari') | |
if (ua.indexOf('Android ') > -1) flag('android') | |
if (!flags.ios && !flags.android) flag('desktop') | |
el.setAttribute('ontouchstart', 'return;') | |
if (typeof el.ontouchstart === 'function') flag('touch') | |
if (navigator.msPointerEnabled && navigator.msMaxTouchPoints > 1) flag('touch') | |
if (navigator.standalone) flag('standalone') | |
if (devicePixelRatio >= 2) flag('retina') | |
if (window != window.top) flag('embedded') | |
if (document.documentElement.webkitRequestFullscreen || document.fullscreenEnabled || document.mozFullScreenEnabled) flag('fullscreen') | |
if (!!(video.canPlayType && video.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, ''))) flag('can_play_h264') | |
if (!!(audio.canPlayType && audio.canPlayType('audio/mpeg;').replace(/no/, ''))) flag('can_play_mp3') | |
if (screen.width > 1280) flag('hd') | |
if (screen.width < 768) flag('narrow') | |
classnames() | |
return flags | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment