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

Side by Side Diff: background.js

Issue 29338734: Issue 3839 - Adapt for Prefs event changes (Closed)
Patch Set: Created March 21, 2016, 4:17 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 | « no previous file | messageResponder.js » ('j') | messageResponder.js » ('J')
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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 }, 86 },
87 get appLocale() 87 get appLocale()
88 { 88 {
89 return parent.ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); 89 return parent.ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-");
90 } 90 }
91 } 91 }
92 }; 92 };
93 93
94 modules.prefs = { 94 modules.prefs = {
95 Prefs: { 95 Prefs: {
96 onChanged: new Notifier() 96 _listeners: Object.create(null),
97
98 on: function(preference, callback)
Thomas Greiner 2016/03/21 17:55:55 What about extending `Notifier` instead so that `N
Sebastian Noack 2016/03/21 19:40:07 Well, changing the calling convention of existing
99 {
100 if (preference in this._listeners)
101 this._listeners[preference].push(callback);
102 else
103 this._listeners[preference] = [callback];
104 }
97 } 105 }
98 }; 106 };
99 var prefs = { 107 var prefs = {
100 notifications_ignoredcategories: (params.showNotificationUI) ? ["*"] : [], 108 notifications_ignoredcategories: (params.showNotificationUI) ? ["*"] : [],
101 notifications_showui: params.showNotificationUI, 109 notifications_showui: params.showNotificationUI,
102 safari_contentblocker: false, 110 safari_contentblocker: false,
103 shouldShowBlockElementMenu: true, 111 shouldShowBlockElementMenu: true,
104 show_devtools_panel: true, 112 show_devtools_panel: true,
105 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/exc eptionrules.txt" 113 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/exc eptionrules.txt"
106 }; 114 };
107 Object.keys(prefs).forEach(function(key) 115 Object.keys(prefs).forEach(function(key)
108 { 116 {
109 Object.defineProperty(modules.prefs.Prefs, key, { 117 Object.defineProperty(modules.prefs.Prefs, key, {
110 get: function() 118 get: function()
111 { 119 {
112 return prefs[key]; 120 return prefs[key];
113 }, 121 },
114 set: function(value) 122 set: function(value)
115 { 123 {
116 prefs[key] = value; 124 prefs[key] = value;
117 modules.prefs.Prefs.onChanged.triggerListeners(key); 125
118 return prefs[key]; 126 var listeners = modules.prefs.Prefs._listeners[key];
127 if (listeners)
128 for (var i = 0; i < listeners.length; i++)
129 listeners[i]();
119 } 130 }
120 }); 131 });
121 }); 132 });
122 133
123 modules.notification = { 134 modules.notification = {
124 Notification: { 135 Notification: {
125 toggleIgnoreCategory: function(category) 136 toggleIgnoreCategory: function(category)
126 { 137 {
127 var categories = prefs.notifications_ignoredcategories; 138 var categories = prefs.notifications_ignoredcategories;
128 var index = categories.indexOf(category); 139 var index = categories.indexOf(category);
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 481
471 if (params.safariContentBlocker) 482 if (params.safariContentBlocker)
472 { 483 {
473 global.safari = { 484 global.safari = {
474 extension: { 485 extension: {
475 setContentBlocker: function() {} 486 setContentBlocker: function() {}
476 } 487 }
477 }; 488 };
478 } 489 }
479 })(this); 490 })(this);
OLDNEW
« no previous file with comments | « no previous file | messageResponder.js » ('j') | messageResponder.js » ('J')

Powered by Google App Engine
This is Rietveld