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

Unified Diff: new-options.js

Issue 29478597: Issue 5326 - General tab (HTML, strings and functionality) (Closed)
Patch Set: Created Aug. 16, 2017, 2:12 p.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
Index: new-options.js
===================================================================
--- a/new-options.js
+++ b/new-options.js
@@ -25,6 +25,7 @@
let filtersMap = Object.create(null);
let collections = Object.create(null);
let acceptableAdsUrl = null;
+ let acceptableAdsPrivacyUrl = null;
let isCustomFiltersLoaded = false;
let {getMessage} = ext.i18n;
let customFilters = [];
@@ -83,8 +84,6 @@
Collection.prototype._getItemTitle = function(item, i)
{
- if (item.url == acceptableAdsUrl)
- return getMessage("options_acceptableAds_description");
if (this.details[i].useOriginalTitle && item.originalTitle)
return item.originalTitle;
return item.title || item.url || item.text;
@@ -98,9 +97,9 @@
// disabled, but only be removed. That way it's grouped together with
// the "Own filter list" which cannot be disabled either at the bottom
// of the filter lists in the Advanced tab.
- if (a.url == acceptableAdsUrl)
+ if (isAcceptableAds(a.url))
return 1;
- if (b.url == acceptableAdsUrl)
+ if (isAcceptableAds(b.url))
return -1;
// Make sure that newly added entries always appear on top in descending
@@ -134,12 +133,19 @@
listItem.setAttribute("data-access", item.url || item.text);
listItem.setAttribute("role", "section");
- let label = listItem.querySelector(".display");
- if (item.recommended && label.hasAttribute("data-tooltip"))
+ let tooltip = listItem.querySelector("[data-tooltip]");
+ if (tooltip)
{
- let tooltipId = label.getAttribute("data-tooltip");
+ let tooltipId = tooltip.getAttribute("data-tooltip");
tooltipId = tooltipId.replace("%value%", item.recommended);
- label.setAttribute("data-tooltip", tooltipId);
+ if (getMessage(tooltipId))
+ {
+ tooltip.setAttribute("data-tooltip", tooltipId);
+ }
+ else
+ {
+ tooltip.parentNode.removeChild(tooltip);
+ }
}
for (let control of listItem.querySelectorAll(".control"))
@@ -214,7 +220,9 @@
continue;
let title = this._getItemTitle(item, i);
- element.querySelector(".display").textContent = title;
+ for (let displayElement of element.querySelectorAll(".display"))
Thomas Greiner 2017/08/16 17:57:09 According to https://developer.mozilla.org/en-US/d
saroyanm 2017/08/17 11:21:17 well spotted.
saroyanm 2017/08/17 21:24:07 Done.
+ displayElement.textContent = title;
+
element.setAttribute("aria-label", title);
if (this.details[i].searchable)
element.setAttribute("data-search", title.toLowerCase());
@@ -222,7 +230,7 @@
if (control)
{
control.setAttribute("aria-checked", item.disabled == false);
- if (item.url == acceptableAdsUrl && this == collections.filterLists)
+ if (isAcceptableAds(item.url) && this == collections.filterLists)
control.disabled = true;
}
@@ -330,31 +338,21 @@
return true;
}
- collections.popular = new Collection([
+ collections.security = new Collection([
{
- id: "recommend-list-table"
+ id: "recommend-security-list-table"
}
]);
collections.langs = new Collection([
{
id: "blocking-languages-table",
- emptyText: ["options_dialog_language_added_empty"]
- },
- {
- id: "blocking-languages-dialog-table",
- emptyText: ["options_dialog_language_added_empty"]
+ emptyText: ["options_language_empty"]
}
]);
collections.allLangs = new Collection([
{
- id: "all-lang-table",
- emptyText: ["options_dialog_language_other_empty"],
- searchable: true
- }
- ]);
- collections.acceptableAds = new Collection([
- {
- id: "acceptableads-table"
+ id: "all-lang-table-add",
+ emptyText: ["options_dialog_language_other_empty"]
}
]);
collections.custom = new Collection([
@@ -375,43 +373,41 @@
}
]);
- function toggleShowLanguage(subscription)
+ function addSubscription(subscription)
{
- if (subscription.recommended == "ads")
+ let collection = null;
+ if (subscription.recommended)
{
- if (subscription.disabled)
+ if (isProtection(subscription.recommended))
{
+ collection = collections.security;
Thomas Greiner 2017/08/16 17:57:10 Detail: The previous comments for this still appli
saroyanm 2017/08/17 21:24:07 Done.
+ }
+ else if (subscription.recommended == "ads")
+ {
+ if (subscription.disabled == false)
+ collection = collections.langs;
+
collections.allLangs.addItem(subscription);
- collections.langs.removeItem(subscription);
+ }
+ else if (subscription.disabled == false)
+ {
+ collection = collections.custom;
Thomas Greiner 2017/08/16 17:57:10 So we're still putting recommended subscriptions i
saroyanm 2017/08/17 11:21:19 Yes, because according to the subscription.xml "Ma
Thomas Greiner 2017/08/17 12:06:05 If they are in subscriptions.xml but are not suppo
saroyanm 2017/08/17 12:32:08 Is it the decision that we can make ? If so I'm
Thomas Greiner 2017/08/17 12:49:06 We are the ones who added them in the first place
saroyanm 2017/08/17 14:06:18 Thanks for clarifying that, in this case whole log
saroyanm 2017/08/17 21:24:05 Done.
}
else
Thomas Greiner 2017/08/16 17:57:09 This part of the if-statement is redundant because
saroyanm 2017/08/17 11:21:18 agree.
saroyanm 2017/08/17 21:24:05 Done.
{
- collections.allLangs.removeItem(subscription);
- collections.langs.addItem(subscription);
+ subscriptionsMap[subscription.url] = subscription;
+ return;
}
}
- }
+ else if (!isAcceptableAds(subscription.url))
+ {
+ collection = collections.custom;
+ }
- function addSubscription(subscription)
- {
- let collection;
- if (subscription.recommended)
- {
- if (subscription.recommended != "ads")
- collection = collections.popular;
- else if (subscription.disabled == false)
- collection = collections.langs;
- else
- collection = collections.allLangs;
- }
- else if (subscription.url == acceptableAdsUrl)
- collection = collections.acceptableAds;
- else
- collection = collections.custom;
+ if (collection)
+ collection.addItem(subscription);
- collection.addItem(subscription);
subscriptionsMap[subscription.url] = subscription;
- toggleShowLanguage(subscription);
updateTooltips();
}
@@ -420,7 +416,26 @@
for (let name in collections)
collections[name].updateItem(subscription);
- toggleShowLanguage(subscription);
+ if (subscription.recommended == "ads")
+ {
+ if (subscription.disabled)
+ collections.langs.removeItem(subscription);
+ else
+ collections.langs.addItem(subscription);
+ }
+ else if (!isProtection(subscription.recommended) &&
+ !isAcceptableAds(subscription.url))
+ {
+ if (subscription.disabled == false)
+ {
+ collections.custom.addItem(subscription);
Thomas Greiner 2017/08/16 17:57:09 Again, it seems like we're still putting recommend
saroyanm 2017/08/17 11:21:17 As, same as the comment above, the definition of t
saroyanm 2017/08/17 21:24:05 Done.
+ updateTooltips();
+ }
+ else
+ {
+ collections.custom.removeItem(subscription);
+ }
+ }
}
function updateFilter(filter)
@@ -561,6 +576,24 @@
case "cancel-custom-filters":
setCustomFiltersView("read");
break;
+ case "change-language-subscription":
+ for (let key in subscriptionsMap)
+ {
+ let subscription = subscriptionsMap[key];
+ let subscriptionType = subscription.recommended;
+ if (subscriptionType == "ads" && subscription.disabled == false)
+ {
+ ext.backgroundPage.sendMessage({
+ type: "subscriptions.remove",
+ url: subscription.url
+ });
+ ext.backgroundPage.sendMessage({
+ type: "subscriptions.add",
+ url: findParentData(element, "access", false)
+ });
+ }
Thomas Greiner 2017/08/16 17:57:10 Detail: Let's exit the loop as soon as we find the
saroyanm 2017/08/17 21:24:06 Done.
+ }
+ break;
case "close-dialog":
closeDialog();
break;
@@ -612,6 +645,36 @@
setCustomFiltersView("read");
});
break;
+ case "switch-acceptable-ads":
Thomas Greiner 2017/08/16 17:57:10 It's great that the code has been made more consis
saroyanm 2017/08/17 11:21:18 I think I missed the part of combining them into o
Thomas Greiner 2017/08/17 12:06:05 Your proposal is perfectly fine. :)
saroyanm 2017/08/17 21:24:04 Done.
+ ext.backgroundPage.sendMessage({
+ type: "subscriptions.remove",
+ url: acceptableAdsPrivacyUrl
+ });
+ ext.backgroundPage.sendMessage({
+ type: "subscriptions.add",
+ url: acceptableAdsUrl
+ });
+ break;
+ case "switch-privacy-acceptable-ads":
+ ext.backgroundPage.sendMessage({
+ type: "subscriptions.remove",
+ url: acceptableAdsUrl
+ });
+ ext.backgroundPage.sendMessage({
+ type: "subscriptions.add",
+ url: acceptableAdsPrivacyUrl
+ });
+ break;
+ case "switch-no-acceptable-ads":
+ ext.backgroundPage.sendMessage({
+ type: "subscriptions.remove",
+ url: acceptableAdsPrivacyUrl
+ });
+ ext.backgroundPage.sendMessage({
+ type: "subscriptions.remove",
+ url: acceptableAdsUrl
+ });
+ break;
case "switch-tab":
let tabId = findParentData(element, "tab", false);
switchTab(tabId);
@@ -788,17 +851,6 @@
function onDOMLoaded()
{
populateLists();
- function onFindLanguageKeyUp()
- {
- let searchStyle = E("search-style");
- if (!this.value)
- searchStyle.innerHTML = "";
- else
- {
- searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" +
- this.value.toLowerCase() + "\"]) { display: none; }";
- }
- }
// Initialize navigation sidebar
ext.backgroundPage.sendMessage({
@@ -820,9 +872,6 @@
// Initialize interactive UI elements
document.body.addEventListener("click", onClick, false);
document.body.addEventListener("keyup", onKeyUp, false);
- let placeholderValue = getMessage("options_dialog_language_find");
- E("find-language").setAttribute("placeholder", placeholderValue);
- E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
let exampleValue = getMessage("options_whitelist_placeholder_example",
["www.example.com"]);
E("whitelisting-textbox").setAttribute("placeholder", exampleValue);
@@ -831,6 +880,11 @@
E("whitelisting-add-button").disabled = !e.target.value;
}, false);
+ getDocLink("acceptable_ads_criteria", (link) =>
+ {
+ setLinks("enable-aa-description", link);
+ });
+
// Advanced tab
let customize = document.querySelectorAll("#customize li[data-pref]");
customize = Array.prototype.map.call(customize, (checkbox) =>
@@ -969,6 +1023,41 @@
focusedBeforeDialog.focus();
}
+ function setDntNotification(state)
+ {
+ if (state)
+ E("acceptable-ads").classList.add("show-dnt-notification");
+ else
+ E("acceptable-ads").classList.remove("show-dnt-notification");
+ }
+
+ function setAcceptableAds(option)
+ {
+ let optionsContainer = E("acceptable-ads");
+ switch (option)
+ {
+ case "default":
+ optionsContainer.querySelector("[value='ads']").checked = true;
+ break;
+ case "privacy":
+ optionsContainer.querySelector("[value='ads,privacy']").checked = true;
+ break;
+ case "none":
+ optionsContainer.querySelector("[value='none']").checked = true;
+ break;
+ }
+ }
+
+ function isAcceptableAds(url)
+ {
+ return url == acceptableAdsUrl || url == acceptableAdsPrivacyUrl;
+ }
+
+ function isProtection(type)
+ {
+ return type == "privacy" || type == "social";
+ }
+
function populateLists()
{
subscriptionsMap = Object.create(null);
@@ -1014,15 +1103,24 @@
disabled: true
});
- // Load user subscriptions
ext.backgroundPage.sendMessage({
- type: "subscriptions.get",
- downloadable: true
+ type: "prefs.get",
+ key: "subscriptions_exceptionsurl_privacy"
},
- (subscriptions) =>
+ (urlPrivacy) =>
{
- for (let subscription of subscriptions)
- onSubscriptionMessage("added", subscription);
+ acceptableAdsPrivacyUrl = urlPrivacy;
+
+ // Load user subscriptions
+ ext.backgroundPage.sendMessage({
+ type: "subscriptions.get",
+ downloadable: true
+ },
+ (subscriptions) =>
+ {
+ for (let subscription of subscriptions)
+ onSubscriptionMessage("added", subscription);
+ });
});
});
}
@@ -1130,14 +1228,33 @@
else
addSubscription(subscription);
+ if (subscription.url == acceptableAdsUrl)
+ setAcceptableAds("default");
Thomas Greiner 2017/08/16 17:57:10 We cannot determine the current state based on whi
saroyanm 2017/08/17 11:21:18 I agree. I'll update accordingly.
saroyanm 2017/08/17 21:24:04 Done.
+
+ if (subscription.url == acceptableAdsPrivacyUrl)
+ {
+ setAcceptableAds("privacy");
+ if (!navigator.doNotTrack)
+ setDntNotification(true);
+ }
+
collections.filterLists.addItem(subscription);
break;
case "removed":
- if (subscription.url == acceptableAdsUrl || subscription.recommended)
+ if (subscription.recommended == "ads" ||
+ isProtection(subscription.recommended))
{
subscription.disabled = true;
onSubscriptionMessage("disabled", subscription);
}
+ if (isAcceptableAds(subscription.url))
+ {
+ setAcceptableAds("none");
+ if (subscription.url == acceptableAdsPrivacyUrl)
+ {
+ setDntNotification(false);
+ }
+ }
else
{
collections.custom.removeItem(subscription);
Thomas Greiner 2017/08/16 17:57:09 Detail: Recommended subscriptions should not be in
saroyanm 2017/08/17 21:24:06 Done.
@@ -1232,20 +1349,6 @@
checkShareResource(sharedResource, onResult);
}
- function getMessages(id)
- {
- let messages = [];
- for (let i = 1; true; i++)
- {
- let message = ext.i18n.getMessage(id + "_" + i);
- if (!message)
- break;
-
- messages.push(message);
- }
- return messages;
- }
-
function updateTooltips()
{
let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]");
@@ -1258,52 +1361,12 @@
anchor.parentNode.replaceChild(wrapper, anchor);
wrapper.appendChild(anchor);
- let topTexts = getMessages(id);
- let bottomTexts = getMessages(id + "_notes");
-
- // We have to use native tooltips to avoid issues when attaching a tooltip
- // to an element in a scrollable list or otherwise it might get cut off
- if (anchor.hasAttribute("data-tooltip-native"))
- {
- let title = topTexts.concat(bottomTexts).join("\n\n");
- anchor.setAttribute("title", title);
- continue;
- }
-
let tooltip = document.createElement("div");
tooltip.setAttribute("role", "tooltip");
- let flip = anchor.getAttribute("data-tooltip-flip");
- if (flip)
- tooltip.className = "flip-" + flip;
-
- let imageSource = anchor.getAttribute("data-tooltip-image");
- if (imageSource)
- {
- let image = document.createElement("img");
- image.src = imageSource;
- image.alt = "";
- tooltip.appendChild(image);
- }
-
- for (let topText of topTexts)
- {
- let paragraph = document.createElement("p");
- paragraph.innerHTML = topText;
- tooltip.appendChild(paragraph);
- }
- if (bottomTexts.length > 0)
- {
- let notes = document.createElement("div");
- notes.className = "notes";
- for (let bottomText of bottomTexts)
- {
- let paragraph = document.createElement("p");
- paragraph.innerHTML = bottomText;
- notes.appendChild(paragraph);
- }
- tooltip.appendChild(notes);
- }
+ let paragraph = document.createElement("p");
+ paragraph.textContent = getMessage(id);
+ tooltip.appendChild(paragraph);
wrapper.appendChild(tooltip);
}
« locale/en-US/new-options.json ('K') | « new-options.html ('k') | skin/new-options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld