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

Side by Side Diff: lib/child/flasher.js

Issue 29329779: Issue 3258 - Blockable items: restore item flashing functionality (Closed)
Patch Set: Addressed comments Created Nov. 25, 2015, 7:05 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/content/ui/sidebar.xul ('k') | lib/child/requestNotifier.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** 18 /**
19 * Draws a blinking border for a list of matching nodes. 19 * @fileOverview Draws a blinking border for a list of matching elements.
20 */ 20 */
21 21
22 var flasher = { 22 function Flasher(elements, scrollToItem)
23 nodes: null, 23 {
24 if (scrollToItem && elements[0].ownerDocument)
25 {
26 // Ensure that at least one element is visible when flashing
27 elements[0].scrollIntoView();
28 }
29
30 this.elements = elements;
31 this.count = 0;
32
33 this.doFlash();
34
35 }
36 Flasher.prototype =
37 {
38 elements: null,
24 count: 0, 39 count: 0,
25 timer: null, 40 timer: null,
26 41
27 flash: function(nodes) 42 doFlash: function()
28 { 43 {
29 this.stop(); 44 if (this.count >= 12)
30 if (nodes)
31 nodes = nodes.filter(node => node.nodeType == Node.ELEMENT_NODE);
32 if (!nodes || !nodes.length)
33 return;
34
35 if (Prefs.flash_scrolltoitem && nodes[0].ownerDocument)
36 { 45 {
37 // Ensure that at least one node is visible when flashing
38 let wnd = nodes[0].ownerDocument.defaultView;
39 try
40 {
41 let topWnd = Utils.getChromeWindow(wnd);
42 let {getBrowser} = require("appSupport");
43 let browser = (getBrowser ? getBrowser(topWnd) : null);
44 if (browser)
45 browser.markupDocumentViewer.scrollToNode(nodes[0]);
46 }
47 catch(e)
48 {
49 Cu.reportError(e);
50 }
51 }
52
53 this.nodes = nodes;
54 this.count = 0;
55
56 this.doFlash();
57 },
58
59 doFlash: function() {
60 if (this.count >= 12) {
61 this.stop(); 46 this.stop();
62 return; 47 return;
63 } 48 }
64 49
65 if (this.count % 2) 50 if (this.count % 2)
66 this.switchOff(); 51 this.switchOff();
67 else 52 else
68 this.switchOn(); 53 this.switchOn();
69 54
70 this.count++; 55 this.count++;
71 56
72 this.timer = window.setTimeout(function() {flasher.doFlash()}, 300); 57 this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
58 this.timer.initWithCallback(() => this.doFlash(), 300, Ci.nsITimer.TYPE_ONE_ SHOT);
73 }, 59 },
74 60
75 stop: function() { 61 stop: function()
76 if (this.timer) { 62 {
77 window.clearTimeout(this.timer); 63 if (this.timer)
64 {
65 this.timer.cancel();
78 this.timer = null; 66 this.timer = null;
79 } 67 }
80 68
81 if (this.nodes) { 69 if (this.elements)
70 {
82 this.switchOff(); 71 this.switchOff();
83 this.nodes = null; 72 this.elements = null;
84 } 73 }
85 }, 74 },
86 75
87 setOutline: function(outline, offset) 76 setOutline: function(outline, offset)
88 { 77 {
89 for (var i = 0; i < this.nodes.length; i++) 78 for (let element of this.elements)
90 { 79 {
91 if ("style" in this.nodes[i]) 80 if (!Cu.isDeadWrapper(element) && "style" in element)
92 { 81 {
93 this.nodes[i].style.outline = outline; 82 element.style.outline = outline;
94 this.nodes[i].style.outlineOffset = offset; 83 element.style.outlineOffset = offset;
95 } 84 }
96 } 85 }
97 }, 86 },
98 87
99 switchOn: function() 88 switchOn: function()
100 { 89 {
101 this.setOutline("#CC0000 dotted 2px", "-2px"); 90 this.setOutline("#CC0000 dotted 2px", "-2px");
102 }, 91 },
103 92
104 switchOff: function() 93 switchOff: function()
105 { 94 {
106 this.setOutline("", ""); 95 this.setOutline("", "");
107 } 96 }
108 }; 97 };
98
99 exports.Flasher = Flasher;
OLDNEW
« no previous file with comments | « chrome/content/ui/sidebar.xul ('k') | lib/child/requestNotifier.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld