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

Unified Diff: lib/ui.js

Issue 6305806509146112: Issue 427 - Remove non-standard function and getter syntax (Closed)
Patch Set: Convert shorthand function expressions to arrow functions, this of course isn't possible for getter… Created May 10, 2014, 12:43 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: lib/ui.js
===================================================================
--- a/lib/ui.js
+++ b/lib/ui.js
@@ -121,17 +121,18 @@ let optionsObserver =
setChecked("adblockplus-savestats", Prefs.savestats);
addCommandHandler("adblockplus-savestats", function()
{
UI.toggleSaveStats(doc.defaultView);
this.value = Prefs.savestats;
});
- let hasAcceptableAds = FilterStorage.subscriptions.some(function(subscription) subscription instanceof DownloadableSubscription && subscription.url == Prefs.subscriptions_exceptionsurl);
+ let hasAcceptableAds = FilterStorage.subscriptions.some((subscription) => subscription instanceof DownloadableSubscription
+ && subscription.url == Prefs.subscriptions_exceptionsurl);
Wladimir Palant 2014/05/15 07:12:38 It should be either operator on new line (like her
setChecked("adblockplus-acceptableAds", hasAcceptableAds);
addCommandHandler("adblockplus-acceptableAds", function()
{
this.value = UI.toggleAcceptableAds();
});
setChecked("adblockplus-sync", syncEngine && syncEngine.enabled);
addCommandHandler("adblockplus-sync", function()
@@ -153,19 +154,18 @@ let optionsObserver =
let request = new XMLHttpRequest();
request.mozBackgroundRequest = true;
request.open("GET", "chrome://adblockplus/content/ui/subscriptions.xml");
request.addEventListener("load", function()
{
if (onShutdown.done)
return;
- let currentSubscription = FilterStorage.subscriptions.filter(
- function(subscription) subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsurl
- );
+ let currentSubscription = FilterStorage.subscriptions.filter((subscription) => subscription instanceof DownloadableSubscription &&
+ subscription.url != Prefs.subscriptions_exceptionsurl);
currentSubscription = (currentSubscription.length ? currentSubscription[0] : null);
let subscriptions =request.responseXML.getElementsByTagName("subscription");
for (let i = 0; i < subscriptions.length; i++)
{
let item = subscriptions[i];
let url = item.getAttribute("url");
if (!url)
@@ -334,17 +334,17 @@ let UI = exports.UI =
let specialElements = {"abp-status-popup": true, "abp-status": true, "abp-toolbarbutton": true, "abp-menuitem": true, "abp-bottombar-container": true};
this.overlay = {all: []};
// Remove whitespace text nodes
let walker = root.ownerDocument.createTreeWalker(
root, Ci.nsIDOMNodeFilter.SHOW_TEXT,
- function(node) !/\S/.test(node.nodeValue), false
+ (node) => !/\S/.test(node.nodeValue), false
);
let whitespaceNodes = [];
while (walker.nextNode())
whitespaceNodes.push(walker.currentNode);
for (let i = 0; i < whitespaceNodes.length; i++)
whitespaceNodes[i].parentNode.removeChild(whitespaceNodes[i]);
@@ -454,17 +454,17 @@ let UI = exports.UI =
{
if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(action) || action == "load")
this.updateState();
}.bind(this));
notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
notificationTimer.initWithCallback(this.showNextNotification.bind(this),
3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT);
- onShutdown.add(function() notificationTimer.cancel());
+ onShutdown.add(() => notificationTimer.cancel());
// Add "anti-adblock messages" notification
initAntiAdblockNotification();
let documentCreationObserver = {
observe: function(subject, topic, data)
{
if (!(subject instanceof Ci.nsIDOMWindow))
@@ -760,28 +760,28 @@ let UI = exports.UI =
"https://easylist-downloads.adblockplus.org/easyprivacy+easylist.txt": true,
"https://easylist-downloads.adblockplus.org/easyprivacy.txt": true,
"https://secure.fanboy.co.nz/fanboy-tracking.txt": true,
"https://fanboy-adblock-list.googlecode.com/hg/fanboy-adblocklist-stats.txt": true,
"https://bitbucket.org/fanboy/fanboyadblock/raw/tip/fanboy-adblocklist-stats.txt": true,
"https://hg01.codeplex.com/fanboyadblock/raw-file/tip/fanboy-adblocklist-stats.txt": true,
"https://adversity.googlecode.com/hg/Adversity-Tracking.txt": true
};
- if (FilterStorage.subscriptions.some(function(subscription) subscription.url == Prefs.subscriptions_exceptionsurl || subscription.url in privacySubscriptions))
+ if (FilterStorage.subscriptions.some(subscription => subscription.url == Prefs.subscriptions_exceptionsurl || subscription.url in privacySubscriptions))
Wladimir Palant 2014/05/15 07:12:38 According to https://developer.mozilla.org/en/docs
addAcceptable = false;
// Don't add subscription if the user has a subscription already
let addSubscription = true;
- if (FilterStorage.subscriptions.some(function(subscription) subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsurl))
+ if (FilterStorage.subscriptions.some(subscription => subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsurl))
addSubscription = false;
// If this isn't the first run, only add subscription if the user has no custom filters
if (addSubscription && Services.vc.compare(prevVersion, "0.0") > 0)
{
- if (FilterStorage.subscriptions.some(function(subscription) subscription.url != Prefs.subscriptions_exceptionsurl && subscription.filters.length))
+ if (FilterStorage.subscriptions.some(subscription => subscription.url != Prefs.subscriptions_exceptionsurl && subscription.filters.length))
addSubscription = false;
}
// Add "acceptable ads" subscription
if (addAcceptable)
{
let subscription = Subscription.fromURL(Prefs.subscriptions_exceptionsurl);
if (subscription)
@@ -1134,17 +1134,17 @@ let UI = exports.UI =
/**
* If the given filter is already in user's list, removes it from the list. Otherwise adds it.
*/
toggleFilter: function(/**Filter*/ filter)
{
if (filter.subscriptions.length)
{
- if (filter.disabled || filter.subscriptions.some(function(subscription) !(subscription instanceof SpecialSubscription)))
+ if (filter.disabled || filter.subscriptions.some(subscription => !(subscription instanceof SpecialSubscription)))
filter.disabled = !filter.disabled;
else
FilterStorage.removeFilter(filter);
}
else
FilterStorage.addFilter(filter);
},
@@ -1170,17 +1170,17 @@ let UI = exports.UI =
/**
* Sets the current filter subscription in a single-subscription scenario,
* all other subscriptions will be removed.
*/
setSubscription: function(url, title)
{
let subscription = Subscription.fromURL(url);
let currentSubscriptions = FilterStorage.subscriptions.filter(
- function(subscription) subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsurl
+ subscription => subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsurl
);
if (!subscription || currentSubscriptions.indexOf(subscription) >= 0)
return;
for (let i = 0; i < currentSubscriptions.length; i++)
FilterStorage.removeSubscription(currentSubscriptions[i]);
subscription.title = title;
@@ -1314,17 +1314,17 @@ let UI = exports.UI =
return false;
},
/**
* Updates state of the icon tooltip.
*/
fillIconTooltip: function(/**Event*/ event, /**Window*/ window)
{
- function E(id) window.document.getElementById(id);
+ let E = id => window.document.getElementById(id);
let node = window.document.tooltipNode;
if (!node || !node.hasAttribute("tooltip"))
{
event.preventDefault();
return;
}
@@ -1352,17 +1352,17 @@ let UI = exports.UI =
let statusDescr = E("abp-tooltip-status");
let state = node.getAttribute("abpstate");
let statusStr = Utils.getString(state + "_tooltip");
if (state == "active")
{
let [activeSubscriptions, activeFilters] = FilterStorage.subscriptions.reduce(function([subscriptions, filters], current)
{
if (current instanceof SpecialSubscription)
- return [subscriptions, filters + current.filters.filter(function(filter) !filter.disabled).length];
+ return [subscriptions, filters + current.filters.filter(filter => !filter.disabled).length];
else if (!current.disabled && !(Prefs.subscriptions_exceptionscheckbox && current.url == Prefs.subscriptions_exceptionsurl))
return [subscriptions + 1, filters];
else
return [subscriptions, filters]
}, [0, 0]);
statusStr = statusStr.replace(/\?1\?/, activeSubscriptions).replace(/\?2\?/, activeFilters);
}
« lib/subscriptionClasses.js ('K') | « lib/synchronizer.js ('k') | lib/utils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld