Index: new-options.js |
=================================================================== |
--- a/new-options.js |
+++ b/new-options.js |
@@ -23,6 +23,7 @@ |
var filtersMap = Object.create(null); |
var collections = Object.create(null); |
var acceptableAdsUrl = null; |
+ var isCustomFiltersLoaded = false; |
var getMessage = ext.i18n.getMessage; |
var filterErrors = |
{ |
@@ -474,150 +475,164 @@ |
location.hash = id; |
} |
+ function execAction(action, key, element) |
+ { |
+ switch (action) |
+ { |
+ case "add-domain-exception": |
+ addWhitelistedDomain(); |
+ break; |
+ case "add-language-subscription": |
+ addEnableSubscription(findParentData(element, "access", false)); |
+ 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); |
+ closeDialog(); |
+ break; |
+ case "cancel-custom-filters": |
+ E("custom-filters").classList.remove("mode-edit"); |
+ break; |
+ case "cancel-domain-exception": |
+ E("whitelisting-textbox").value = ""; |
+ document.querySelector("#whitelisting .controls").classList.remove("mode-edit"); |
+ break; |
+ case "close-dialog": |
+ closeDialog(); |
+ break; |
+ case "edit-custom-filters": |
+ editCustomFilters(); |
+ break; |
+ case "edit-domain-exception": |
+ document.querySelector("#whitelisting .controls").classList.add("mode-edit"); |
+ E("whitelisting-textbox").focus(); |
+ break; |
+ case "import-subscription": |
+ var url = E("blockingList-textbox").value; |
+ addEnableSubscription(url); |
+ closeDialog(); |
+ break; |
+ case "open-context-menu": |
+ var listItem = findParentData(element, "access", true); |
+ if (listItem != context) |
+ listItem.classList.add("show-context-menu"); |
+ break; |
+ case "open-dialog": |
+ var dialog = findParentData(element, "dialog", false); |
+ openDialog(dialog); |
+ break; |
+ case "open-doclink": |
+ var doclink = findParentData(element, "doclink", false); |
+ openDocLink(doclink); |
+ break; |
+ case "remove-filter": |
+ ext.backgroundPage.sendMessage( |
+ { |
+ type: "filters.remove", |
+ text: findParentData(element, "access", false) |
+ }); |
+ break; |
+ case "remove-subscription": |
+ ext.backgroundPage.sendMessage( |
+ { |
+ type: "subscriptions.remove", |
+ url: findParentData(element, "access", false) |
+ }); |
+ break; |
+ case "save-custom-filters": |
+ sendMessageHandleErrors( |
+ { |
+ type: "filters.importRaw", |
+ text: E("custom-filters-raw").value, |
+ removeExisting: true |
+ }, |
+ function() |
+ { |
+ E("custom-filters").classList.remove("mode-edit"); |
+ }); |
+ break; |
+ case "switch-tab": |
+ if (key == "Enter") |
+ { |
+ var tabId = findParentData(element, "tab", false); |
+ switchTab(tabId); |
+ } |
+ else if (element.hasAttribute("aria-selected")) |
+ { |
+ if (key == "ArrowLeft" || key == "ArrowUp") |
+ { |
+ element = element.previousElementSibling |
+ || container.lastElementChild; |
+ } |
+ else if (key == "ArrowRight" || key == "ArrowDown") |
+ { |
+ element = element.nextElementSibling |
+ || container.firstElementChild; |
+ } |
+ |
+ var tabId = findParentData(element, "tab", false); |
+ switchTab(tabId); |
+ } |
+ break; |
+ case "toggle-disable-subscription": |
+ ext.backgroundPage.sendMessage( |
+ { |
+ type: "subscriptions.toggle", |
+ keepInstalled: true, |
+ url: findParentData(element, "access", false) |
+ }); |
+ break; |
+ case "toggle-pref": |
+ ext.backgroundPage.sendMessage( |
+ { |
+ type: "prefs.toggle", |
+ key: findParentData(element, "pref", false) |
+ }); |
+ break; |
+ case "toggle-remove-subscription": |
+ var subscriptionUrl = findParentData(element, "access", false); |
+ if (element.getAttribute("aria-checked") == "true") |
+ { |
+ ext.backgroundPage.sendMessage({ |
+ type: "subscriptions.remove", |
+ url: subscriptionUrl |
+ }); |
+ } |
+ else |
+ addEnableSubscription(subscriptionUrl); |
+ break; |
+ case "update-all-subscriptions": |
+ ext.backgroundPage.sendMessage( |
+ { |
+ type: "subscriptions.update" |
+ }); |
+ break; |
+ case "update-subscription": |
+ ext.backgroundPage.sendMessage( |
+ { |
+ type: "subscriptions.update", |
+ url: findParentData(element, "access", false) |
+ }); |
+ break; |
+ } |
+ } |
+ |
function onClick(e) |
{ |
var context = document.querySelector(".show-context-menu"); |
if (context) |
context.classList.remove("show-context-menu"); |
- var element = e.target; |
- while (true) |
- { |
- if (!element) |
- return; |
+ var actions = findParentData(e.target, "action", false); |
+ if (!actions) |
+ return; |
- if (element.hasAttribute("data-action")) |
- break; |
- |
- element = element.parentElement; |
- } |
- |
- var element = findParentData(e.target, "action", true); |
- var actions = element.getAttribute("data-action").split(","); |
+ actions = actions.split(","); |
for (var i = 0; i < actions.length; i++) |
{ |
- switch (actions[i]) |
- { |
- 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); |
- closeDialog(); |
- break; |
- case "cancel-custom-filters": |
- E("custom-filters").classList.remove("mode-edit"); |
- break; |
- case "cancel-domain-exception": |
- E("whitelisting-textbox").value = ""; |
- document.querySelector("#whitelisting .controls").classList.remove("mode-edit"); |
- break; |
- case "close-dialog": |
- closeDialog(); |
- break; |
- case "edit-custom-filters": |
- E("custom-filters").classList.add("mode-edit"); |
- editCustomFilters(); |
- break; |
- case "edit-domain-exception": |
- document.querySelector("#whitelisting .controls").classList.add("mode-edit"); |
- E("whitelisting-textbox").focus(); |
- break; |
- case "import-subscription": |
- var url = E("blockingList-textbox").value; |
- addEnableSubscription(url); |
- closeDialog(); |
- break; |
- case "open-dialog": |
- var dialog = findParentData(element, "dialog", false); |
- openDialog(dialog); |
- break; |
- case "open-doclink": |
- var doclink = findParentData(element, "doclink", false); |
- openDocLink(doclink); |
- break; |
- case "save-custom-filters": |
- sendMessageHandleErrors( |
- { |
- type: "filters.importRaw", |
- text: E("custom-filters-raw").value, |
- removeExisting: true |
- }, |
- function() |
- { |
- E("custom-filters").classList.remove("mode-edit"); |
- }); |
- break; |
- case "switch-tab": |
- var tabId = findParentData(e.target, "tab", false); |
- switchTab(tabId); |
- break; |
- case "toggle-pref": |
- ext.backgroundPage.sendMessage( |
- { |
- type: "prefs.toggle", |
- key: findParentData(element, "pref", false) |
- }); |
- break; |
- case "update-all-subscriptions": |
- ext.backgroundPage.sendMessage( |
- { |
- type: "subscriptions.update" |
- }); |
- break; |
- case "open-context-menu": |
- var listItem = findParentData(element, "access", true); |
- if (listItem != context) |
- listItem.classList.add("show-context-menu"); |
- break; |
- case "update-subscription": |
- ext.backgroundPage.sendMessage( |
- { |
- type: "subscriptions.update", |
- url: findParentData(element, "access", false) |
- }); |
- break; |
- case "remove-subscription": |
- ext.backgroundPage.sendMessage( |
- { |
- type: "subscriptions.remove", |
- url: findParentData(element, "access", false) |
- }); |
- break; |
- case "toggle-remove-subscription": |
- var subscriptionUrl = findParentData(element, "access", false); |
- if (element.getAttribute("aria-checked") == "true") |
- { |
- ext.backgroundPage.sendMessage({ |
- type: "subscriptions.remove", |
- url: subscriptionUrl |
- }); |
- } |
- else |
- addEnableSubscription(subscriptionUrl); |
- break; |
- case "toggle-disable-subscription": |
- ext.backgroundPage.sendMessage( |
- { |
- type: "subscriptions.toggle", |
- keepInstalled: true, |
- url: findParentData(element, "access", false) |
- }); |
- break; |
- case "add-language-subscription": |
- addEnableSubscription(findParentData(element, "access", false)); |
- break; |
- case "remove-filter": |
- ext.backgroundPage.sendMessage( |
- { |
- type: "filters.remove", |
- text: findParentData(element, "access", false) |
- }); |
- break; |
- } |
+ execAction(actions[i], "Enter", e.target); |
} |
} |
@@ -653,38 +668,10 @@ |
if (keys.indexOf(key) < 0) |
return; |
- switch (container.getAttribute("data-action")) |
+ var actions = container.getAttribute("data-action").split(","); |
+ for (var i = 0; i < actions.length; i++) |
{ |
- case "add-domain-exception": |
- addWhitelistedDomain(); |
- break; |
- case "open-doclink": |
- var doclink = findParentData(element, "doclink", false); |
- openDocLink(doclink); |
- break; |
- case "switch-tab": |
- if (key == "Enter") |
- { |
- var tabId = findParentData(element, "tab", false); |
- switchTab(tabId); |
- } |
- else if (element.hasAttribute("aria-selected")) |
- { |
- if (key == "ArrowLeft" || key == "ArrowUp") |
- { |
- element = element.previousElementSibling |
- || container.lastElementChild; |
- } |
- else if (key == "ArrowRight" || key == "ArrowDown") |
- { |
- element = element.nextElementSibling |
- || container.firstElementChild; |
- } |
- |
- var tabId = findParentData(element, "tab", false); |
- switchTab(tabId); |
- } |
- break; |
+ execAction(actions[i], key, element); |
} |
} |
@@ -957,6 +944,8 @@ |
{ |
for (var i = 0; i < filters.length; i++) |
updateFilter(filters[i]); |
+ |
+ isCustomFiltersLoaded = true; |
}); |
} |
}); |
@@ -1006,6 +995,10 @@ |
function editCustomFilters() |
{ |
+ if (!isCustomFiltersLoaded) |
+ return; |
+ |
+ E("custom-filters").classList.add("mode-edit"); |
var customFilterItems = collections.customFilters.items; |
var filterTexts = []; |
for (var i = 0; i < customFilterItems.length; i++) |