forked from adblockplus/backup-adblockpluschrome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iconAnimation.js
107 lines (89 loc) · 2.5 KB
/
iconAnimation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* This file is part of Adblock Plus <http://adblockplus.org/>,
* Copyright (C) 2006-2014 Eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Adblock Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
iconAnimation = {
_icons: new ext.PageMap(),
_animatedPages: new ext.PageMap(),
_step: 0,
update: function(type)
{
if (type == this._type)
return;
if (!this._type)
this._start();
this._type = type;
},
stop: function()
{
clearInterval(this._interval);
delete this._interval;
delete this._type;
this._animatedPages.clear();
},
registerPage: function(page, icon)
{
this._icons.set(page, icon);
if (this._animatedPages.has(page))
this._updateIcon(page);
},
_start: function()
{
this._interval = setInterval(function()
{
ext.pages.query({active: true}, function(pages)
{
if (pages.length == 0)
return;
for (var i = 0; i < pages.length; i++)
this._animatedPages.set(pages[i], null);
var interval = setInterval(function()
{
this._step++;
pages.forEach(this._updateIcon.bind(this));
if (this._step < 10)
return;
clearInterval(interval);
setTimeout(function()
{
interval = setInterval(function()
{
this._step--;
pages.forEach(this._updateIcon.bind(this));
if (this._step > 0)
return;
clearInterval(interval);
this._animatedPages.clear();
}.bind(this), 100);
}.bind(this), 1000);
}.bind(this), 100);
}.bind(this));
}.bind(this), 15000);
},
_updateIcon: function(page)
{
var path = this._icons.get(page);
if (!path)
return;
if (this._step > 0)
{
var suffix = "-notification-" + this._type;
if (this._step < 10)
suffix += "-" + this._step;
path = path.replace(/(?=\..+$)/, suffix);
}
page.browserAction.setIcon(path);
}
};