| OLD | NEW | 
|---|
| 1 (function() | 1 (function() | 
| 2 { | 2 { | 
| 3   document.addEventListener("DOMContentLoaded", function() | 3   document.addEventListener("DOMContentLoaded", function() | 
| 4   { | 4   { | 
| 5 | 5 | 
| 6     /************************************************************************** | 6     /************************************************************************** | 
| 7      * General | 7      * General | 
| 8      **************************************************************************/ | 8      **************************************************************************/ | 
| 9 | 9 | 
| 10     // Change html class name from "no-js" to "js" | 10     // Change html class name from "no-js" to "js" | 
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 228     } | 228     } | 
| 229 | 229 | 
| 230     /************************************************************************** | 230     /************************************************************************** | 
| 231      * BrowserSelect | 231      * BrowserSelect | 
| 232      **************************************************************************/ | 232      **************************************************************************/ | 
| 233 | 233 | 
| 234     function BrowserSelect(select) | 234     function BrowserSelect(select) | 
| 235     { | 235     { | 
| 236       this.select = select; | 236       this.select = select; | 
| 237       CustomSelect.apply(this, [this.select]); | 237       CustomSelect.apply(this, [this.select]); | 
|  | 238       this.noContentMessage = document.getElementById("no-content-for-platform-m
     essage"); | 
| 238 | 239 | 
| 239       this.BROWSER_STORAGE_KEY = "BROWSER"; | 240       this.BROWSER_STORAGE_KEY = "BROWSER"; | 
| 240       this.BROWSER_AUTODETECTED_STORAGE_KEY = "BROWSER_AUTODETECTED"; | 241       this.BROWSER_AUTODETECTED_STORAGE_KEY = "BROWSER_AUTODETECTED"; | 
| 241       this.SUPPORTED_BROWSERS = ["chrome", "opera", "samsungBrowser", | 242       this.SUPPORTED_BROWSERS = ["chrome", "opera", "samsungBrowser", | 
| 242                                  "yandexbrowser", "maxthon", "msie", | 243                                  "yandexbrowser", "maxthon", "msie", | 
| 243                                  "msedge", "firefox", "ios", "safari"]; | 244                                  "msedge", "firefox", "ios", "safari"]; | 
| 244       this.DEFAULT_BROWSER = "chrome"; | 245       this.DEFAULT_BROWSER = "chrome"; | 
| 245 | 246 | 
|  | 247       this.setCurrentArticleSupportedBrowsers(); | 
|  | 248 | 
| 246       this.select | 249       this.select | 
| 247         .addEventListener("click", this._onClickOrKeyDown.bind(this), false); | 250         .addEventListener("click", this._onClickOrKeyDown.bind(this), false); | 
| 248 | 251 | 
| 249       this.select | 252       this.select | 
| 250         .addEventListener("keydown", this._onClickOrKeyDown.bind(this), false); | 253         .addEventListener("keydown", this._onClickOrKeyDown.bind(this), false); | 
| 251 | 254 | 
|  | 255       this.noContentMessage | 
|  | 256         .addEventListener("click", this._onClickNoContentMessage.bind(this), fal
     se); | 
|  | 257 | 
| 252       var storedBrowser = localStorage.getItem(this.BROWSER_STORAGE_KEY); | 258       var storedBrowser = localStorage.getItem(this.BROWSER_STORAGE_KEY); | 
| 253       if (storedBrowser) this.selectOption(storedBrowser); | 259       if (storedBrowser) this.selectOption(storedBrowser); | 
| 254       else this.detectBrowser(); | 260       else this.detectBrowser(); | 
| 255     } | 261     } | 
| 256 | 262 | 
| 257     BrowserSelect.prototype = Object.create(CustomSelect.prototype); | 263     BrowserSelect.prototype = Object.create(CustomSelect.prototype); | 
| 258     BrowserSelect.prototype.constructor = BrowserSelect; | 264     BrowserSelect.prototype.constructor = BrowserSelect; | 
| 259 | 265 | 
|  | 266     BrowserSelect.prototype.setCurrentArticleSupportedBrowsers = function() | 
|  | 267     { | 
|  | 268       for (var i = 0; i < this.SUPPORTED_BROWSERS.length; i++) | 
|  | 269       { | 
|  | 270         var supportedBrowser = this.SUPPORTED_BROWSERS[i]; | 
|  | 271         if (!document.querySelector(".platform-"+supportedBrowser)) | 
|  | 272         { | 
|  | 273           this.noContentMessage.querySelector("."+supportedBrowser) | 
|  | 274               .setAttribute("hidden", "true"); | 
|  | 275         } | 
|  | 276       } | 
|  | 277     }; | 
|  | 278 | 
| 260     BrowserSelect.prototype.detectBrowser = function() | 279     BrowserSelect.prototype.detectBrowser = function() | 
| 261     { | 280     { | 
| 262       for (var i = 0; i < this.SUPPORTED_BROWSERS.length; i++) | 281       for (var i = 0; i < this.SUPPORTED_BROWSERS.length; i++) | 
| 263       { | 282       { | 
| 264         var supportedBrowser = this.SUPPORTED_BROWSERS[i]; | 283         var supportedBrowser = this.SUPPORTED_BROWSERS[i]; | 
| 265         if (bowser[supportedBrowser]) | 284         if (bowser[supportedBrowser]) | 
| 266         { | 285         { | 
| 267           localStorage.setItem(this.BROWSER_AUTODETECTED_STORAGE_KEY, "true"); | 286           localStorage.setItem(this.BROWSER_AUTODETECTED_STORAGE_KEY, "true"); | 
| 268           return this.selectOption(supportedBrowser); | 287           return this.selectOption(supportedBrowser); | 
| 269         } | 288         } | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 299       { | 318       { | 
| 300         var autodetected = document | 319         var autodetected = document | 
| 301                               .getElementById("browser-select-autodetected") | 320                               .getElementById("browser-select-autodetected") | 
| 302                               .innerHTML; | 321                               .innerHTML; | 
| 303         selectedOption += "<span class='muted'>(" + autodetected + ")</span>"; | 322         selectedOption += "<span class='muted'>(" + autodetected + ")</span>"; | 
| 304       } | 323       } | 
| 305 | 324 | 
| 306       this.select | 325       this.select | 
| 307           .querySelector(".custom-select-selected") | 326           .querySelector(".custom-select-selected") | 
| 308           .innerHTML = selectedOption; | 327           .innerHTML = selectedOption; | 
|  | 328 | 
|  | 329       this.noContentMessage.setAttribute("aria-hidden", "true"); | 
|  | 330       this.noContentMessage.setAttribute("hidden", "true"); | 
| 309 | 331 | 
| 310       if (!document.querySelector(".platform-" + browser)) | 332       if (!document.querySelector(".platform-" + browser)) | 
| 311       { | 333       { | 
| 312         this.handleNoContentForBrowser(browser); | 334         this.noContentMessage.removeAttribute("aria-hidden"); | 
|  | 335         this.noContentMessage.removeAttribute("hidden"); | 
| 313       } | 336       } | 
| 314     }; | 337     }; | 
| 315 | 338 | 
| 316     BrowserSelect.prototype.handleNoContentForBrowser = function(browser) |  | 
| 317     { |  | 
| 318       var section = document.createElement("section"); |  | 
| 319       section.classList.add("platform-" + browser); |  | 
| 320       section.innerHTML = document |  | 
| 321                             .getElementById("no-content-for-platform-message") |  | 
| 322                             .innerHTML; |  | 
| 323 |  | 
| 324       document |  | 
| 325         .querySelector(".article-body") |  | 
| 326         .insertAdjacentElement("afterbegin", section); |  | 
| 327     } |  | 
| 328 |  | 
| 329     BrowserSelect.prototype._onClickOrKeyDown = function(event) | 339     BrowserSelect.prototype._onClickOrKeyDown = function(event) | 
| 330     { | 340     { | 
| 331       if (!event.target.classList.contains("custom-select-option")) return; | 341       if (!event.target.classList.contains("custom-select-option")) return; | 
| 332 | 342 | 
| 333       var IS_ENTER_KEY = event.key == "Enter" || event.keyCode == 13; | 343       var IS_ENTER_KEY = event.key == "Enter" || event.keyCode == 13; | 
| 334       if (event.keyCode && !IS_ENTER_KEY) return; | 344       if (event.keyCode && !IS_ENTER_KEY) return; | 
| 335 | 345 | 
| 336       localStorage.removeItem(this.BROWSER_AUTODETECTED_STORAGE_KEY); | 346       localStorage.removeItem(this.BROWSER_AUTODETECTED_STORAGE_KEY); | 
| 337 | 347 | 
| 338       // Uncheck previously checked option | 348       // Uncheck previously checked option | 
| 339       this.select | 349       this.select | 
| 340           .querySelector("[aria-checked='true']") | 350           .querySelector("[aria-checked='true']") | 
| 341           .setAttribute("aria-checked", "false"); | 351           .setAttribute("aria-checked", "false"); | 
| 342 | 352 | 
| 343       this.selectOption(event.target.getAttribute("data-value")); | 353       this.selectOption(event.target.getAttribute("data-value")); | 
| 344 | 354 | 
| 345       this.close(); | 355       this.close(); | 
| 346     }; | 356     }; | 
| 347 | 357 | 
|  | 358     BrowserSelect.prototype._onClickNoContentMessage = function(event) | 
|  | 359     { | 
|  | 360       if (event.target.tagName != "BUTTON") return; | 
|  | 361 | 
|  | 362       var browser = event.target.parentElement.className; | 
|  | 363       this.selectOption(browser); | 
|  | 364     }; | 
|  | 365 | 
| 348     var browserSelect = document.getElementById("browser-select"); | 366     var browserSelect = document.getElementById("browser-select"); | 
| 349     if (browserSelect) | 367     if (browserSelect) | 
| 350     { | 368     { | 
| 351       new BrowserSelect(browserSelect); | 369       new BrowserSelect(browserSelect); | 
| 352     } | 370     } | 
| 353 | 371 | 
| 354   }, false); | 372   }, false); | 
| 355 }()); | 373 }()); | 
| OLD | NEW | 
|---|