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

Delta Between Two Patch Sets: background.js

Issue 29338734: Issue 3839 - Adapt for Prefs event changes (Closed)
Left Patch Set: Reuse event emitter logic Created March 21, 2016, 7:39 p.m.
Right Patch Set: Addresed comments Created March 22, 2016, 2:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | messageResponder.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 { 46 {
47 for (var i = 0; i < listeners.length; i++) 47 for (var i = 0; i < listeners.length; i++)
48 listeners[i].apply(null, Array.prototype.slice.call(arguments, 1)); 48 listeners[i].apply(null, Array.prototype.slice.call(arguments, 1));
49 } 49 }
50 } 50 }
51 }; 51 };
52 52
53 function Notifier() 53 function Notifier()
54 { 54 {
55 this._eventEmitter = new EventEmitter(); 55 this._eventEmitter = new EventEmitter();
56 }; 56 }
57 Notifier.prototype = { 57 Notifier.prototype = {
58 addListener: function(listener) 58 addListener: function(listener)
59 { 59 {
60 this._eventEmitter.on("", listener); 60 var listeners = this._eventEmitter._listeners[""];
61 if (!listeners || listener.indexOf(listener) == -1)
62 this._eventEmitter.on("", listener);
61 }, 63 },
62 removeListener: function(listener) 64 removeListener: function(listener)
63 { 65 {
64 this._eventEmitter.off("", listener); 66 this._eventEmitter.off("", listener);
65 }, 67 },
66 triggerListeners: function() 68 triggerListeners: function()
67 { 69 {
68 var args = Array.prototype.slice.apply(arguments); 70 var args = Array.prototype.slice.apply(arguments);
69 args.unshift(""); 71 args.unshift("");
70 this._eventEmitter.emit.apply(this._eventEmitter, args); 72 this._eventEmitter.emit.apply(this._eventEmitter, args);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 Object.keys(prefs).forEach(function(key) 130 Object.keys(prefs).forEach(function(key)
129 { 131 {
130 Object.defineProperty(modules.prefs.Prefs, key, { 132 Object.defineProperty(modules.prefs.Prefs, key, {
131 get: function() 133 get: function()
132 { 134 {
133 return prefs[key]; 135 return prefs[key];
134 }, 136 },
135 set: function(value) 137 set: function(value)
136 { 138 {
137 prefs[key] = value; 139 prefs[key] = value;
138 140 modules.prefs.Prefs.emit(key);
139 var listeners = modules.prefs.Prefs._listeners[key];
140 if (listeners)
141 for (var i = 0; i < listeners.length; i++)
142 listeners[i]();
143 } 141 }
144 }); 142 });
145 }); 143 });
146 144
147 modules.notification = { 145 modules.notification = {
148 Notification: { 146 Notification: {
149 toggleIgnoreCategory: function(category) 147 toggleIgnoreCategory: function(category)
150 { 148 {
151 var categories = prefs.notifications_ignoredcategories; 149 var categories = prefs.notifications_ignoredcategories;
152 var index = categories.indexOf(category); 150 var index = categories.indexOf(category);
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 492
495 if (params.safariContentBlocker) 493 if (params.safariContentBlocker)
496 { 494 {
497 global.safari = { 495 global.safari = {
498 extension: { 496 extension: {
499 setContentBlocker: function() {} 497 setContentBlocker: function() {}
500 } 498 }
501 }; 499 };
502 } 500 }
503 })(this); 501 })(this);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld