OLD | NEW |
| (Empty) |
1 /* Do not copy this file. Instead, do something like this in your | |
2 own code. | |
3 | |
4 if (!window.WebGLRenderingContext) { | |
5 // Browser has no idea what WebGL is. Suggest they | |
6 // get a new browser by presenting the user with link to | |
7 // http://get.webgl.org | |
8 return; | |
9 } | |
10 | |
11 gl = canvas.getContext("webgl"); | |
12 if (!gl) { | |
13 // Browser could not initialize WebGL. User probably needs to | |
14 // update their drivers or get a new browser. Present a link to | |
15 // http://get.webgl.org/troubleshooting | |
16 return; | |
17 } | |
18 | |
19 */ | |
20 | |
21 var BrowserDetect = { | |
22 init: function () { | |
23 var info = this.searchString(this.dataBrowser) || {identity:"unknown"} | |
24 this.browser = info.identity; | |
25 this.version = this.searchVersion(navigator.userAgent) | |
26 || this.searchVersion(navigator.appVersion) | |
27 || "an unknown version"; | |
28 this.platformInfo = this.searchString(this.dataPlatform) || this.dataPlatfor
m["unknown"]; | |
29 this.platform = this.platformInfo.identity; | |
30 var browserInfo = this.urls[this.browser]; | |
31 if (!browserInfo) { | |
32 browserInfo = this.urls["unknown"]; | |
33 } else if (browserInfo.platforms) { | |
34 var info = browserInfo.platforms[this.platform]; | |
35 if (info) { | |
36 browserInfo = info; | |
37 } | |
38 } | |
39 this.urls = browserInfo; | |
40 }, | |
41 searchString: function (data) { | |
42 for (var i = 0; i < data.length; i++){ | |
43 var info = data[i]; | |
44 var dataString = info.string; | |
45 var dataProp = info.prop; | |
46 this.versionSearchString = info.versionSearch || info.identity; | |
47 if (dataString) { | |
48 if (dataString.indexOf(info.subString) != -1) { | |
49 return info; | |
50 } | |
51 } else if (dataProp) { | |
52 return info; | |
53 } | |
54 } | |
55 }, | |
56 searchVersion: function (dataString) { | |
57 var index = dataString.indexOf(this.versionSearchString); | |
58 if (index == -1) { | |
59 return; | |
60 } | |
61 return parseFloat(dataString.substring( | |
62 index + this.versionSearchString.length + 1)); | |
63 }, | |
64 dataBrowser: [ | |
65 { string: navigator.userAgent, | |
66 subString: "Chrome", | |
67 identity: "Chrome" | |
68 }, | |
69 { string: navigator.userAgent, | |
70 subString: "OmniWeb", | |
71 versionSearch: "OmniWeb/", | |
72 identity: "OmniWeb" | |
73 }, | |
74 { string: navigator.vendor, | |
75 subString: "Apple", | |
76 identity: "Safari", | |
77 versionSearch: "Version" | |
78 }, | |
79 { string: navigator.userAgent, | |
80 subString: "Android", | |
81 identity: "Android" | |
82 }, | |
83 { prop: window.opera, | |
84 identity: "Opera" | |
85 }, | |
86 { string: navigator.vendor, | |
87 subString: "iCab", | |
88 identity: "iCab" | |
89 }, | |
90 { string: navigator.vendor, | |
91 subString: "KDE", | |
92 identity: "Konqueror" | |
93 }, | |
94 { string: navigator.userAgent, | |
95 subString: "Firefox", | |
96 identity: "Firefox" | |
97 }, | |
98 { string: navigator.vendor, | |
99 subString: "Camino", | |
100 identity: "Camino" | |
101 }, | |
102 {// for newer Netscapes (6+) | |
103 string: navigator.userAgent, | |
104 subString: "Netscape", | |
105 identity: "Netscape" | |
106 }, | |
107 { string: navigator.userAgent, | |
108 subString: "MSIE", | |
109 identity: "Explorer", | |
110 versionSearch: "MSIE" | |
111 }, | |
112 { string: navigator.userAgent, | |
113 subString: "Gecko", | |
114 identity: "Mozilla", | |
115 versionSearch: "rv" | |
116 }, | |
117 { // for older Netscapes (4-) | |
118 string: navigator.userAgent, | |
119 subString: "Mozilla", | |
120 identity: "Netscape", | |
121 versionSearch: "Mozilla" | |
122 } | |
123 ], | |
124 dataPlatform: [ | |
125 { string: navigator.platform, | |
126 subString: "Win", | |
127 identity: "Windows", | |
128 browsers: [ | |
129 {url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"
}, | |
130 // add back in when opera is stable {url: "http://labs.opera.com/" name: "Op
era Labs"}, | |
131 {url: "http://www.google.com/chrome/", name: "Google Chrome"} | |
132 ] | |
133 }, | |
134 { string: navigator.platform, | |
135 subString: "Mac", | |
136 identity: "Mac", | |
137 browsers: [ | |
138 {url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"
}, | |
139 {url: "http://www.google.com/chrome/", name: "Google Chrome"}, | |
140 // add back in when opera is stable {url: "http://labs.opera.com/", name:
"Opera Labs"}, | |
141 {url: "http://www.webkit.org/", name: "WebKit Developer Builds"} | |
142 ] | |
143 }, | |
144 { string: navigator.userAgent, | |
145 subString: "iPhone", | |
146 identity: "iPhone/iPod", | |
147 browsers: [ | |
148 {url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"
} | |
149 ] | |
150 }, | |
151 { string: navigator.platform, | |
152 subString: "iPad", | |
153 identity: "iPad", | |
154 browsers: [ | |
155 {url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"
} | |
156 ] | |
157 }, | |
158 { string: navigator.userAgent, | |
159 subString: "Android", | |
160 identity: "Android", | |
161 browsers: [ | |
162 {url: "https://market.android.com/details?id=org.mozilla.firefox", name: "
Mozilla Firefox"} | |
163 ] | |
164 }, | |
165 { string: navigator.platform, | |
166 subString: "Linux", | |
167 identity: "Linux", | |
168 browsers: [ | |
169 {url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"
}, | |
170 {url: "http://www.google.com/chrome/", name: "Google Chrome"}, | |
171 {url: "http://labs.opera.com/", name: "Opera Labs"} | |
172 ] | |
173 }, | |
174 { string: "unknown", | |
175 subString: "unknown", | |
176 identity: "unknown", | |
177 browsers: [ | |
178 {url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"
}, | |
179 {url: "http://www.google.com/chrome/", name: "Google Chrome"}, | |
180 {url: "http://labs.opera.com/", name: "Opera Labs"}, | |
181 {url: "http://www.webkit.org/", name: "WebKit Developer Builds"} | |
182 ] | |
183 } | |
184 ], | |
185 /* | |
186 upgradeUrl: Tell the user how to upgrade their browser. | |
187 troubleshootingUrl: Help the user. | |
188 platforms: Urls by platform. See dataPlatform.identity for valid plat
form names. | |
189 */ | |
190 urls: { | |
191 "Chrome": { | |
192 upgradeUrl: "http://www.google.com/support/chrome/bin/answer.py?answer=953
46", | |
193 troubleshootingUrl: "http://www.google.com/support/chrome/bin/answer.py?an
swer=1220892" | |
194 }, | |
195 "Firefox": { | |
196 upgradeUrl: "http://www.mozilla.com/en-US/firefox/new/", | |
197 troubleshootingUrl: "https://support.mozilla.com/en-US/kb/how-do-i-upgrade
-my-graphics-drivers" | |
198 }, | |
199 "Opera": { | |
200 upgradeUrl: "http://labs.opera.com", | |
201 troubleshootingUrl: "http://my.opera.com/core/blog/2011/02/28/webgl-and-ha
rdware-acceleration-2" | |
202 }, | |
203 "Android": { | |
204 upgradeUrl: null, | |
205 troubleshootingUrl: null | |
206 }, | |
207 "Safari": { | |
208 platforms: { | |
209 "iPhone/iPod": { | |
210 upgradeUrl: "http://www.apple.com/ios/", | |
211 troubleshootingUrl: "http://www.apple.com/support/iphone/" | |
212 }, | |
213 "iPad": { | |
214 upgradeUrl: "http://www.apple.com/ios/", | |
215 troubleshootingUrl: "http://www.apple.com/support/ipad/" | |
216 }, | |
217 "Mac": { | |
218 upgradeUrl: "http://www.webkit.org/", | |
219 troubleshootingUrl: "http://www.webkit.org/blog/919/webgl-draft-specif
ication-now-available/" | |
220 } | |
221 }, | |
222 upgradeUrl: "http://www.webkit.org/", | |
223 troubleshootingUrl: "http://www.webkit.org/blog/919/webgl-draft-specificat
ion-now-available/" | |
224 }, | |
225 "unknown": { | |
226 upgradeUrl: null, | |
227 troubleshootingUrl: null | |
228 } | |
229 } | |
230 }; | |
231 | |
232 | |
233 | |
OLD | NEW |