forked from dojo/dojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sniff.js
88 lines (78 loc) · 3.31 KB
/
sniff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
define(["./has"], function(has){
// module:
// dojo/sniff
/*=====
return function(){
// summary:
// This module sets has() flags based on the current browser.
// It returns the has() function.
};
=====*/
if(has("host-browser")){
var n = navigator,
dua = n.userAgent,
dav = n.appVersion,
tv = parseFloat(dav);
has.add("air", dua.indexOf("AdobeAIR") >= 0);
has.add("wp", parseFloat(dua.split("Windows Phone")[1]) || undefined);
has.add("msapp", parseFloat(dua.split("MSAppHost/")[1]) || undefined);
has.add("khtml", dav.indexOf("Konqueror") >= 0 ? tv : undefined);
has.add("webkit", !has("wp") // NOTE: necessary since Windows Phone 8.1 Update 1, see #18540
&& parseFloat(dua.split("WebKit/")[1]) || undefined);
has.add("chrome", parseFloat(dua.split("Chrome/")[1]) || undefined);
has.add("android", !has("wp") // NOTE: necessary since Windows Phone 8.1 Update 1, see #18528
&& parseFloat(dua.split("Android ")[1]) || undefined);
has.add("safari", dav.indexOf("Safari") >= 0
&& !has("wp") // NOTE: necessary since Windows Phone 8.1 Update 1, see #18540
&& !has("chrome") && !has("android") ?
parseFloat(dav.split("Version/")[1]) : undefined);
has.add("mac", dav.indexOf("Macintosh") >= 0);
has.add("quirks", document.compatMode == "BackCompat");
if(!has("wp") // NOTE: necessary since Windows Phone 8.1 Update 1, see #18528
&& dua.match(/(iPhone|iPod|iPad)/)){
var p = RegExp.$1.replace(/P/, "p");
var v = dua.match(/OS ([\d_]+)/) ? RegExp.$1 : "1";
var os = parseFloat(v.replace(/_/, ".").replace(/_/g, ""));
has.add(p, os); // "iphone", "ipad" or "ipod"
has.add("ios", os);
}
has.add("bb", (dua.indexOf("BlackBerry") >= 0 || dua.indexOf("BB10") >= 0) && parseFloat(dua.split("Version/")[1]) || undefined);
has.add("trident", parseFloat(dav.split("Trident/")[1]) || undefined);
has.add("svg", typeof SVGAngle !== "undefined");
if(!has("webkit")){
// Opera
if(dua.indexOf("Opera") >= 0){
// 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
has.add("opera", tv >= 9.8 ? parseFloat(dua.split("Version/")[1]) || tv : tv);
}
// Mozilla and firefox
if(dua.indexOf("Gecko") >= 0 && !has("wp") // NOTE: necessary since Windows Phone 8.1 Update 1
&& !has("khtml") && !has("webkit") && !has("trident")){
has.add("mozilla", tv);
}
if(has("mozilla")){
//We really need to get away from this. Consider a sane isGecko approach for the future.
has.add("ff", parseFloat(dua.split("Firefox/")[1] || dua.split("Minefield/")[1]) || undefined);
}
// IE
if(document.all && !has("opera")){
var 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;
}
has.add("ie", isIE);
}
// Wii
has.add("wii", typeof opera != "undefined" && opera.wiiremote);
}
}
return has;
});