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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 { | 48 { |
49 // setTimeout to allow document.activeElement | 49 // setTimeout to allow document.activeElement |
50 // to move to newly focused element | 50 // to move to newly focused element |
51 setTimeout(function() | 51 setTimeout(function() |
52 { | 52 { |
53 var newFocus = document.activeElement; | 53 var newFocus = document.activeElement; |
54 | 54 |
55 if (newFocus | 55 if (newFocus |
56 .classList.contains("custom-select-selected") || | 56 .classList.contains("custom-select-selected") || |
57 newFocus | 57 newFocus |
58 .classList.contains("custom-select-option") || | |
59 newFocus | |
58 .parentElement | 60 .parentElement |
59 .classList.contains("custom-select-option")) | 61 .classList.contains("custom-select-option")) |
60 { | 62 { |
61 return; | 63 return; |
62 } | 64 } |
63 | 65 |
64 this.close(); | 66 this.close(); |
65 | 67 |
66 }.bind(this), 1); | 68 }.bind(this), 1); |
67 } | 69 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 | 219 |
218 this.toggleSection(event.target); | 220 this.toggleSection(event.target); |
219 } | 221 } |
220 | 222 |
221 var productTopicsAccordion = document.getElementById('product-topics-accordi on'); | 223 var productTopicsAccordion = document.getElementById('product-topics-accordi on'); |
222 if (productTopicsAccordion) | 224 if (productTopicsAccordion) |
223 { | 225 { |
224 new Accordion(productTopicsAccordion); | 226 new Accordion(productTopicsAccordion); |
225 } | 227 } |
226 | 228 |
229 /************************************************************************** | |
230 * BrowserSelect | |
231 **************************************************************************/ | |
232 | |
233 function BrowserSelect(select) | |
234 { | |
235 this.select = select; | |
236 CustomSelect.apply(this, [this.select]); | |
237 | |
238 this.DEFAULT_BROWSER = "chrome"; | |
239 this.BROWSER_STORAGE_KEY = "BROWSER"; | |
240 this.BROWSER_AUTODETECTED_STORAGE_KEY = "BROWSER_AUTODETECTED"; | |
241 | |
242 this.select | |
243 .addEventListener("click", this._onClickOrKeyDown.bind(this), false); | |
244 | |
245 this.select | |
246 .addEventListener("keydown", this._onClickOrKeyDown.bind(this), false); | |
247 | |
248 var storedBrowser = localStorage.getItem(this.BROWSER_STORAGE_KEY); | |
249 if (storedBrowser) this.selectOption(storedBrowser); | |
250 else this.detectBrowser(); | |
251 } | |
252 | |
253 BrowserSelect.prototype = Object.create(CustomSelect.prototype); | |
254 BrowserSelect.prototype.constructor = BrowserSelect; | |
255 | |
256 BrowserSelect.prototype.detectBrowser = function() | |
257 { | |
258 localStorage.setItem(this.BROWSER_AUTODETECTED_STORAGE_KEY, "true"); | |
259 | |
260 var browser; | |
261 if (bowser.chrome) browser = "chrome"; | |
262 else if (bowser.opera) browser = "opera"; | |
263 else if (bowser.coast) browser = "opera"; | |
264 else if (bowser.samsungBrowser) browser = "samsung"; | |
265 else if (bowser.yandexbrowser) browser = "yandex"; | |
266 else if (bowser.maxthon) browser = "maxthon"; | |
267 else if (bowser.msie) browser = "ie"; | |
268 else if (bowser.msedge) browser = "edge"; | |
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 }; | |
280 | |
281 BrowserSelect.prototype.selectOption = function(browser) | |
282 { | |
283 localStorage.setItem(this.BROWSER_STORAGE_KEY, browser); | |
284 | |
285 // Change body class | |
286 var bodyClassList = Array.prototype.slice.call(document.body.classList); | |
287 for (var i = 0; i < bodyClassList.length; i++) | |
288 { | |
289 if (bodyClassList[i].indexOf('ua-') > -1) | |
290 { | |
291 document.body.classList.remove(bodyClassList[i]); | |
292 } | |
293 } | |
294 document.body.classList.add("ua-" + browser); | |
295 | |
296 // Check selected option | |
297 var selectedItem = this.select | |
298 .querySelector("[data-value='" + browser + "']"); | |
ire
2017/11/01 12:36:49
@julian Is this what you mean?
juliandoucette
2017/11/01 12:49:21
Yes.
RE: kzar's comment.
I think kzar debunked m
ire
2017/11/01 17:20:12
Okay, I prefer my way then :p
| |
299 selectedItem.setAttribute("aria-checked", "true"); | |
300 | |
301 // Set selected option | |
302 var selectedOption = selectedItem.innerHTML; | |
303 | |
304 if (localStorage.getItem(this.BROWSER_AUTODETECTED_STORAGE_KEY)) | |
305 { | |
306 var autodetected = document | |
307 .getElementById('browser-select-autodetected') | |
308 .innerHTML; | |
309 selectedOption += "<span class='muted'>(" + autodetected + ")</span>"; | |
310 } | |
311 | |
312 this.select | |
313 .querySelector(".custom-select-selected") | |
314 .innerHTML = selectedOption; | |
315 }; | |
316 | |
317 BrowserSelect.prototype._onClickOrKeyDown = function(event) | |
318 { | |
319 if (!event.target.classList.contains("custom-select-option")) return; | |
320 | |
321 var IS_ENTER_KEY = event.key == "Enter" || event.keyCode == 13; | |
322 if (event.keyCode && !IS_ENTER_KEY) return; | |
323 | |
324 localStorage.removeItem(this.BROWSER_AUTODETECTED_STORAGE_KEY); | |
325 | |
326 // Uncheck previously checked option | |
327 this.select | |
328 .querySelector("[aria-checked='true']") | |
329 .setAttribute("aria-checked", "false"); | |
330 | |
331 this.selectOption(event.target.getAttribute("data-value")); | |
332 | |
333 this.close(); | |
334 }; | |
335 | |
336 var browserSelect = document.getElementById("browser-select"); | |
337 if (browserSelect) | |
338 { | |
339 new BrowserSelect(browserSelect); | |
340 } | |
341 | |
227 }, false); | 342 }, false); |
228 }()); | 343 }()); |
OLD | NEW |