Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: static/src/js/main.js

Issue 29607560: Issue 6003 - Better handling of no-content-for-platform-message on help.eyeo.com (Closed) Base URL: https://hg.adblockplus.org/help.eyeo.com
Patch Set: Addressed NITs Created Dec. 12, 2017, 10:20 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | static/src/scss/components/_article.scss » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: static/src/js/main.js
===================================================================
--- a/static/src/js/main.js
+++ b/static/src/js/main.js
@@ -247,38 +247,58 @@
/**************************************************************************
* BrowserSelect
**************************************************************************/
function BrowserSelect(select)
{
this.select = select;
CustomSelect.apply(this, [this.select]);
+ this.noContentMessage = document.getElementById("no-content-for-platform-notice");
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 +338,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 +369,22 @@
.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;
+ this.selectOption(event.target.parentElement.getAttribute("data-value"));
+ };
+
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
+}());
« no previous file with comments | « no previous file | static/src/scss/components/_article.scss » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld