OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2013 Eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 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/>. |
| 16 */ |
| 17 |
| 18 iconAnimation = { |
| 19 _icons = new TabMap(), |
| 20 _animatedTabs = new TabMap(), |
| 21 step = 0, |
| 22 |
| 23 update: function(severity) |
| 24 { |
| 25 if (severity == this._severity) |
| 26 return; |
| 27 |
| 28 if (!this._severity) |
| 29 this._start(); |
| 30 |
| 31 this._severity = severity; |
| 32 }, |
| 33 stop: function() |
| 34 { |
| 35 clearInterval(this._interval); |
| 36 |
| 37 delete this._interval; |
| 38 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 }, |
| 49 _start: function() |
| 50 { |
| 51 this._interval = setInterval(function() |
| 52 { |
| 53 this._getVisibleTabs(function(tabs) |
| 54 { |
| 55 if (tabs.length == 0) |
| 56 return; |
| 57 |
| 58 for (var i = 0; i < tabs.length; i++) |
| 59 this._animatedTabs.set(tabs[i], null); |
| 60 |
| 61 var interval = setInterval(function() |
| 62 { |
| 63 this._step++; |
| 64 tabs.forEach(this._updateIcon.bind(this)); |
| 65 |
| 66 if (this._step < 10) |
| 67 return; |
| 68 |
| 69 clearInterval(interval); |
| 70 setTimeout(function() |
| 71 { |
| 72 interval = setInterval(function() |
| 73 { |
| 74 this._step--; |
| 75 tabs.forEach(this._updateIcon.bind(this)); |
| 76 |
| 77 if (this._step > 0) |
| 78 return; |
| 79 |
| 80 clearInterval(interval); |
| 81 this._animatedTabs.clear(); |
| 82 }.bind(this), 100); |
| 83 }.bind(this), 1000); |
| 84 }.bind(this), 100); |
| 85 }.bind(this)); |
| 86 }.bind(this), 15000); |
| 87 }, |
| 88 _getVisibleTabs: function(callback) |
| 89 { |
| 90 ext.windows.getAll(function(windows) |
| 91 { |
| 92 var tabs = []; |
| 93 var visibleWindows = windows.length; |
| 94 |
| 95 for (var i = 0; i < windows.length; i++) |
| 96 { |
| 97 if (!windows[i].visible) |
| 98 { |
| 99 if (--visibleWindows == 0) |
| 100 callback(tabs); |
| 101 |
| 102 continue; |
| 103 } |
| 104 |
| 105 windows[i].getActiveTab(function(tab) |
| 106 { |
| 107 tabs.push(tab); |
| 108 |
| 109 if (tabs.length == visibleWindows) |
| 110 callback(tabs); |
| 111 }); |
| 112 } |
| 113 }); |
| 114 }, |
| 115 _updateIcon: function(tab) |
| 116 { |
| 117 var path = this._icons.get(tab); |
| 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.pageAction.setIcon(path); |
| 133 } |
| 134 }; |
OLD | NEW |