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) |
| 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 |
| 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"; |
| 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"; |
| 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 var bodyClassList = Array.prototype.slice.call(document.body.classList); |
| 264 for (var i = 0; i < bodyClassList.length; i++) |
| 265 { |
| 266 if (bodyClassList[i].indexOf('ua-') > -1) |
| 267 { |
| 268 document.body.classList.remove(bodyClassList[i]); |
| 269 } |
| 270 } |
| 271 document.body.classList.add("ua-"+browser); |
| 272 |
| 273 // Check selected option |
| 274 var selectedItem = this.browserSelect |
| 275 .querySelector("[data-value='"+browser+"']"); |
| 276 selectedItem.setAttribute("aria-checked", "true"); |
| 277 |
| 278 // Set selected option |
| 279 var selectedOption = document.createElement("li"); |
| 280 selectedOption.innerHTML = selectedItem.innerHTML; |
| 281 |
| 282 if (localStorage.getItem(this.BROWSER_AUTODETECTED_STORAGE_KEY)) |
| 283 { |
| 284 var autodetected = document |
| 285 .getElementById('browser-select-autodetected') |
| 286 .innerHTML; |
| 287 selectedOption.innerHTML += "<span class='muted'>("+autodetected+")</spa
n>"; |
| 288 } |
| 289 |
| 290 this.browserSelect |
| 291 .querySelector(".custom-select-selected") |
| 292 .innerHTML = selectedOption.innerHTML; |
| 293 } |
| 294 |
| 295 BrowserSelect.prototype._onClickOrKeyDown = function(event) |
| 296 { |
| 297 if (!event.target.classList.contains("custom-select-option")) return; |
| 298 |
| 299 var IS_ENTER_KEY = event.key == "Enter" || event.keyCode == 13; |
| 300 if (event.keyCode && !IS_ENTER_KEY) return; |
| 301 |
| 302 localStorage.removeItem(this.BROWSER_AUTODETECTED_STORAGE_KEY); |
| 303 |
| 304 // Uncheck previously checked option |
| 305 this.browserSelect |
| 306 .querySelector("[aria-checked='true']") |
| 307 .setAttribute("aria-checked", "false"); |
| 308 |
| 309 this.selectOption(event.target.getAttribute("data-value")); |
| 310 |
| 311 // Close Select |
| 312 this.browserCustomSelect.close(); |
| 313 } |
| 314 |
| 315 var browserSelect = document.getElementById("browser-select"); |
| 316 if (browserSelect) |
| 317 { |
| 318 new BrowserSelect(browserSelect); |
| 319 } |
| 320 |
202 }, false); | 321 }, false); |
203 }()); | 322 }()); |
OLD | NEW |