LEFT | RIGHT |
1 (function(){ | 1 (function() |
| 2 { |
2 document.addEventListener("DOMContentLoaded", function() | 3 document.addEventListener("DOMContentLoaded", function() |
3 { | 4 { |
4 | 5 |
5 /************************************************************************** | 6 /************************************************************************** |
6 * General | 7 * General |
7 **************************************************************************/ | 8 **************************************************************************/ |
8 | 9 |
9 // Change html class name from "no-js" to "js" | 10 // Change html class name from "no-js" to "js" |
10 document.documentElement.className = "js"; | 11 document.documentElement.className = "js"; |
11 | 12 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 229 |
229 /************************************************************************** | 230 /************************************************************************** |
230 * BrowserSelect | 231 * BrowserSelect |
231 **************************************************************************/ | 232 **************************************************************************/ |
232 | 233 |
233 function BrowserSelect(select) | 234 function BrowserSelect(select) |
234 { | 235 { |
235 this.select = select; | 236 this.select = select; |
236 CustomSelect.apply(this, [this.select]); | 237 CustomSelect.apply(this, [this.select]); |
237 | 238 |
238 this.DEFAULT_BROWSER = "chrome"; | |
239 this.BROWSER_STORAGE_KEY = "BROWSER"; | 239 this.BROWSER_STORAGE_KEY = "BROWSER"; |
240 this.BROWSER_AUTODETECTED_STORAGE_KEY = "BROWSER_AUTODETECTED"; | 240 this.BROWSER_AUTODETECTED_STORAGE_KEY = "BROWSER_AUTODETECTED"; |
| 241 this.SUPPORTED_BROWSERS = ["chrome", "opera", "samsungBrowser", |
| 242 "yandexbrowser", "maxthon", "msie", |
| 243 "msedge", "firefox", "ios", "safari"]; |
| 244 this.DEFAULT_BROWSER = "chrome"; |
241 | 245 |
242 this.select | 246 this.select |
243 .addEventListener("click", this._onClickOrKeyDown.bind(this), false); | 247 .addEventListener("click", this._onClickOrKeyDown.bind(this), false); |
244 | 248 |
245 this.select | 249 this.select |
246 .addEventListener("keydown", this._onClickOrKeyDown.bind(this), false); | 250 .addEventListener("keydown", this._onClickOrKeyDown.bind(this), false); |
247 | 251 |
248 var storedBrowser = localStorage.getItem(this.BROWSER_STORAGE_KEY); | 252 var storedBrowser = localStorage.getItem(this.BROWSER_STORAGE_KEY); |
249 if (storedBrowser) this.selectOption(storedBrowser); | 253 if (storedBrowser) this.selectOption(storedBrowser); |
250 else this.detectBrowser(); | 254 else this.detectBrowser(); |
251 } | 255 } |
252 | 256 |
253 BrowserSelect.prototype = Object.create(CustomSelect.prototype); | 257 BrowserSelect.prototype = Object.create(CustomSelect.prototype); |
254 BrowserSelect.prototype.constructor = BrowserSelect; | 258 BrowserSelect.prototype.constructor = BrowserSelect; |
255 | 259 |
256 BrowserSelect.prototype.detectBrowser = function() | 260 BrowserSelect.prototype.detectBrowser = function() |
257 { | 261 { |
258 localStorage.setItem(this.BROWSER_AUTODETECTED_STORAGE_KEY, "true"); | 262 for (var i = 0; i < this.SUPPORTED_BROWSERS.length; i++) |
259 | 263 { |
260 var browser; | 264 var supportedBrowser = this.SUPPORTED_BROWSERS[i]; |
261 if (bowser.chrome) browser = "chrome"; | 265 if (bowser[supportedBrowser]) |
262 else if (bowser.opera) browser = "opera"; | 266 { |
263 else if (bowser.coast) browser = "opera"; | 267 localStorage.setItem(this.BROWSER_AUTODETECTED_STORAGE_KEY, "true"); |
264 else if (bowser.samsungBrowser) browser = "samsung"; | 268 return this.selectOption(supportedBrowser); |
265 else if (bowser.yandexbrowser) browser = "yandex"; | 269 } |
266 else if (bowser.maxthon) browser = "maxthon"; | 270 } |
267 else if (bowser.msie) browser = "ie"; | 271 |
268 else if (bowser.msedge) browser = "edge"; | 272 this.selectOption(this.DEFAULT_BROWSER); |
269 else if (bowser.firefox) browser = "firefox"; | |
270 else if (bowser.ios) browser = "ios"; | |
271 else if (bowser.safari) browser = "safari"; | |
272 else | |
273 { | |
274 localStorage.removeItem(this.BROWSER_AUTODETECTED_STORAGE_KEY); | |
275 browser = this.DEFAULT_BROWSER; | |
276 } | |
277 | |
278 this.selectOption(browser); | |
279 }; | 273 }; |
280 | 274 |
281 BrowserSelect.prototype.selectOption = function(browser) | 275 BrowserSelect.prototype.selectOption = function(browser) |
282 { | 276 { |
283 localStorage.setItem(this.BROWSER_STORAGE_KEY, browser); | 277 localStorage.setItem(this.BROWSER_STORAGE_KEY, browser); |
284 | 278 |
285 // Change body class | 279 // Change body class |
286 var bodyClassList = Array.prototype.slice.call(document.body.classList); | 280 var bodyClassList = Array.prototype.slice.call(document.body.classList); |
287 for (var i = 0; i < bodyClassList.length; i++) | 281 for (var i = 0; i < bodyClassList.length; i++) |
288 { | 282 { |
289 if (bodyClassList[i].indexOf('ua-') > -1) | 283 if (bodyClassList[i].indexOf('ua-') > -1) |
290 { | 284 { |
291 document.body.classList.remove(bodyClassList[i]); | 285 document.body.classList.remove(bodyClassList[i]); |
292 } | 286 } |
293 } | 287 } |
294 document.body.classList.add("ua-" + browser); | 288 document.body.classList.add("ua-" + browser); |
295 | 289 |
296 // Check selected option | 290 // Check selected option |
297 var selectedItem = this.select.querySelector("[data-value='" + browser + "
']"); | 291 var selectedItem = this.select |
| 292 .querySelector("[data-value='" + browser + "']"); |
298 selectedItem.setAttribute("aria-checked", "true"); | 293 selectedItem.setAttribute("aria-checked", "true"); |
299 | 294 |
300 // Set selected option | 295 // Set selected option |
301 var selectedOption = selectedItem.innerHTML; | 296 var selectedOption = selectedItem.innerHTML; |
302 | 297 |
303 if (localStorage.getItem(this.BROWSER_AUTODETECTED_STORAGE_KEY)) | 298 if (localStorage.getItem(this.BROWSER_AUTODETECTED_STORAGE_KEY)) |
304 { | 299 { |
305 var autodetected = document | 300 var autodetected = document |
306 .getElementById('browser-select-autodetected') | 301 .getElementById('browser-select-autodetected') |
307 .innerHTML; | 302 .innerHTML; |
(...skipping 25 matching lines...) Expand all Loading... |
333 }; | 328 }; |
334 | 329 |
335 var browserSelect = document.getElementById("browser-select"); | 330 var browserSelect = document.getElementById("browser-select"); |
336 if (browserSelect) | 331 if (browserSelect) |
337 { | 332 { |
338 new BrowserSelect(browserSelect); | 333 new BrowserSelect(browserSelect); |
339 } | 334 } |
340 | 335 |
341 }, false); | 336 }, false); |
342 }()); | 337 }()); |
LEFT | RIGHT |