Created
January 12, 2012 16:10
-
-
Save ttrenka/1601352 to your computer and use it in GitHub Desktop.
Example of dojo/sniff
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
define(["./has"], function(has){ | |
if(!has("host-browser")){ | |
return {}; | |
} | |
var hasAdd = has.add, | |
n = navigator, | |
dua = n.userAgent, | |
dav = n.appVersion, | |
tv = parseFloat(dav), | |
isOpera, | |
isAIR, | |
isKhtml, | |
isWebKit, | |
isChrome, | |
isMac, | |
isSafari, | |
isMozilla , | |
isMoz, | |
isIE, | |
isFF, | |
isQuirks, | |
isIos, | |
isAndroid, | |
isWii; | |
// fill in the rendering support information in dojo.render.* | |
if(dua.indexOf("AdobeAIR") >= 0){ isAIR = 1; } | |
isKhtml = (dav.indexOf("Konqueror") >= 0) ? tv : 0; | |
isWebKit = parseFloat(dua.split("WebKit/")[1]) || undefined; | |
isChrome = parseFloat(dua.split("Chrome/")[1]) || undefined; | |
isMac = dav.indexOf("Macintosh") >= 0; | |
isIos = /iPhone|iPod|iPad/.test(dua); | |
isAndroid = parseFloat(dua.split("Android ")[1]) || undefined; | |
isWii = typeof opera != "undefined" && opera.wiiremote; | |
// safari detection derived from: | |
// http://developer.apple.com/internet/safari/faq.html#anchor2 | |
// http://developer.apple.com/internet/safari/uamatrix.html | |
var index = Math.max(dav.indexOf("WebKit"), dav.indexOf("Safari"), 0); | |
if(index && !isChrome){ | |
// try to grab the explicit Safari version first. If we don't get | |
// one, look for less than 419.3 as the indication that we're on something | |
// "Safari 2-ish". | |
isSafari = parseFloat(dav.split("Version/")[1]); | |
if(!isSafari || parseFloat(dav.substr(index + 7)) <= 419.3){ | |
isSafari = 2; | |
} | |
} | |
if (!has("dojo-webkit")) { | |
if(dua.indexOf("Opera") >= 0){ | |
isOpera = tv; | |
// see http://dev.opera.com/articles/view/opera-ua-string-changes and http://www.useragentstring.com/pages/Opera/ | |
// 9.8 has both styles; <9.8, 9.9 only old style | |
if(isOpera >= 9.8){ | |
isOpera = parseFloat(dua.split("Version/")[1]) || tv; | |
} | |
} | |
if(dua.indexOf("Gecko") >= 0 && !isKhtml && !isWebKit){ | |
isMozilla = isMoz = tv; | |
} | |
if(isMoz){ | |
//We really need to get away from this. Consider a sane isGecko approach for the future. | |
isFF = parseFloat(dua.split("Firefox/")[1] || dua.split("Minefield/")[1]) || undefined; | |
} | |
if(document.all && !isOpera){ | |
isIE = parseFloat(dav.split("MSIE ")[1]) || undefined; | |
//In cases where the page has an HTTP header or META tag with | |
//X-UA-Compatible, then it is in emulation mode. | |
//Make sure isIE reflects the desired version. | |
//document.documentMode of 5 means quirks mode. | |
//Only switch the value if documentMode's major version | |
//is different from isIE's major version. | |
var mode = document.documentMode; | |
if(mode && mode != 5 && Math.floor(isIE) != mode){ | |
isIE = mode; | |
} | |
} | |
} | |
isQuirks = document.compatMode == "BackCompat"; | |
hasAdd("opera", isOpera); | |
hasAdd("air", isAIR); | |
hasAdd("khtml", isKhtml); | |
hasAdd("webkit", isWebKit); | |
hasAdd("chrome", isChrome); | |
hasAdd("mac", isMac ); | |
hasAdd("safari", isSafari); | |
hasAdd("mozilla", isMozilla ); | |
hasAdd("ie", isIE ); | |
hasAdd("ff", isFF); | |
hasAdd("quirks", isQuirks); | |
hasAdd("ios", isIos); | |
hasAdd("android", isAndroid); | |
return { | |
browser: true, | |
opera: isOpera, | |
AIR: isAIR, | |
khtml: isKhtml, | |
webkit: isWebKit, | |
chrome: isChrome, | |
mac: isMac, | |
safari: isSafari, | |
mozilla: isMozilla, | |
ie: isIE, | |
ff: isFF, | |
quirks: isQuirks, | |
ios: isIos, | |
android: isAndroid, | |
locale: (isIE ? n.userLanguage : n.language).toLowerCase() | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment