OLD | NEW |
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-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 iconAnimation = { | 18 iconAnimation = { |
19 _icons: new TabMap(), | 19 step: 0, |
20 _animatedTabs: new TabMap(), | 20 tabs: new TabMap(), |
21 _step: 0, | |
22 | 21 |
23 update: function(severity) | 22 update: function(severity) |
24 { | 23 { |
25 if (severity == this._severity) | 24 if (severity == this.severity) |
26 return; | 25 return; |
27 | 26 |
28 if (!this._severity) | 27 if (!this.severity) |
29 this._start(); | 28 this._start(); |
30 | 29 |
31 this._severity = severity; | 30 this.severity = severity; |
32 }, | 31 }, |
33 stop: function() | 32 stop: function() |
34 { | 33 { |
35 clearInterval(this._interval); | 34 clearInterval(this._interval); |
36 | 35 |
37 delete this._interval; | 36 delete this._interval; |
38 delete this._severity; | 37 delete this.severity; |
39 | |
40 this._animatedTabs.clear(); | |
41 }, | |
42 registerTab: function(tab, icon) | |
43 { | |
44 this._icons.set(tab, icon); | |
45 | |
46 if (this._animatedTabs.has(tab)) | |
47 this._updateIcon(tab); | |
48 }, | 38 }, |
49 _start: function() | 39 _start: function() |
50 { | 40 { |
51 this._interval = setInterval(function() | 41 this._interval = setInterval(function() |
52 { | 42 { |
53 this._getVisibleTabs(function(tabs) | 43 this._getVisibleTabs(function(tabs) |
54 { | 44 { |
55 if (tabs.length == 0) | 45 if (tabs.length == 0) |
56 return; | 46 return; |
57 | 47 |
58 for (var i = 0; i < tabs.length; i++) | 48 for (var i = 0; i < tabs.length; i++) |
59 this._animatedTabs.set(tabs[i], null); | 49 this.tabs.set(tabs[i], null); |
60 | 50 |
61 var interval = setInterval(function() | 51 var interval = setInterval(function() |
62 { | 52 { |
63 this._step++; | 53 this.step++; |
64 tabs.forEach(this._updateIcon.bind(this)); | 54 tabs.forEach(this._updateIcon.bind(this)); |
65 | 55 |
66 if (this._step < 10) | 56 if (this.step < 10) |
67 return; | 57 return; |
68 | 58 |
69 clearInterval(interval); | 59 clearInterval(interval); |
70 setTimeout(function() | 60 setTimeout(function() |
71 { | 61 { |
72 interval = setInterval(function() | 62 interval = setInterval(function() |
73 { | 63 { |
74 this._step--; | 64 this.step--; |
75 tabs.forEach(this._updateIcon.bind(this)); | 65 tabs.forEach(this._updateIcon.bind(this)); |
76 | 66 |
77 if (this._step > 0) | 67 if (this.step > 0) |
78 return; | 68 return; |
79 | 69 |
80 clearInterval(interval); | 70 clearInterval(interval); |
81 this._animatedTabs.clear(); | 71 this.tabs.clear(); |
82 }.bind(this), 100); | 72 }.bind(this), 100); |
83 }.bind(this), 1000); | 73 }.bind(this), 1000); |
84 }.bind(this), 100); | 74 }.bind(this), 100); |
85 }.bind(this)); | 75 }.bind(this)); |
86 }.bind(this), 15000); | 76 }.bind(this), 15000); |
87 }, | 77 }, |
88 _getVisibleTabs: function(callback) | 78 _getVisibleTabs: function(callback) |
89 { | 79 { |
90 ext.windows.getAll(function(windows) | 80 ext.windows.getAll(function(windows) |
91 { | 81 { |
(...skipping 15 matching lines...) Expand all Loading... |
107 tabs.push(tab); | 97 tabs.push(tab); |
108 | 98 |
109 if (tabs.length == visibleWindows) | 99 if (tabs.length == visibleWindows) |
110 callback(tabs); | 100 callback(tabs); |
111 }); | 101 }); |
112 } | 102 } |
113 }); | 103 }); |
114 }, | 104 }, |
115 _updateIcon: function(tab) | 105 _updateIcon: function(tab) |
116 { | 106 { |
117 var path = this._icons.get(tab); | 107 tab.browserAction.setIcon(getTabStatus(tab, this).icon); |
118 | |
119 if (!path) | |
120 return; | |
121 | |
122 if (this._step > 0) | |
123 { | |
124 var suffix = "-notification-" + this._severity; | |
125 | |
126 if (this._step < 10) | |
127 suffix += "-" + this._step; | |
128 | |
129 path = path.replace(/(?=\..+$)/, suffix); | |
130 } | |
131 | |
132 tab.browserAction.setIcon(path); | |
133 } | 108 } |
134 }; | 109 }; |
OLD | NEW |