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

Side by Side Diff: lib/ui.js

Issue 6305806509146112: Issue 427 - Remove non-standard function and getter syntax (Closed)
Patch Set: Created May 5, 2014, 12:18 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/synchronizer.js ('k') | lib/utils.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return; 119 return;
120 } 120 }
121 121
122 setChecked("adblockplus-savestats", Prefs.savestats); 122 setChecked("adblockplus-savestats", Prefs.savestats);
123 addCommandHandler("adblockplus-savestats", function() 123 addCommandHandler("adblockplus-savestats", function()
124 { 124 {
125 UI.toggleSaveStats(doc.defaultView); 125 UI.toggleSaveStats(doc.defaultView);
126 this.value = Prefs.savestats; 126 this.value = Prefs.savestats;
127 }); 127 });
128 128
129 let hasAcceptableAds = FilterStorage.subscriptions.some(function(subscript ion) subscription instanceof DownloadableSubscription && subscription.url == Pre fs.subscriptions_exceptionsurl); 129 let hasAcceptableAds = FilterStorage.subscriptions.some(function(subscript ion) {
130 return (subscription instanceof DownloadableSubscription &&
131 subscription.url == Prefs.subscriptions_exceptionsurl);
132 });
130 setChecked("adblockplus-acceptableAds", hasAcceptableAds); 133 setChecked("adblockplus-acceptableAds", hasAcceptableAds);
131 addCommandHandler("adblockplus-acceptableAds", function() 134 addCommandHandler("adblockplus-acceptableAds", function()
132 { 135 {
133 this.value = UI.toggleAcceptableAds(); 136 this.value = UI.toggleAcceptableAds();
134 }); 137 });
135 138
136 setChecked("adblockplus-sync", syncEngine && syncEngine.enabled); 139 setChecked("adblockplus-sync", syncEngine && syncEngine.enabled);
137 addCommandHandler("adblockplus-sync", function() 140 addCommandHandler("adblockplus-sync", function()
138 { 141 {
139 this.value = UI.toggleSync(); 142 this.value = UI.toggleSync();
(...skipping 11 matching lines...) Expand all
151 { 154 {
152 // Load subscriptions data 155 // Load subscriptions data
153 let request = new XMLHttpRequest(); 156 let request = new XMLHttpRequest();
154 request.mozBackgroundRequest = true; 157 request.mozBackgroundRequest = true;
155 request.open("GET", "chrome://adblockplus/content/ui/subscriptions.xml") ; 158 request.open("GET", "chrome://adblockplus/content/ui/subscriptions.xml") ;
156 request.addEventListener("load", function() 159 request.addEventListener("load", function()
157 { 160 {
158 if (onShutdown.done) 161 if (onShutdown.done)
159 return; 162 return;
160 163
161 let currentSubscription = FilterStorage.subscriptions.filter( 164 let currentSubscription = FilterStorage.subscriptions.filter(function( subscription) {
162 function(subscription) subscription instanceof DownloadableSubscript ion && subscription.url != Prefs.subscriptions_exceptionsurl 165 return (subscription instanceof DownloadableSubscription &&
163 ); 166 subscription.url != Prefs.subscriptions_exceptionsurl);
167 });
164 currentSubscription = (currentSubscription.length ? currentSubscriptio n[0] : null); 168 currentSubscription = (currentSubscription.length ? currentSubscriptio n[0] : null);
165 169
166 let subscriptions =request.responseXML.getElementsByTagName("subscript ion"); 170 let subscriptions =request.responseXML.getElementsByTagName("subscript ion");
167 for (let i = 0; i < subscriptions.length; i++) 171 for (let i = 0; i < subscriptions.length; i++)
168 { 172 {
169 let item = subscriptions[i]; 173 let item = subscriptions[i];
170 let url = item.getAttribute("url"); 174 let url = item.getAttribute("url");
171 if (!url) 175 if (!url)
172 continue; 176 continue;
173 177
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 { 336 {
333 Utils.splitAllLabels(root); 337 Utils.splitAllLabels(root);
334 338
335 let specialElements = {"abp-status-popup": true, "abp-status": true, "abp-to olbarbutton": true, "abp-menuitem": true, "abp-bottombar-container": true}; 339 let specialElements = {"abp-status-popup": true, "abp-status": true, "abp-to olbarbutton": true, "abp-menuitem": true, "abp-bottombar-container": true};
336 340
337 this.overlay = {all: []}; 341 this.overlay = {all: []};
338 342
339 // Remove whitespace text nodes 343 // Remove whitespace text nodes
340 let walker = root.ownerDocument.createTreeWalker( 344 let walker = root.ownerDocument.createTreeWalker(
341 root, Ci.nsIDOMNodeFilter.SHOW_TEXT, 345 root, Ci.nsIDOMNodeFilter.SHOW_TEXT,
342 function(node) !/\S/.test(node.nodeValue), false 346 function(node) { return !/\S/.test(node.nodeValue) }, false
343 ); 347 );
344 let whitespaceNodes = []; 348 let whitespaceNodes = [];
345 while (walker.nextNode()) 349 while (walker.nextNode())
346 whitespaceNodes.push(walker.currentNode); 350 whitespaceNodes.push(walker.currentNode);
347 351
348 for (let i = 0; i < whitespaceNodes.length; i++) 352 for (let i = 0; i < whitespaceNodes.length; i++)
349 whitespaceNodes[i].parentNode.removeChild(whitespaceNodes[i]); 353 whitespaceNodes[i].parentNode.removeChild(whitespaceNodes[i]);
350 354
351 // Put overlay elements into appropriate fields 355 // Put overlay elements into appropriate fields
352 while (root.firstElementChild) 356 while (root.firstElementChild)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 }.bind(this)); 456 }.bind(this));
453 FilterNotifier.addListener(function(action) 457 FilterNotifier.addListener(function(action)
454 { 458 {
455 if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(actio n) || action == "load") 459 if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(actio n) || action == "load")
456 this.updateState(); 460 this.updateState();
457 }.bind(this)); 461 }.bind(this));
458 462
459 notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); 463 notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
460 notificationTimer.initWithCallback(this.showNextNotification.bind(this), 464 notificationTimer.initWithCallback(this.showNextNotification.bind(this),
461 3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT) ; 465 3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT) ;
462 onShutdown.add(function() notificationTimer.cancel()); 466 onShutdown.add(function() { notificationTimer.cancel(); });
463 467
464 // Add "anti-adblock messages" notification 468 // Add "anti-adblock messages" notification
465 initAntiAdblockNotification(); 469 initAntiAdblockNotification();
466 470
467 let documentCreationObserver = { 471 let documentCreationObserver = {
468 observe: function(subject, topic, data) 472 observe: function(subject, topic, data)
469 { 473 {
470 if (!(subject instanceof Ci.nsIDOMWindow)) 474 if (!(subject instanceof Ci.nsIDOMWindow))
471 return; 475 return;
472 476
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 let addAcceptable = (Services.vc.compare(prevVersion, "2.0") < 0); 762 let addAcceptable = (Services.vc.compare(prevVersion, "2.0") < 0);
759 let privacySubscriptions = { 763 let privacySubscriptions = {
760 "https://easylist-downloads.adblockplus.org/easyprivacy+easylist.txt": tru e, 764 "https://easylist-downloads.adblockplus.org/easyprivacy+easylist.txt": tru e,
761 "https://easylist-downloads.adblockplus.org/easyprivacy.txt": true, 765 "https://easylist-downloads.adblockplus.org/easyprivacy.txt": true,
762 "https://secure.fanboy.co.nz/fanboy-tracking.txt": true, 766 "https://secure.fanboy.co.nz/fanboy-tracking.txt": true,
763 "https://fanboy-adblock-list.googlecode.com/hg/fanboy-adblocklist-stats.tx t": true, 767 "https://fanboy-adblock-list.googlecode.com/hg/fanboy-adblocklist-stats.tx t": true,
764 "https://bitbucket.org/fanboy/fanboyadblock/raw/tip/fanboy-adblocklist-sta ts.txt": true, 768 "https://bitbucket.org/fanboy/fanboyadblock/raw/tip/fanboy-adblocklist-sta ts.txt": true,
765 "https://hg01.codeplex.com/fanboyadblock/raw-file/tip/fanboy-adblocklist-s tats.txt": true, 769 "https://hg01.codeplex.com/fanboyadblock/raw-file/tip/fanboy-adblocklist-s tats.txt": true,
766 "https://adversity.googlecode.com/hg/Adversity-Tracking.txt": true 770 "https://adversity.googlecode.com/hg/Adversity-Tracking.txt": true
767 }; 771 };
768 if (FilterStorage.subscriptions.some(function(subscription) subscription.url == Prefs.subscriptions_exceptionsurl || subscription.url in privacySubscription s)) 772 if (FilterStorage.subscriptions.some(function(subscription) {
773 return (subscription.url == Prefs.subscriptions_exceptionsurl ||
774 subscription.url in privacySubscriptions);
775 }))
769 addAcceptable = false; 776 addAcceptable = false;
770 777
771 // Don't add subscription if the user has a subscription already 778 // Don't add subscription if the user has a subscription already
772 let addSubscription = true; 779 let addSubscription = true;
773 if (FilterStorage.subscriptions.some(function(subscription) subscription ins tanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exce ptionsurl)) 780 if (FilterStorage.subscriptions.some(function(subscription) {
781 return (subscription instanceof DownloadableSubscription &&
782 subscription.url != Prefs.subscriptions_exceptionsurl);
783 }))
774 addSubscription = false; 784 addSubscription = false;
775 785
776 // If this isn't the first run, only add subscription if the user has no cus tom filters 786 // If this isn't the first run, only add subscription if the user has no cus tom filters
777 if (addSubscription && Services.vc.compare(prevVersion, "0.0") > 0) 787 if (addSubscription && Services.vc.compare(prevVersion, "0.0") > 0)
778 { 788 {
779 if (FilterStorage.subscriptions.some(function(subscription) subscription.u rl != Prefs.subscriptions_exceptionsurl && subscription.filters.length)) 789 if (FilterStorage.subscriptions.some(function(subscription) {
790 return (subscription.url != Prefs.subscriptions_exceptionsurl &&
791 subscription.filters.length);
792 }))
780 addSubscription = false; 793 addSubscription = false;
781 } 794 }
782 795
783 // Add "acceptable ads" subscription 796 // Add "acceptable ads" subscription
784 if (addAcceptable) 797 if (addAcceptable)
785 { 798 {
786 let subscription = Subscription.fromURL(Prefs.subscriptions_exceptionsurl) ; 799 let subscription = Subscription.fromURL(Prefs.subscriptions_exceptionsurl) ;
787 if (subscription) 800 if (subscription)
788 { 801 {
789 subscription.title = "Allow non-intrusive advertising"; 802 subscription.title = "Allow non-intrusive advertising";
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 Prefs[pref] = !Prefs[pref]; 1142 Prefs[pref] = !Prefs[pref];
1130 }, 1143 },
1131 1144
1132 /** 1145 /**
1133 * If the given filter is already in user's list, removes it from the list. Ot herwise adds it. 1146 * If the given filter is already in user's list, removes it from the list. Ot herwise adds it.
1134 */ 1147 */
1135 toggleFilter: function(/**Filter*/ filter) 1148 toggleFilter: function(/**Filter*/ filter)
1136 { 1149 {
1137 if (filter.subscriptions.length) 1150 if (filter.subscriptions.length)
1138 { 1151 {
1139 if (filter.disabled || filter.subscriptions.some(function(subscription) !( subscription instanceof SpecialSubscription))) 1152 if (filter.disabled || filter.subscriptions.some(function(subscription) {
1153 return !(subscription instanceof SpecialSubscription);
1154 }))
1140 filter.disabled = !filter.disabled; 1155 filter.disabled = !filter.disabled;
1141 else 1156 else
1142 FilterStorage.removeFilter(filter); 1157 FilterStorage.removeFilter(filter);
1143 } 1158 }
1144 else 1159 else
1145 FilterStorage.addFilter(filter); 1160 FilterStorage.addFilter(filter);
1146 }, 1161 },
1147 1162
1148 1163
1149 /** 1164 /**
(...skipping 14 matching lines...) Expand all
1164 Prefs.savestats = true; 1179 Prefs.savestats = true;
1165 }, 1180 },
1166 1181
1167 /** 1182 /**
1168 * Sets the current filter subscription in a single-subscription scenario, 1183 * Sets the current filter subscription in a single-subscription scenario,
1169 * all other subscriptions will be removed. 1184 * all other subscriptions will be removed.
1170 */ 1185 */
1171 setSubscription: function(url, title) 1186 setSubscription: function(url, title)
1172 { 1187 {
1173 let subscription = Subscription.fromURL(url); 1188 let subscription = Subscription.fromURL(url);
1174 let currentSubscriptions = FilterStorage.subscriptions.filter( 1189 let currentSubscriptions = FilterStorage.subscriptions.filter(function(subsc ription) {
1175 function(subscription) subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsurl 1190 return (subscription instanceof DownloadableSubscription &&
1176 ); 1191 subscription.url != Prefs.subscriptions_exceptionsurl);
1192 });
1177 if (!subscription || currentSubscriptions.indexOf(subscription) >= 0) 1193 if (!subscription || currentSubscriptions.indexOf(subscription) >= 0)
1178 return; 1194 return;
1179 1195
1180 for (let i = 0; i < currentSubscriptions.length; i++) 1196 for (let i = 0; i < currentSubscriptions.length; i++)
1181 FilterStorage.removeSubscription(currentSubscriptions[i]); 1197 FilterStorage.removeSubscription(currentSubscriptions[i]);
1182 1198
1183 subscription.title = title; 1199 subscription.title = title;
1184 FilterStorage.addSubscription(subscription); 1200 FilterStorage.addSubscription(subscription);
1185 if (subscription instanceof DownloadableSubscription && !subscription.lastDo wnload) 1201 if (subscription instanceof DownloadableSubscription && !subscription.lastDo wnload)
1186 Synchronizer.execute(subscription); 1202 Synchronizer.execute(subscription);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 return true; 1325 return true;
1310 } 1326 }
1311 return false; 1327 return false;
1312 }, 1328 },
1313 1329
1314 /** 1330 /**
1315 * Updates state of the icon tooltip. 1331 * Updates state of the icon tooltip.
1316 */ 1332 */
1317 fillIconTooltip: function(/**Event*/ event, /**Window*/ window) 1333 fillIconTooltip: function(/**Event*/ event, /**Window*/ window)
1318 { 1334 {
1319 function E(id) window.document.getElementById(id); 1335 function E(id) {
1336 return window.document.getElementById(id);
1337 }
1320 1338
1321 let node = window.document.tooltipNode; 1339 let node = window.document.tooltipNode;
1322 if (!node || !node.hasAttribute("tooltip")) 1340 if (!node || !node.hasAttribute("tooltip"))
1323 { 1341 {
1324 event.preventDefault(); 1342 event.preventDefault();
1325 return; 1343 return;
1326 } 1344 }
1327 1345
1328 // Prevent tooltip from overlapping menu 1346 // Prevent tooltip from overlapping menu
1329 for (let id of ["abp-toolbar-popup", "abp-status-popup"]) 1347 for (let id of ["abp-toolbar-popup", "abp-status-popup"])
(...skipping 17 matching lines...) Expand all
1347 actionDescr.setAttribute("value", Utils.getString("action" + action + "_to oltip")); 1365 actionDescr.setAttribute("value", Utils.getString("action" + action + "_to oltip"));
1348 1366
1349 let statusDescr = E("abp-tooltip-status"); 1367 let statusDescr = E("abp-tooltip-status");
1350 let state = node.getAttribute("abpstate"); 1368 let state = node.getAttribute("abpstate");
1351 let statusStr = Utils.getString(state + "_tooltip"); 1369 let statusStr = Utils.getString(state + "_tooltip");
1352 if (state == "active") 1370 if (state == "active")
1353 { 1371 {
1354 let [activeSubscriptions, activeFilters] = FilterStorage.subscriptions.red uce(function([subscriptions, filters], current) 1372 let [activeSubscriptions, activeFilters] = FilterStorage.subscriptions.red uce(function([subscriptions, filters], current)
1355 { 1373 {
1356 if (current instanceof SpecialSubscription) 1374 if (current instanceof SpecialSubscription)
1357 return [subscriptions, filters + current.filters.filter(function(filte r) !filter.disabled).length]; 1375 return [subscriptions, filters + current.filters.filter(function(filte r) { return !filter.disabled; }).length];
1358 else if (!current.disabled && !(Prefs.subscriptions_exceptionscheckbox & & current.url == Prefs.subscriptions_exceptionsurl)) 1376 else if (!current.disabled && !(Prefs.subscriptions_exceptionscheckbox & & current.url == Prefs.subscriptions_exceptionsurl))
1359 return [subscriptions + 1, filters]; 1377 return [subscriptions + 1, filters];
1360 else 1378 else
1361 return [subscriptions, filters] 1379 return [subscriptions, filters]
1362 }, [0, 0]); 1380 }, [0, 0]);
1363 1381
1364 statusStr = statusStr.replace(/\?1\?/, activeSubscriptions).replace(/\?2\? /, activeFilters); 1382 statusStr = statusStr.replace(/\?1\?/, activeSubscriptions).replace(/\?2\? /, activeFilters);
1365 } 1383 }
1366 statusDescr.setAttribute("value", statusStr); 1384 statusDescr.setAttribute("value", statusStr);
1367 1385
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1917 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], 1935 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)],
1918 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] 1936 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)]
1919 ]; 1937 ];
1920 1938
1921 onShutdown.add(function() 1939 onShutdown.add(function()
1922 { 1940 {
1923 for (let window in UI.applicationWindows) 1941 for (let window in UI.applicationWindows)
1924 if (UI.isBottombarOpen(window)) 1942 if (UI.isBottombarOpen(window))
1925 UI.toggleBottombar(window); 1943 UI.toggleBottombar(window);
1926 }); 1944 });
OLDNEW
« no previous file with comments | « lib/synchronizer.js ('k') | lib/utils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld