source: branches/2.2/phpgwapi/js/browser/browserDetect.js @ 4532

Revision 4532, 6.1 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1885 - Modificado para funcionar no browsers chrome e safari no modulo Expresso Messenger

  • Property svn:executable set to *
Line 
1(function()
2{               
3        // NAVIGATOR USER AGENT
4        var agt                 = navigator.userAgent.toLowerCase();
5        var appVer              = navigator.appVersion.toLowerCase();
6
7        var is_minor            = parseFloat(appVer);
8        var is_major            = parseInt(is_minor);
9
10        var iePos               = appVer.indexOf('msie');
11
12        if ( iePos != -1 )
13        {
14            is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
15            is_major = parseInt(is_minor);
16        }
17       
18        //Konqueror
19       
20        var is_konq = false;
21        var kqPos   = agt.indexOf('konqueror');
22       
23        if ( kqPos !=-1 )
24        {
25            is_konq  = true;
26            is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
27            is_major = parseInt(is_minor);
28        }
29
30        //Is_Khtml
31        var is_khtml    = (((agt.indexOf('safari')!=-1) && (agt.indexOf('mac')!=-1)) && ( is_konq ));
32
33        //Is_Opera
34        var is_opera    = (agt.indexOf("opera") != -1 );
35
36        //Is_IE
37        var is_ie               = ((iePos!=-1) && (!is_opera) && (!is_khtml));
38
39        // Gecko
40        var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
41        var is_gver  = 0;
42       
43        if (is_gecko)
44            is_gver = navigator.productSub;
45
46        // Moz
47        var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
48                        (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
49                        (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
50                        (is_gecko) && ((navigator.vendor=="")||(navigator.vendor=="Mozilla")));
51
52        var _browser = [
53
54            // Chrome   
55            ['chrome8', ( agt.indexOf('chrome/8') != -1 ) ],
56            ['chrome11', ( agt.indexOf('chrome/11') != -1 ) ],
57
58            // EPIPHANY
59            ['epiphany2', ( agt.indexOf('epiphany/2') != -1 ) ],
60
61            // FIREFOX
62            ['firefox1', ( agt.indexOf('firefox/1') != -1 ) ],
63            ['firefox2', ( agt.indexOf('firefox/2') != -1 ) ],
64            ['firefox3', ( agt.indexOf('firefox/3') != -1 ) ],
65            ['firefox4', ( agt.indexOf('firefox/4') != -1 ) ],
66
67            // ICEWEASEL
68            ['iceweasel3', (agt.indexOf('iceweasel/3') != -1 ) ],
69
70            // IE
71            ['ie3',     (((iePos!=-1) && (!is_opera) && (!is_khtml)) && (is_major < 4 )) ],
72            ['ie4', (((iePos!=-1) && (!is_opera) && (!is_khtml)) && (is_major == 4 )) ],
73            ['ie5', (((iePos!=-1) && (!is_opera) && (!is_khtml)) && (is_major == 5 )) ],
74            ['ie55', (((iePos!=-1) && (!is_opera) && (!is_khtml)) && (agt.indexOf("msie 5.5") !=-1 )) ],
75            ['ie6', (((iePos!=-1) && (!is_opera) && (!is_khtml)) && (is_major == 6 )) ],
76            ['ie7', (((iePos!=-1) && (!is_opera) && (!is_khtml)) && (is_major == 7 )) ],
77            ['ie8', (((iePos!=-1) && (!is_opera) && (!is_khtml)) && (is_major == 8 )) ],
78
79            //IS?
80            ['is_ie', ((iePos!=-1) && (!is_opera) && (!is_khtml)) ],
81            ['is_gecko', is_gecko ],
82            ['is_opera', is_opera ],
83            ['is_khtml', is_khtml ],
84            ['is_moz', is_moz ],
85
86            // OPERA
87            ['is_opera', is_opera],
88            ['opera2', ( agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1) ],
89            ['opera3', ( agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1) ],
90            ['opera4', ( agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1) ],
91            ['opera5', ( agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1) ],
92            ['opera6', ( agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1) ],
93            ['opera7', ( agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1) ],
94            ['opera8', ( agt.indexOf("opera 8") != -1 || agt.indexOf("opera/8") != -1) ],
95            ['opera9', ( agt.indexOf("opera 9") != -1 || agt.indexOf("opera/9") != -1) ],
96
97            // IS SAFARI/KHTML
98            ['safari', ( agt.indexOf('safari') != -1 ) ],
99            ['khtml', is_khtml ]
100        ];
101
102        function isCompatible()
103        {
104            if( arguments.length > 0 )
105            {
106                var _args = arguments;
107
108                for( i = 0; i < _args.length; i++ )
109                {
110                    for( j = 0; j < _browser.length; j++ )
111                    {
112                        if( _args[i].toLowerCase() === _browser[j][0] )
113                        {
114                            if( _browser[j][1] )
115                                return true;
116                        }
117                    }   
118                }
119
120                return false;
121            }
122        }
123
124        function SnifferBrowser()
125        {
126        }
127
128        SnifferBrowser.prototype.isCompatible = isCompatible;
129
130        window.SnifferBrowser = new SnifferBrowser;
131       
132})();
133
134/*  Script utilizado para detectar o browser
135
136        Variaveis Globais no Expresso:
137
138        OS              -> retorna o Sistema Operacional
139        browser -> retorna o nome do Browser
140        version -> retorna a versão do Browser
141        isExplorer -> retorna true se Browser for Internet Explorer
142*/
143        var detect = navigator.userAgent.toLowerCase();
144        var OS,browser,version,total,thestring;
145        var isExplorer = false;
146
147        if (checkIt('konqueror'))
148        {
149                browser = "Konqueror";
150                OS = "Linux";
151        }
152        else if (checkIt('safari')) browser = "Safari"
153        else if (checkIt('omniweb')) browser = "OmniWeb"
154        else if (checkIt('opera')) browser = "Opera"
155        else if (checkIt('webtv')) browser = "WebTV";
156        else if (checkIt('icab')) browser = "iCab";
157        else if (checkIt('msie')) {browser = "Internet Explorer";isExplorer=true;}
158        else if (!checkIt('compatible'))
159        {
160                browser = "Netscape Navigator"
161                version = detect.charAt(8);
162        }
163        else browser = "An unknown browser";
164       
165        if (!version) version = detect.charAt(place + thestring.length);
166       
167        if (!OS)
168        {
169                if (checkIt('linux')) OS = "Linux";
170                else if (checkIt('x11')) OS = "Unix";
171                else if (checkIt('mac')) OS = "Mac"
172                else if (checkIt('win')) OS = "Windows"
173                else OS = "an unknown operating system";
174        }
175       
176        function checkIt(string)
177        {
178                place = detect.indexOf(string) + 1;
179                thestring = string;
180                return place;
181        }
Note: See TracBrowser for help on using the repository browser.