Index: new-options.js |
=================================================================== |
--- a/new-options.js |
+++ b/new-options.js |
@@ -37,6 +37,7 @@ |
["synchronize_checksum_mismatch", |
"options_filterList_lastDownload_checksumMismatch"] |
]); |
+ const timestampUI = Symbol(); |
function Collection(details) |
{ |
@@ -44,18 +45,25 @@ |
this.items = []; |
} |
- Collection.prototype._setEmpty = function(table, text) |
+ Collection.prototype._setEmpty = function(table, texts) |
{ |
- let placeholder = table.querySelector(".empty-placeholder"); |
- if (text && !placeholder) |
+ let placeholders = table.querySelectorAll(".empty-placeholder"); |
+ |
+ if (texts && placeholders.length == 0) |
{ |
- placeholder = document.createElement("li"); |
- placeholder.className = "empty-placeholder"; |
- placeholder.textContent = getMessage(text); |
- table.appendChild(placeholder); |
+ for (let text of texts) |
+ { |
+ let placeholder = document.createElement("li"); |
+ placeholder.className = "empty-placeholder"; |
+ placeholder.textContent = getMessage(text); |
+ table.appendChild(placeholder); |
+ } |
} |
- else if (placeholder) |
- table.removeChild(placeholder); |
+ else if (placeholders.length > 0) |
+ { |
+ for (let placeholder of placeholders) |
+ table.removeChild(placeholder); |
+ } |
}; |
Collection.prototype._createElementQuery = function(item) |
@@ -92,6 +100,10 @@ |
return 1; |
if (b.url == acceptableAdsUrl) |
return -1; |
+ if (a[timestampUI]) |
+ return b[timestampUI] ? b[timestampUI] - a[timestampUI] : -1; |
+ if (b[timestampUI]) |
+ return a[timestampUI] ? a[timestampUI] - b[timestampUI] : 1; |
Thomas Greiner
2017/05/26 11:10:39
This condition is duplicated and contradictory bec
Thomas Greiner
2017/05/26 11:10:40
Detail: Please add a comment as we did with the sp
saroyanm
2017/05/31 08:30:27
Done.
saroyanm
2017/05/31 08:30:28
Done.
|
let aTitle = this._getItemTitle(a, 0).toLowerCase(); |
let bTitle = this._getItemTitle(b, 0).toLowerCase(); |
@@ -197,7 +209,7 @@ |
{ |
control.setAttribute("aria-checked", item.disabled == false); |
if (item.url == acceptableAdsUrl && this == collections.filterLists) |
- control.setAttribute("disabled", true); |
+ control.disabled = true; |
} |
let dateElement = element.querySelector(".date"); |
@@ -285,17 +297,17 @@ |
collections.langs = new Collection([ |
{ |
id: "blocking-languages-table", |
- emptyText: "options_dialog_language_added_empty" |
+ emptyText: ["options_dialog_language_added_empty"] |
}, |
{ |
id: "blocking-languages-dialog-table", |
- emptyText: "options_dialog_language_added_empty" |
+ emptyText: ["options_dialog_language_added_empty"] |
} |
]); |
collections.allLangs = new Collection([ |
{ |
id: "all-lang-table", |
- emptyText: "options_dialog_language_other_empty", |
+ emptyText: ["options_dialog_language_other_empty"], |
searchable: true |
} |
]); |
@@ -312,13 +324,13 @@ |
collections.whitelist = new Collection([ |
{ |
id: "whitelisting-table", |
- emptyText: "options_whitelisted_empty" |
+ emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"] |
} |
]); |
collections.customFilters = new Collection([ |
{ |
id: "custom-filters-table", |
- emptyText: "options_customFilters_empty" |
+ emptyText: ["options_customFilters_empty"] |
} |
]); |
collections.filterLists = new Collection([ |
@@ -495,22 +507,12 @@ |
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": { |
let url = E("blockingList-textbox").value; |
addEnableSubscription(url); |
@@ -750,10 +752,25 @@ |
let placeholderValue = getMessage("options_dialog_language_find"); |
E("find-language").setAttribute("placeholder", placeholderValue); |
E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); |
- E("whitelisting-textbox").addEventListener("keypress", (e) => |
+ let exampleValue = getMessages("options_whitelist_placeholder_example", |
+ ["www.example.com"]); |
+ E("whitelisting-textbox").setAttribute("placeholder", exampleValue); |
+ E("whitelisting-textbox").addEventListener("keyup", (e) => |
{ |
+ let addWhitelistButton = E("whitelisting-add-button"); |
+ addWhitelistButton.disabled = false; |
if (getKey(e) == "Enter") |
- addWhitelistedDomain(); |
+ { |
+ if (!addWhitelistButton.disabled) |
+ addWhitelistedDomain(); |
+ } |
+ else |
+ { |
+ if (!e.target.value) |
+ { |
+ addWhitelistButton.disabled = true; |
Thomas Greiner
2017/05/26 11:10:39
Detail: Now that we reduced it to a simple check,
saroyanm
2017/05/31 08:30:27
Done.
|
+ } |
+ } |
}, false); |
// Advanced tab |
@@ -962,6 +979,16 @@ |
function addWhitelistedDomain() |
{ |
let domain = E("whitelisting-textbox"); |
+ for (let whitelistItem of collections.whitelist.items) |
+ { |
+ if (whitelistItem.title == domain.value) |
+ { |
+ collections.whitelist.removeItem(whitelistItem); |
+ whitelistItem[timestampUI] = Date.now(); |
+ collections.whitelist.addItem(whitelistItem); |
Thomas Greiner
2017/05/26 11:10:40
Removing and then adding the item again is quite a
saroyanm
2017/05/30 12:30:43
I agree with you.
The problem is that we are curr
saroyanm
2017/05/31 08:30:27
Done.
|
+ domain.value = ""; |
Thomas Greiner
2017/05/26 11:10:39
No need to continue the loop because we already fo
saroyanm
2017/05/31 08:30:27
Done.
|
+ } |
+ } |
if (domain.value) |
{ |
sendMessageHandleErrors({ |
@@ -971,8 +998,7 @@ |
} |
domain.value = ""; |
- document.querySelector("#whitelisting .controls") |
- .classList.remove("mode-edit"); |
+ E("whitelisting-add-button").disabled = true; |
} |
function editCustomFilters() |