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("hidden", "true"); |
309 | 330 |
310 if (!document.querySelector(".platform-" + browser)) | 331 if (!document.querySelector(".platform-" + browser)) |
311 { | 332 { |
312 this.handleNoContentForBrowser(browser); | 333 this.noContentMessage.removeAttribute("hidden"); |
313 } | 334 } |
314 }; | 335 }; |
315 | 336 |
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) | 337 BrowserSelect.prototype._onClickOrKeyDown = function(event) |
330 { | 338 { |
331 if (!event.target.classList.contains("custom-select-option")) return; | 339 if (!event.target.classList.contains("custom-select-option")) return; |
332 | 340 |
333 var IS_ENTER_KEY = event.key == "Enter" || event.keyCode == 13; | 341 var IS_ENTER_KEY = event.key == "Enter" || event.keyCode == 13; |
334 if (event.keyCode && !IS_ENTER_KEY) return; | 342 if (event.keyCode && !IS_ENTER_KEY) return; |
335 | 343 |
336 localStorage.removeItem(this.BROWSER_AUTODETECTED_STORAGE_KEY); | 344 localStorage.removeItem(this.BROWSER_AUTODETECTED_STORAGE_KEY); |
337 | 345 |
338 // Uncheck previously checked option | 346 // Uncheck previously checked option |
339 this.select | 347 this.select |
340 .querySelector("[aria-checked='true']") | 348 .querySelector("[aria-checked='true']") |
341 .setAttribute("aria-checked", "false"); | 349 .setAttribute("aria-checked", "false"); |
342 | 350 |
343 this.selectOption(event.target.getAttribute("data-value")); | 351 this.selectOption(event.target.getAttribute("data-value")); |
344 | 352 |
345 this.close(); | 353 this.close(); |
346 }; | 354 }; |
347 | 355 |
| 356 BrowserSelect.prototype._onClickNoContentMessage = function(event) |
| 357 { |
| 358 if (event.target.tagName != "BUTTON") return; |
| 359 |
| 360 var browser = event.target.parentElement.className; |
| 361 this.selectOption(browser); |
| 362 }; |
| 363 |
348 var browserSelect = document.getElementById("browser-select"); | 364 var browserSelect = document.getElementById("browser-select"); |
349 if (browserSelect) | 365 if (browserSelect) |
350 { | 366 { |
351 new BrowserSelect(browserSelect); | 367 new BrowserSelect(browserSelect); |
352 } | 368 } |
353 | 369 |
354 }, false); | 370 }, false); |
355 }()); | 371 }()); |
OLD | NEW |