| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 (function(){ | 1 (function(){ |
| 2 document.addEventListener("DOMContentLoaded", function() | 2 document.addEventListener("DOMContentLoaded", function() |
| 3 { | 3 { |
| 4 | 4 |
| 5 /************************************************************************** | 5 /************************************************************************** |
| 6 * General | 6 * General |
| 7 **************************************************************************/ | 7 **************************************************************************/ |
| 8 | 8 |
| 9 // Change html class name from "no-js" to "js" | 9 // Change html class name from "no-js" to "js" |
| 10 document.documentElement.className = "js"; | 10 document.documentElement.className = "js"; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 | 192 |
| 193 this.toggleSection(event.target); | 193 this.toggleSection(event.target); |
| 194 } | 194 } |
| 195 | 195 |
| 196 var productTopicsAccordion = document.getElementById('product-topics-accordi on'); | 196 var productTopicsAccordion = document.getElementById('product-topics-accordi on'); |
| 197 if (productTopicsAccordion) | 197 if (productTopicsAccordion) |
| 198 { | 198 { |
| 199 new Accordion(productTopicsAccordion); | 199 new Accordion(productTopicsAccordion); |
| 200 } | 200 } |
| 201 | 201 |
| 202 /************************************************************************** | |
| 203 * BrowserSelect | |
| 204 **************************************************************************/ | |
| 205 | |
| 206 function BrowserSelect(select) | |
|
juliandoucette
2017/10/13 13:39:56
Note: You could extend CustomSelect's prototype (e
ire
2017/10/17 15:03:33
Cool. I'll keep what i did here then.
| |
| 207 { | |
| 208 this.browserSelect = select; | |
| 209 this.browserCustomSelect = new CustomSelect(this.browserSelect); | |
| 210 | |
| 211 this.DEFAULT_BROWSER = "chrome"; | |
| 212 this.BROWSER_STORAGE_KEY = "BROWSER"; | |
| 213 this.BROWSER_AUTODETECTED_STORAGE_KEY = "BROWSER_AUTODETECTED"; | |
| 214 | |
| 215 this.browserSelect | |
| 216 .addEventListener("click", this._onClickOrKeyDown.bind(this), false); | |
| 217 | |
|
juliandoucette
2017/10/13 13:39:56
NIT: You should be able to click-away too (click e
ire
2017/10/17 15:03:34
Yes, I will fix this in a separate issue
https://
juliandoucette
2017/10/18 15:04:10
Acknowledged.
| |
| 218 this.browserSelect | |
| 219 .addEventListener("keydown", this._onClickOrKeyDown.bind(this), false); | |
| 220 | |
| 221 var storedBrowser = localStorage.getItem(this.BROWSER_STORAGE_KEY); | |
| 222 if (storedBrowser) | |
| 223 { | |
| 224 this.selectOption(storedBrowser); | |
| 225 } | |
| 226 else | |
| 227 { | |
| 228 this.detectBrowser(); | |
| 229 } | |
| 230 } | |
| 231 | |
| 232 BrowserSelect.prototype.detectBrowser = function() | |
| 233 { | |
| 234 localStorage.setItem(this.BROWSER_AUTODETECTED_STORAGE_KEY, "true"); | |
| 235 | |
| 236 var browser; | |
| 237 if (bowser.chrome) browser = "chrome"; | |
|
juliandoucette
2017/10/13 13:39:55
Wait, what? How can browser have properties if it
ire
2017/10/17 15:03:34
You can override previously defined (or undefined)
juliandoucette
2017/10/18 15:04:10
Can you elaborate / explain when/how this variable
ire
2017/10/20 13:40:46
Sure!
I create a pen to illustrate this - https:/
| |
| 238 else if (bowser.opera) browser = "opera"; | |
| 239 else if (bowser.coast) browser = "opera"; | |
| 240 else if (bowser.samsungBrowser) browser = "samsung"; | |
| 241 else if (bowser.yandexbrowser) browser = "yandex"; | |
| 242 else if (bowser.maxthon) browser = "maxthon"; | |
| 243 else if (bowser.msie) browser = "ie"; | |
| 244 else if (bowser.msedge) browser = "edge"; | |
| 245 else if (bowser.firefox) browser = "firefox"; | |
| 246 else if (bowser.ios) browser = "ios"; | |
| 247 else if (bowser.safari) browser = "safari"; | |
|
juliandoucette
2017/10/18 15:04:10
Why check each browser property and not *just* bro
ire
2017/10/20 13:40:46
I felt it wouldn't be as reliable/steady as this.
| |
| 248 else | |
| 249 { | |
| 250 localStorage.removeItem(this.BROWSER_AUTODETECTED_STORAGE_KEY); | |
| 251 browser = this.DEFAULT_BROWSER; | |
| 252 } | |
| 253 | |
| 254 this.selectOption(browser); | |
| 255 } | |
| 256 | |
| 257 BrowserSelect.prototype.selectOption = function(browser) | |
| 258 { | |
| 259 // Save value to Local Storage | |
| 260 localStorage.setItem(this.BROWSER_STORAGE_KEY, browser); | |
| 261 | |
| 262 // Change body class | |
| 263 document.body.className = "ua-"+browser; | |
|
juliandoucette
2017/10/13 13:39:55
What if there are not related classes attached to
juliandoucette
2017/10/13 13:41:36
unrelated*
ire
2017/10/17 15:03:34
Done.
| |
| 264 | |
| 265 // Set selected option | |
| 266 var selectedOption = document.createElement("li"); | |
| 267 selectedOption.innerHTML = this | |
| 268 .browserSelect | |
|
juliandoucette
2017/10/13 13:39:55
NIT: spaces around +?
ire
2017/10/17 15:03:34
I thought we don't put spaces within the ()?
juliandoucette
2017/10/18 15:04:11
We don't put spaces after the opening brace and be
ire
2017/10/20 13:40:48
Alright, makes sense. Done.
| |
| 269 .querySelector("[data-value='"+browser+"']") | |
| 270 .innerHTML; | |
| 271 | |
| 272 if (localStorage.getItem(this.BROWSER_AUTODETECTED_STORAGE_KEY)) | |
| 273 { | |
| 274 selectedOption.innerHTML += "<span class='muted'>(autodetected)</span>"; | |
|
juliandoucette
2017/10/13 13:39:55
This isn't translated. I suggest translating it in
ire
2017/10/17 15:03:34
I place it in a template so I wouldn't have to hav
juliandoucette
2017/10/18 15:04:10
You mean you will place it in a template? Or somet
ire
2017/10/20 13:40:48
Sorry I meant to say "I will place it in a templat
| |
| 275 } | |
| 276 | |
| 277 this.browserSelect | |
| 278 .querySelector(".custom-select-selected") | |
| 279 .innerHTML = selectedOption.innerHTML; | |
| 280 } | |
| 281 | |
| 282 BrowserSelect.prototype._onClickOrKeyDown = function(event) | |
| 283 { | |
| 284 if (!event.target.classList.contains("custom-select-option")) return; | |
| 285 | |
| 286 var IS_ENTER_KEY = event.key == "Enter" || event.keyCode == 13; | |
| 287 if (event.keyCode && !IS_ENTER_KEY) return; | |
|
juliandoucette
2017/10/13 13:39:56
Why check event.keyCode here?
ire
2017/10/17 15:03:33
Because this function is also relevant for clicks.
juliandoucette
2017/10/18 15:04:11
Acknowledged. I was confused.
| |
| 288 | |
| 289 localStorage.removeItem(this.BROWSER_AUTODETECTED_STORAGE_KEY); | |
| 290 | |
| 291 this.selectOption(event.target.getAttribute("data-value")); | |
| 292 | |
| 293 // Close Select | |
| 294 this.browserCustomSelect.close(); | |
| 295 } | |
| 296 | |
| 297 var browserSelect = document.getElementById("browser-select"); | |
| 298 if (browserSelect) | |
| 299 { | |
| 300 new BrowserSelect(browserSelect); | |
| 301 } | |
| 302 | |
| 202 }, false); | 303 }, false); |
| 203 }()); | 304 }()); |
| OLD | NEW |