Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 const numberOfFrames = 10; | |
19 | |
18 let whitelistedState = new ext.PageMap(); | 20 let whitelistedState = new ext.PageMap(); |
19 let notificationType = null; | 21 let notificationType = null; |
20 let animationInterval = null; | 22 let animationInterval = null; |
21 let animationStep = 0; | 23 let animationStep = 0; |
22 | 24 |
23 function getIconPath(whitelisted) | 25 function getIconPath(whitelisted) |
24 { | 26 { |
25 let filename = "icons/abp-$size"; | 27 let filename = "icons/abp-$size"; |
26 | 28 |
27 // If the current page is whitelisted, pick an icon that indicates that | 29 // If the current page is whitelisted, pick an icon that indicates that |
28 // Adblock Plus is disabled, however not when the notification icon has | 30 // Adblock Plus is disabled, however not when the notification icon has |
29 // full opacity, or on Safari where icons are genrally grayscale-only. | 31 // full opacity, or on Safari where icons are genrally grayscale-only. |
30 if (whitelisted && animationStep < 10 && require("info").platform != "safari") | 32 if (whitelisted && animationStep < numberOfFrames && require("info").platform != "safari") |
31 filename += "-whitelisted"; | 33 filename += "-whitelisted"; |
32 | 34 |
33 // If the icon is currently animating to indicate a pending notification, | 35 // If the icon is currently animating to indicate a pending notification, |
34 // pick the icon for the corresponing notification type and animation frame. | 36 // pick the icon for the corresponing notification type and animation frame. |
35 if (notificationType && animationStep > 0) | 37 if (notificationType && animationStep > 0) |
36 { | 38 { |
37 filename += "-notification-" + notificationType; | 39 filename += "-notification-" + notificationType; |
38 | 40 |
39 if (animationStep < 10) | 41 if (animationStep < numberOfFrames) |
40 filename += "-" + animationStep; | 42 filename += "-" + animationStep; |
41 } | 43 } |
42 | 44 |
43 return filename + ".png"; | 45 return filename + ".png"; |
44 } | 46 } |
45 | 47 |
46 function setIcon(page) | 48 function setIcon(page) |
47 { | 49 { |
48 page.browserAction.setIcon(getIconPath(whitelistedState.get(page))); | 50 page.browserAction.setIcon(getIconPath(whitelistedState.get(page))); |
49 } | 51 } |
50 | 52 |
51 function runAnimation() | 53 function runAnimation() |
52 { | 54 { |
53 return setInterval(function() | 55 return setInterval(function() |
54 { | 56 { |
55 ext.pages.query({active: true}, function(pages) | 57 ext.pages.query({active: true}, function(pages) |
56 { | 58 { |
57 let fadeInInterval = setInterval(function() | 59 let fadeInInterval = setInterval(function() |
58 { | 60 { |
59 animationStep++; | 61 animationStep++; |
60 pages.forEach(setIcon); | 62 pages.forEach(setIcon); |
61 | 63 |
62 if (animationStep < 10) | 64 if (animationStep < numberOfFrames) |
Felix Dahlke
2015/02/12 04:52:56
We're checking for `animationStep < 10` three time
Sebastian Noack
2015/02/12 11:15:29
Done.
| |
63 return; | 65 return; |
64 | 66 |
65 setTimeout(function() | 67 setTimeout(function() |
66 { | 68 { |
67 let fadeOutInterval = setInterval(function() | 69 let fadeOutInterval = setInterval(function() |
68 { | 70 { |
69 animationStep--; | 71 animationStep--; |
70 pages.forEach(setIcon); | 72 pages.forEach(setIcon); |
71 | 73 |
72 if (animationStep > 0) | 74 if (animationStep > 0) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 notificationType = type; | 108 notificationType = type; |
107 | 109 |
108 if (animationInterval == null) | 110 if (animationInterval == null) |
109 animationInterval = runAnimation(); | 111 animationInterval = runAnimation(); |
110 } | 112 } |
111 exports.startIconAnimation = startIconAnimation; | 113 exports.startIconAnimation = startIconAnimation; |
112 | 114 |
113 /** | 115 /** |
114 * Stops to animate the browser action icon. | 116 * Stops to animate the browser action icon. |
115 */ | 117 */ |
116 function stopIconAnimation() | 118 function stopIconAnimation() |
Felix Dahlke
2015/02/12 04:52:56
Now that I'm giving this code a good read - don't
Sebastian Noack
2015/02/12 11:15:29
To keep things simple we let the current transitio
Felix Dahlke
2015/02/12 14:14:30
You're right, I somehow thought we'd abort the tra
| |
117 { | 119 { |
118 if (animationInterval != null) | 120 if (animationInterval != null) |
119 { | 121 { |
120 clearInterval(animationInterval); | 122 clearInterval(animationInterval); |
121 animationInterval = null; | 123 animationInterval = null; |
122 } | 124 } |
123 | 125 |
124 notificationType = null; | 126 notificationType = null; |
125 } | 127 } |
126 exports.stopIconAnimation = stopIconAnimation; | 128 exports.stopIconAnimation = stopIconAnimation; |
LEFT | RIGHT |