Retrait de navigateurs obsolètes. Ajout Chrome.
[Epoz.git] / Products / Epoz / epoz / epoz_core / epoz_script_detect.js.dtml
1 // Browser Detect v2.1.6
2 // license: http://creativecommons.org/licenses/by/1.0/
3 // code by Chris Nott (chris[at]dithered[dot]com)
4 // updated by Benoît Pin
5
6 var browser;
7 (function() {
8 function BrowserDetect() {
9 var ua = navigator.userAgent.toLowerCase();
10
11 // browser engine name
12 this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);
13 this.isTrident = (ua.indexOf('trident') != -1);
14 this.isGecko = (!this.isTrident && (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1));
15
16 // browser name
17 this.isKonqueror = (ua.indexOf('konqueror') != -1);
18 this.isSafari = (ua.indexOf('safari') != - 1);
19 this.isOmniweb = (ua.indexOf('omniweb') != - 1);
20 this.isOpera = (ua.indexOf('opera') != -1);
21 this.isIE = (this.isTrident || ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) );
22 this.isMozilla = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
23 this.isFirebird = (ua.indexOf('firebird/') != -1);
24 this.isFirefox = (ua.indexOf('firefox/') != -1);
25 this.isChrome = (ua.indexOf('chrome/') != -1);
26
27 // rendering engine versions
28 this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
29 this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
30 this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
31
32 // browser version
33 this.versionMinor = parseFloat(navigator.appVersion);
34
35 // correct version number
36 if (this.isGecko && !this.isMozilla)
37 this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
38 else if (this.isMozilla)
39 this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
40 else if (this.isIE && this.versionMinor >= 4) {
41 if (ua.indexOf('msie') != -1)
42 this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
43 else if (this.isTrident)
44 this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
45 }
46 else if (this.isKonqueror)
47 this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
48 else if (this.isSafari)
49 this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
50 else if (this.isOpera)
51 this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
52 else if(this.isChrome)
53 this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('chrome/') + 7 ) );
54
55 this.versionMajor = parseInt(this.versionMinor);
56
57 // dom support
58 this.isDOM1 = (document.getElementById);
59 this.isDOM2Event = (document.addEventListener && document.removeEventListener);
60
61 // css compatibility mode
62 this.mode = document.compatMode ? document.compatMode : 'BackCompat';
63
64 // platform
65 this.isWin = (ua.indexOf('win') != -1);
66 this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
67 this.isMac = (ua.indexOf('mac') != -1);
68 this.isUnix = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1);
69 this.isLinux = (ua.indexOf('linux') != -1);
70 this.isMobile = (ua.indexOf('mobile') != -1);
71
72 // specific browser shortcuts
73 this.isIE6x = (this.isIE && this.versionMajor == 6);
74 this.isIE6up = (this.isIE && this.versionMajor >= 6);
75 this.isIE7max = (this.isIE && this.versionMajor <= 7);
76 this.isIE8max = (this.isIE && this.versionMajor <= 8);
77 this.isIE10 = (this.isIE && this.versionMajor == 10);
78 this.isIE10max = (this.isIE && this.versionMajor <= 10);
79 this.isIE11 = (this.isIE && this.versionMajor == 11);
80
81 }
82 browser = new BrowserDetect();
83 }());