Index: static/js/main.js |
=================================================================== |
--- a/static/js/main.js |
+++ b/static/js/main.js |
@@ -230,38 +230,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]; |
juliandoucette
2017/12/11 15:15:28
NIT: Despite "Declare local variables as near to t
ire
2017/12/12 10:21:13
I'm not sure I understand where else this variable
juliandoucette
2017/12/12 12:30:31
Traditionally...
```
var name;
for (...) {
nam
ire
2017/12/13 10:30:18
Thanks for the suggestions. Responses:
On 2017/12
juliandoucette
2017/12/13 14:57:47
To avoid confusion about the scope of the variable
|
+ if (!document.querySelector(".platform-"+supportedBrowser)) |
juliandoucette
2017/12/11 15:15:28
NIT/TOL: querySelector supports selector groups e.
ire
2017/12/12 10:21:13
Thanks! I did know of selector groups but didn't t
juliandoucette
2017/12/12 12:30:31
If a selector in a selector group matches no resul
ire
2017/12/13 10:30:18
Ah I see! I think your solution is preferable. I m
juliandoucette
2017/12/13 14:57:47
Agreed.
|
+ { |
+ 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"); |
@@ -301,36 +320,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; |
@@ -341,16 +351,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"); |
juliandoucette
2017/12/11 15:15:28
NIT: Unnecessary variable.
this.selectOption(
e
ire
2017/12/12 10:21:13
Done.
|
+ this.selectOption(browser); |
+ }; |
+ |
var browserSelect = document.getElementById("browser-select"); |
if (browserSelect) |
{ |
new BrowserSelect(browserSelect); |
} |
}, false); |
}()); |