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

Unified Diff: options.js

Issue 29321417: Issue 2357 - Added "predefined list" dialog to options page (Closed)
Patch Set: Created July 14, 2015, 11:33 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 | « options.html ('k') | skin/options.css » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: options.js
===================================================================
--- a/options.js
+++ b/options.js
@@ -53,10 +53,10 @@
var text = item.title || item.url || item.text;
var listItem = document.createElement("li");
listItem.appendChild(document.importNode(template.content, true));
- listItem.dataset.access = item.url || item.text;
+ listItem.setAttribute("data-access", item.url || item.text);
listItem.querySelector(".display").textContent = text;
if (text)
- listItem.dataset.search = text.toLowerCase();
+ listItem.setAttribute("data-search", text.toLowerCase());
var control = listItem.querySelector(".control");
if (control)
@@ -105,7 +105,7 @@
function onToggleSubscriptionClick(e)
{
e.preventDefault();
- var subscriptionUrl = e.target.parentNode.dataset.access;
+ var subscriptionUrl = e.target.parentNode.getAttribute("data-access");
if (!e.target.checked)
removeSubscription(subscriptionUrl);
else
@@ -115,13 +115,13 @@
function onAddLanguageSubscriptionClick(e)
{
e.preventDefault();
- var url = this.parentNode.dataset.access;
+ var url = this.parentNode.getAttribute("data-access");
addEnableSubscription(url);
}
function onRemoveFilterClick()
{
- var filter = this.parentNode.dataset.access;
+ var filter = this.parentNode.getAttribute("data-access");
removeFilter(filter);
}
@@ -316,6 +316,56 @@
request.send(null);
}
+ function onClick(e)
+ {
+ var element = e.target;
+ while (true)
+ {
+ if (!element)
+ return;
+
+ if (element.hasAttribute("data-action"))
+ break;
+
+ element = element.parentElement;
+ }
+
+ switch (element.getAttribute("data-action"))
+ {
+ case "add-domain-exception":
+ addWhitelistedDomain();
+ break;
+ case "add-predefined-subscription":
+ var dialog = E("dialog-content-predefined");
+ var title = dialog.querySelector("h3").textContent;
+ var url = dialog.querySelector(".url").textContent;
+ addEnableSubscription(url, title);
+ document.body.removeAttribute("data-dialog");
+ break;
+ case "cancel-domain-exception":
+ E("whitelisting-textbox").value = "";
+ break;
+ case "close-dialog":
+ document.body.removeAttribute("data-dialog");
+ break;
+ case "edit-custom-filters":
+ editCustomFilters();
+ break;
+ case "import-subscription":
+ var url = E("blockingList-textbox").value;
+ addEnableSubscription(url);
+ document.body.removeAttribute("data-dialog");
+ break;
+ case "open-dialog":
+ openDialog(element.getAttribute("data-dialog"));
+ break;
+ case "switch-tab":
+ document.body.setAttribute("data-tab",
+ element.getAttribute("data-tab"));
+ break;
+ }
+ }
+
function onDOMLoaded()
{
var recommendationTemplate = document.querySelector("#recommend-list-table template");
@@ -327,15 +377,6 @@
populateLists();
- var tabList = document.querySelectorAll("#main-navigation-tabs li");
- for (var i = 0; i < tabList.length; i++)
- {
- tabList[i].addEventListener("click", function(e)
- {
- document.body.dataset.tab = e.currentTarget.dataset.show;
- }, false);
- }
-
function onFindLanguageKeyUp()
{
var searchStyle = E("search-style");
@@ -368,31 +409,10 @@
updateShareLink();
// Initialize interactive UI elements
+ document.body.addEventListener("click", onClick, false);
var placeholderValue = ext.i18n.getMessage("options_dialog_language_find");
E("find-language").setAttribute("placeholder", placeholderValue);
- E("add-blocking-list").addEventListener("click", function()
- {
- openDialog("customlist");
- }, false);
- E("add-website-language").addEventListener("click", function()
- {
- openDialog("language");
- }, false);
- E("dialog-close").addEventListener("click", function()
- {
- delete document.body.dataset.dialog;
- }, false);
- E("edit-ownBlockingList-button").addEventListener("click", editCustomFilters, false);
E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
- E("whitelisting").addEventListener("click", function(e)
- {
- var id = e.target.id;
- if (id == "whitelisting-add-icon" || id == "whitelisting-enter-icon")
- addWhitelistedDomain();
- else if (id == "whitelisting-cancel-button")
- E("whitelisting-textbox").value = "";
- }, false);
- E("whitelisting-add-button").addEventListener("click", addWhitelistedDomain, false);
E("whitelisting-textbox").addEventListener("keypress", function(e)
{
// e.keyCode has been deprecated so we attempt to use e.key
@@ -400,17 +420,11 @@
if ((e.key && e.key == "Enter") || (!e.key && e.keyCode == 13))
addWhitelistedDomain();
}, false);
- E("import-blockingList-button").addEventListener("click", function()
- {
- var url = E("blockingList-textbox").value;
- addEnableSubscription(url);
- delete document.body.dataset.dialog;
- }, false);
}
function openDialog(name)
{
- document.body.dataset.dialog = name;
+ document.body.setAttribute("data-dialog", name);
}
function populateLists()
@@ -604,12 +618,6 @@
}
}
- function showAddSubscriptionDialog(subscription)
- {
- E("blockingList-textbox").value = subscription.url;
- openDialog("customlist");
- }
-
function updateShareLink()
{
ext.backgroundPage.sendMessage(
@@ -647,7 +655,13 @@
{
case "app.listen":
if (message.action == "addSubscription")
- showAddSubscriptionDialog(message.args[0]);
+ {
+ var subscription = message.args[0];
+ var dialog = E("dialog-content-predefined");
+ dialog.querySelector("h3").textContent = subscription.title || "";
+ dialog.querySelector(".url").textContent = subscription.url;
+ openDialog("predefined");
+ }
break;
case "filters.listen":
onFilterMessage(message.action, message.args[0]);
« no previous file with comments | « options.html ('k') | skin/options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld