[483] | 1 | define(["./has"], function(has){ |
---|
| 2 | // module: |
---|
| 3 | // dojo/sniff |
---|
| 4 | |
---|
| 5 | /*===== |
---|
| 6 | return function(){ |
---|
| 7 | // summary: |
---|
| 8 | // This module sets has() flags based on the current browser. |
---|
| 9 | // It returns the has() function. |
---|
| 10 | }; |
---|
| 11 | =====*/ |
---|
| 12 | |
---|
| 13 | if(has("host-browser")){ |
---|
| 14 | var n = navigator, |
---|
| 15 | dua = n.userAgent, |
---|
| 16 | dav = n.appVersion, |
---|
| 17 | tv = parseFloat(dav); |
---|
| 18 | |
---|
| 19 | has.add("air", dua.indexOf("AdobeAIR") >= 0); |
---|
| 20 | has.add("msapp", parseFloat(dua.split("MSAppHost/")[1]) || undefined); |
---|
| 21 | has.add("khtml", dav.indexOf("Konqueror") >= 0 ? tv : undefined); |
---|
| 22 | has.add("webkit", parseFloat(dua.split("WebKit/")[1]) || undefined); |
---|
| 23 | has.add("chrome", parseFloat(dua.split("Chrome/")[1]) || undefined); |
---|
| 24 | has.add("safari", dav.indexOf("Safari")>=0 && !has("chrome") ? parseFloat(dav.split("Version/")[1]) : undefined); |
---|
| 25 | has.add("mac", dav.indexOf("Macintosh") >= 0); |
---|
| 26 | has.add("quirks", document.compatMode == "BackCompat"); |
---|
| 27 | if(dua.match(/(iPhone|iPod|iPad)/)){ |
---|
| 28 | var p = RegExp.$1.replace(/P/, "p"); |
---|
| 29 | var v = dua.match(/OS ([\d_]+)/) ? RegExp.$1 : "1"; |
---|
| 30 | var os = parseFloat(v.replace(/_/, ".").replace(/_/g, "")); |
---|
| 31 | has.add(p, os); // "iphone", "ipad" or "ipod" |
---|
| 32 | has.add("ios", os); |
---|
| 33 | } |
---|
| 34 | has.add("android", parseFloat(dua.split("Android ")[1]) || undefined); |
---|
| 35 | has.add("bb", (dua.indexOf("BlackBerry") >= 0 || dua.indexOf("BB10") >= 0) && parseFloat(dua.split("Version/")[1]) || undefined); |
---|
| 36 | has.add("trident", parseFloat(dav.split("Trident/")[1]) || undefined); |
---|
| 37 | |
---|
| 38 | has.add("svg", typeof SVGAngle !== "undefined"); |
---|
| 39 | |
---|
| 40 | if(!has("webkit")){ |
---|
| 41 | // Opera |
---|
| 42 | if(dua.indexOf("Opera") >= 0){ |
---|
| 43 | // see http://dev.opera.com/articles/view/opera-ua-string-changes and http://www.useragentstring.com/pages/Opera/ |
---|
| 44 | // 9.8 has both styles; <9.8, 9.9 only old style |
---|
| 45 | has.add("opera", tv >= 9.8 ? parseFloat(dua.split("Version/")[1]) || tv : tv); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | // Mozilla and firefox |
---|
| 49 | if(dua.indexOf("Gecko") >= 0 && !has("khtml") && !has("webkit") && !has("trident")){ |
---|
| 50 | has.add("mozilla", tv); |
---|
| 51 | } |
---|
| 52 | if(has("mozilla")){ |
---|
| 53 | //We really need to get away from this. Consider a sane isGecko approach for the future. |
---|
| 54 | has.add("ff", parseFloat(dua.split("Firefox/")[1] || dua.split("Minefield/")[1]) || undefined); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | // IE |
---|
| 58 | if(document.all && !has("opera")){ |
---|
| 59 | var isIE = parseFloat(dav.split("MSIE ")[1]) || undefined; |
---|
| 60 | |
---|
| 61 | //In cases where the page has an HTTP header or META tag with |
---|
| 62 | //X-UA-Compatible, then it is in emulation mode. |
---|
| 63 | //Make sure isIE reflects the desired version. |
---|
| 64 | //document.documentMode of 5 means quirks mode. |
---|
| 65 | //Only switch the value if documentMode's major version |
---|
| 66 | //is different from isIE's major version. |
---|
| 67 | var mode = document.documentMode; |
---|
| 68 | if(mode && mode != 5 && Math.floor(isIE) != mode){ |
---|
| 69 | isIE = mode; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | has.add("ie", isIE); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | // Wii |
---|
| 76 | has.add("wii", typeof opera != "undefined" && opera.wiiremote); |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | return has; |
---|
| 81 | }); |
---|