dojo/sniff.js

Maintainability

42.42

Lines of code

88

Created with Raphaël 2.1.002550751002015-1-52014-12-42014-12-3

2015-5-18
Maintainability: 42.42

Created with Raphaël 2.1.0022.54567.5902015-1-52014-12-42014-12-3

2015-5-18
Lines of Code: 88

Difficulty

25.89

Estimated Errors

1.10

Function weight

By Complexity

Created with Raphaël 2.1.0<anonymous>25

By SLOC

Created with Raphaël 2.1.0<anonymous>88
define(["./has"], function(has){
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
        has.add("air", dua.indexOf("AdobeAIR") >= 0);
19
        has.add("wp", parseFloat(dua.split("Windows Phone")[1]) || undefined);
20
        has.add("msapp", parseFloat(dua.split("MSAppHost/")[1]) || undefined);
21
        has.add("khtml", dav.indexOf("Konqueror") >= 0 ? tv : undefined);
22
        has.add("webkit", !has("wp") // NOTE: necessary since Windows Phone 8.1 Update 1, see #18540
23
                && parseFloat(dua.split("WebKit/")[1]) || undefined);
Column: 17 "Bad line breaking before '&&'."
24
        has.add("chrome", parseFloat(dua.split("Chrome/")[1]) || undefined);
25
        has.add("android", !has("wp") // NOTE: necessary since Windows Phone 8.1 Update 1, see #18528
26
                && parseFloat(dua.split("Android ")[1]) || undefined);
Column: 17 "Bad line breaking before '&&'."
27
        has.add("safari", dav.indexOf("Safari") >= 0 
28
                && !has("wp") // NOTE: necessary since Windows Phone 8.1 Update 1, see #18540
Column: 17 "Bad line breaking before '&&'."
29
                && !has("chrome") && !has("android") ?
Column: 17 "Bad line breaking before '&&'."
30
            parseFloat(dav.split("Version/")[1]) : undefined);
31
        has.add("mac", dav.indexOf("Macintosh") >= 0);
32
        has.add("quirks", document.compatMode == "BackCompat");
33
        if(!has("wp") // NOTE: necessary since Windows Phone 8.1 Update 1, see #18528
34
                && dua.match(/(iPhone|iPod|iPad)/)){
Column: 17 "Bad line breaking before '&&'."
35
            var p = RegExp.$1.replace(/P/, "p");
36
            var v = dua.match(/OS ([\d_]+)/) ? RegExp.$1 : "1";
37
            var os = parseFloat(v.replace(/_/, ".").replace(/_/g, ""));
38
            has.add(p, os);     // "iphone", "ipad" or "ipod"
39
            has.add("ios", os);
40
        }
41
        has.add("bb", (dua.indexOf("BlackBerry") >= 0 || dua.indexOf("BB10") >= 0) && parseFloat(dua.split("Version/")[1]) || undefined);
42
        has.add("trident", parseFloat(dav.split("Trident/")[1]) || undefined);
43
 
44
        has.add("svg", typeof SVGAngle !== "undefined");
45
 
46
        if(!has("webkit")){
47
            // Opera
48
            if(dua.indexOf("Opera") >= 0){
49
                // see http://dev.opera.com/articles/view/opera-ua-string-changes and http://www.useragentstring.com/pages/Opera/
50
                // 9.8 has both styles; <9.8, 9.9 only old style
51
                has.add("opera", tv >= 9.8 ? parseFloat(dua.split("Version/")[1]) || tv : tv);
52
            }
53
 
54
            // Mozilla and firefox
55
            if(dua.indexOf("Gecko") >= 0 && !has("wp") // NOTE: necessary since Windows Phone 8.1 Update 1
56
                    && !has("khtml") && !has("webkit") && !has("trident")){
Column: 21 "Bad line breaking before '&&'."
57
                has.add("mozilla", tv);
58
            }
59
            if(has("mozilla")){
60
                //We really need to get away from this. Consider a sane isGecko approach for the future.
61
                has.add("ff", parseFloat(dua.split("Firefox/")[1] || dua.split("Minefield/")[1]) || undefined);
62
            }
63
 
64
            // IE
65
            if(document.all && !has("opera")){
66
                var isIE = parseFloat(dav.split("MSIE ")[1]) || undefined;
67
 
68
                //In cases where the page has an HTTP header or META tag with
69
                //X-UA-Compatible, then it is in emulation mode.
70
                //Make sure isIE reflects the desired version.
71
                //document.documentMode of 5 means quirks mode.
72
                //Only switch the value if documentMode's major version
73
                //is different from isIE's major version.
74
                var mode = document.documentMode;
75
                if(mode && mode != 5 && Math.floor(isIE) != mode){
76
                    isIE = mode;
77
                }
78
 
79
                has.add("ie", isIE);
80
            }
81
 
82
            // Wii
83
            has.add("wii", typeof opera != "undefined" && opera.wiiremote);
84
        }
85
    }
86
 
87
    return has;
88
});