Left: | ||
Right: |
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 17 matching lines...) Expand all Loading... | |
29 toggleNavbarCollapseEls[i] | 30 toggleNavbarCollapseEls[i] |
30 .addEventListener("click", toggleNavbarCollapse, false); | 31 .addEventListener("click", toggleNavbarCollapse, false); |
31 } | 32 } |
32 | 33 |
33 /************************************************************************** | 34 /************************************************************************** |
34 * CustomSelect | 35 * CustomSelect |
35 **************************************************************************/ | 36 **************************************************************************/ |
36 | 37 |
37 function CustomSelect(select) | 38 function CustomSelect(select) |
38 { | 39 { |
39 console.log(select) | |
juliandoucette
2017/10/31 13:19:58
Hello, world
ire
2017/11/01 12:36:49
Oops! Thanks :)
| |
40 | |
41 this.select = select; | 40 this.select = select; |
42 this.close(); | 41 this.close(); |
43 this.select | 42 this.select |
44 .addEventListener("click", this._onClick.bind(this), false); | 43 .addEventListener("click", this._onClick.bind(this), false); |
45 this.select | 44 this.select |
46 .addEventListener("focusout", this._onFocusOut.bind(this), false); | 45 .addEventListener("focusout", this._onFocusOut.bind(this), false); |
47 } | 46 } |
48 | 47 |
49 CustomSelect.prototype._onFocusOut = function() | 48 CustomSelect.prototype._onFocusOut = function() |
50 { | 49 { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 | 229 |
231 /************************************************************************** | 230 /************************************************************************** |
232 * BrowserSelect | 231 * BrowserSelect |
233 **************************************************************************/ | 232 **************************************************************************/ |
234 | 233 |
235 function BrowserSelect(select) | 234 function BrowserSelect(select) |
236 { | 235 { |
237 this.select = select; | 236 this.select = select; |
238 CustomSelect.apply(this, [this.select]); | 237 CustomSelect.apply(this, [this.select]); |
239 | 238 |
240 this.DEFAULT_BROWSER = "chrome"; | |
241 this.BROWSER_STORAGE_KEY = "BROWSER"; | 239 this.BROWSER_STORAGE_KEY = "BROWSER"; |
juliandoucette
2017/10/31 13:19:59
NIT/Suggest: The word "STORAGE" is unnecessary (ve
ire
2017/11/01 12:36:49
I don't think it's unnecessary, because it's relat
| |
242 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"; | |
243 | 245 |
244 this.select | 246 this.select |
245 .addEventListener("click", this._onClickOrKeyDown.bind(this), false); | 247 .addEventListener("click", this._onClickOrKeyDown.bind(this), false); |
246 | 248 |
247 this.select | 249 this.select |
248 .addEventListener("keydown", this._onClickOrKeyDown.bind(this), false); | 250 .addEventListener("keydown", this._onClickOrKeyDown.bind(this), false); |
249 | 251 |
250 var storedBrowser = localStorage.getItem(this.BROWSER_STORAGE_KEY); | 252 var storedBrowser = localStorage.getItem(this.BROWSER_STORAGE_KEY); |
251 if (storedBrowser) this.selectOption(storedBrowser); | 253 if (storedBrowser) this.selectOption(storedBrowser); |
252 else this.detectBrowser(); | 254 else this.detectBrowser(); |
253 } | 255 } |
254 | 256 |
255 BrowserSelect.prototype = CustomSelect.prototype; | 257 BrowserSelect.prototype = Object.create(CustomSelect.prototype); |
juliandoucette
2017/10/31 13:19:59
This assignment is by reference; not by copy. As a
ire
2017/11/01 12:36:48
Thanks! Done.
| |
258 BrowserSelect.prototype.constructor = BrowserSelect; | |
256 | 259 |
257 BrowserSelect.prototype.detectBrowser = function() | 260 BrowserSelect.prototype.detectBrowser = function() |
258 { | 261 { |
259 localStorage.setItem(this.BROWSER_AUTODETECTED_STORAGE_KEY, "true"); | 262 for (var i = 0; i < this.SUPPORTED_BROWSERS.length; i++) |
260 | 263 { |
261 var browser; | 264 var supportedBrowser = this.SUPPORTED_BROWSERS[i]; |
262 if (bowser.chrome) browser = "chrome"; | 265 if (bowser[supportedBrowser]) |
263 else if (bowser.opera) browser = "opera"; | 266 { |
264 else if (bowser.coast) browser = "opera"; | 267 localStorage.setItem(this.BROWSER_AUTODETECTED_STORAGE_KEY, "true"); |
265 else if (bowser.samsungBrowser) browser = "samsung"; | 268 return this.selectOption(supportedBrowser); |
266 else if (bowser.yandexbrowser) browser = "yandex"; | 269 } |
267 else if (bowser.maxthon) browser = "maxthon"; | 270 } |
268 else if (bowser.msie) browser = "ie"; | 271 |
269 else if (bowser.msedge) browser = "edge"; | 272 this.selectOption(this.DEFAULT_BROWSER); |
270 else if (bowser.firefox) browser = "firefox"; | |
271 else if (bowser.ios) browser = "ios"; | |
272 else if (bowser.safari) browser = "safari"; | |
273 else | |
274 { | |
275 localStorage.removeItem(this.BROWSER_AUTODETECTED_STORAGE_KEY); | |
276 browser = this.DEFAULT_BROWSER; | |
277 } | |
278 | |
279 this.selectOption(browser); | |
280 }; | 273 }; |
281 | 274 |
282 BrowserSelect.prototype.selectOption = function(browser) | 275 BrowserSelect.prototype.selectOption = function(browser) |
283 { | 276 { |
284 localStorage.setItem(this.BROWSER_STORAGE_KEY, browser); | 277 localStorage.setItem(this.BROWSER_STORAGE_KEY, browser); |
285 | 278 |
286 // Change body class | 279 // Change body class |
287 var bodyClassList = Array.prototype.slice.call(document.body.classList); | 280 var bodyClassList = Array.prototype.slice.call(document.body.classList); |
288 for (var i = 0; i < bodyClassList.length; i++) | 281 for (var i = 0; i < bodyClassList.length; i++) |
289 { | 282 { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 }; | 328 }; |
336 | 329 |
337 var browserSelect = document.getElementById("browser-select"); | 330 var browserSelect = document.getElementById("browser-select"); |
338 if (browserSelect) | 331 if (browserSelect) |
339 { | 332 { |
340 new BrowserSelect(browserSelect); | 333 new BrowserSelect(browserSelect); |
341 } | 334 } |
342 | 335 |
343 }, false); | 336 }, false); |
344 }()); | 337 }()); |
LEFT | RIGHT |