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

Unified Diff: lib/child/flasher.js

Issue 29329779: Issue 3258 - Blockable items: restore item flashing functionality (Closed)
Patch Set: Better handling of dead objects Created Nov. 5, 2015, 11:06 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/child/flasher.js
===================================================================
rename from chrome/content/ui/flasher.js
rename to lib/child/flasher.js
--- a/chrome/content/ui/flasher.js
+++ b/lib/child/flasher.js
@@ -11,98 +11,89 @@
* 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/>.
*/
/**
- * Draws a blinking border for a list of matching nodes.
+ * @fileOverview Draws a blinking border for a list of matching nodes.
*/
-var flasher = {
+function Flasher(nodes, scrollToItem)
+{
+ if (scrollToItem && nodes[0].ownerDocument)
+ {
+ // Ensure that at least one node is visible when flashing
+ nodes[0].scrollIntoView();
Thomas Greiner 2015/11/24 12:15:42 Detail: You're expecting a specific kind of `nsIDO
Wladimir Palant 2015/11/25 19:06:38 I decided to rename the variables.
+ }
+
+ this.nodes = nodes;
+ this.count = 0;
+
+ this.doFlash();
+
+}
+Flasher.prototype =
+{
nodes: null,
count: 0,
timer: null,
- flash: function(nodes)
+ doFlash: function()
{
- this.stop();
- if (nodes)
- nodes = nodes.filter(node => node.nodeType == Node.ELEMENT_NODE);
- if (!nodes || !nodes.length)
- return;
-
- if (Prefs.flash_scrolltoitem && nodes[0].ownerDocument)
+ if (this.count >= 12)
{
- // Ensure that at least one node is visible when flashing
- let wnd = nodes[0].ownerDocument.defaultView;
- try
- {
- let topWnd = Utils.getChromeWindow(wnd);
- let {getBrowser} = require("appSupport");
- let browser = (getBrowser ? getBrowser(topWnd) : null);
- if (browser)
- browser.markupDocumentViewer.scrollToNode(nodes[0]);
- }
- catch(e)
- {
- Cu.reportError(e);
- }
- }
-
- this.nodes = nodes;
- this.count = 0;
-
- this.doFlash();
- },
-
- doFlash: function() {
- if (this.count >= 12) {
this.stop();
return;
}
if (this.count % 2)
this.switchOff();
else
this.switchOn();
this.count++;
- this.timer = window.setTimeout(function() {flasher.doFlash()}, 300);
+ this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+ this.timer.initWithCallback(() => this.doFlash(), 300, Ci.nsITimer.TYPE_ONE_SHOT);
},
- stop: function() {
- if (this.timer) {
- window.clearTimeout(this.timer);
+ stop: function()
+ {
+ if (this.timer)
+ {
+ this.timer.cancel();
this.timer = null;
}
- if (this.nodes) {
+ if (this.nodes)
+ {
this.switchOff();
this.nodes = null;
}
},
setOutline: function(outline, offset)
{
- for (var i = 0; i < this.nodes.length; i++)
+ for (let node of this.nodes)
{
- if ("style" in this.nodes[i])
+ if (!Cu.isDeadWrapper(node) && "style" in node)
{
- this.nodes[i].style.outline = outline;
- this.nodes[i].style.outlineOffset = offset;
+ node.style.outline = outline;
+ node.style.outlineOffset = offset;
}
}
},
switchOn: function()
{
this.setOutline("#CC0000 dotted 2px", "-2px");
},
switchOff: function()
{
this.setOutline("", "");
}
};
+
+exports.Flasher = Flasher;

Powered by Google App Engine
This is Rietveld