Index: static/src/js/main.js |
=================================================================== |
--- a/static/src/js/main.js |
+++ b/static/src/js/main.js |
@@ -247,38 +247,57 @@ |
/************************************************************************** |
* BrowserSelect |
**************************************************************************/ |
function BrowserSelect(select) |
{ |
this.select = select; |
CustomSelect.apply(this, [this.select]); |
+ this.noContentMessage = document.getElementById("no-content-for-platform-message"); |
this.BROWSER_STORAGE_KEY = "BROWSER"; |
this.BROWSER_AUTODETECTED_STORAGE_KEY = "BROWSER_AUTODETECTED"; |
this.SUPPORTED_BROWSERS = ["chrome", "opera", "samsungBrowser", |
"yandexbrowser", "maxthon", "msie", |
"msedge", "firefox", "ios", "safari"]; |
this.DEFAULT_BROWSER = "chrome"; |
+ this.setCurrentArticleSupportedBrowsers(); |
+ |
this.select |
.addEventListener("click", this._onClickOrKeyDown.bind(this), false); |
this.select |
.addEventListener("keydown", this._onClickOrKeyDown.bind(this), false); |
+ this.noContentMessage |
+ .addEventListener("click", this._onClickNoContentMessage.bind(this), false); |
+ |
var storedBrowser = localStorage.getItem(this.BROWSER_STORAGE_KEY); |
if (storedBrowser) this.selectOption(storedBrowser); |
else this.detectBrowser(); |
} |
BrowserSelect.prototype = Object.create(CustomSelect.prototype); |
BrowserSelect.prototype.constructor = BrowserSelect; |
+ BrowserSelect.prototype.setCurrentArticleSupportedBrowsers = function() |
+ { |
+ for (var i = 0; i < this.SUPPORTED_BROWSERS.length; i++) |
+ { |
+ var supportedBrowser = this.SUPPORTED_BROWSERS[i]; |
+ if (!document.querySelector(".platform-"+supportedBrowser)) |
+ { |
+ this.noContentMessage.querySelector("[data-value='" + supportedBrowser + "']") |
+ .setAttribute("hidden", "true"); |
+ } |
+ } |
+ }; |
+ |
BrowserSelect.prototype.detectBrowser = function() |
{ |
for (var i = 0; i < this.SUPPORTED_BROWSERS.length; i++) |
{ |
var supportedBrowser = this.SUPPORTED_BROWSERS[i]; |
if (bowser[supportedBrowser]) |
{ |
localStorage.setItem(this.BROWSER_AUTODETECTED_STORAGE_KEY, "true"); |
@@ -318,36 +337,27 @@ |
.getElementById("browser-select-autodetected") |
.innerHTML; |
selectedOption += "<span class='muted'>(" + autodetected + ")</span>"; |
} |
this.select |
.querySelector(".custom-select-selected") |
.innerHTML = selectedOption; |
- |
- if (!document.querySelector(".platform-" + browser)) |
+ |
+ if (document.querySelector(".platform-" + browser)) |
{ |
- this.handleNoContentForBrowser(browser); |
+ this.noContentMessage.setAttribute("hidden", "true"); |
+ } |
+ else |
+ { |
+ this.noContentMessage.removeAttribute("hidden"); |
} |
}; |
- BrowserSelect.prototype.handleNoContentForBrowser = function(browser) |
- { |
- var section = document.createElement("section"); |
- section.classList.add("platform-" + browser); |
- section.innerHTML = document |
- .getElementById("no-content-for-platform-message") |
- .innerHTML; |
- |
- document |
- .querySelector(".article-body") |
- .insertAdjacentElement("afterbegin", section); |
- } |
- |
BrowserSelect.prototype._onClickOrKeyDown = function(event) |
{ |
var option = event.target.closest(".custom-select-option"); |
if (!option) return; |
var IS_ENTER_KEY = event.key == "Enter" || event.keyCode == 13; |
if (event.keyCode && !IS_ENTER_KEY) return; |
@@ -358,21 +368,24 @@ |
.querySelector("[aria-checked='true']") |
.setAttribute("aria-checked", "false"); |
this.selectOption(option.getAttribute("data-value")); |
this.close(); |
}; |
+ BrowserSelect.prototype._onClickNoContentMessage = function(event) |
+ { |
+ if (event.target.tagName != "BUTTON") return; |
+ |
+ var browser = event.target.parentElement.getAttribute("data-value"); |
+ this.selectOption(browser); |
+ }; |
+ |
var browserSelect = document.getElementById("browser-select"); |
if (browserSelect) |
{ |
new BrowserSelect(browserSelect); |
} |
}, false); |
-}()); |
-//# sourceMappingURL=main.js.map |
- |
-//# sourceMappingURL=main-debug.js.map |
- |
-//# sourceMappingURL=main.js.map |
+}()); |