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 elements. |
*/ |
-var flasher = { |
- nodes: null, |
+function Flasher(elements, scrollToItem) |
+{ |
+ if (scrollToItem && elements[0].ownerDocument) |
+ { |
+ // Ensure that at least one element is visible when flashing |
+ elements[0].scrollIntoView(); |
+ } |
+ |
+ this.elements = elements; |
+ this.count = 0; |
+ |
+ this.doFlash(); |
+ |
+} |
+Flasher.prototype = |
+{ |
+ elements: 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.elements) |
+ { |
this.switchOff(); |
- this.nodes = null; |
+ this.elements = null; |
} |
}, |
setOutline: function(outline, offset) |
{ |
- for (var i = 0; i < this.nodes.length; i++) |
+ for (let element of this.elements) |
{ |
- if ("style" in this.nodes[i]) |
+ if (!Cu.isDeadWrapper(element) && "style" in element) |
{ |
- this.nodes[i].style.outline = outline; |
- this.nodes[i].style.outlineOffset = offset; |
+ element.style.outline = outline; |
+ element.style.outlineOffset = offset; |
} |
} |
}, |
switchOn: function() |
{ |
this.setOutline("#CC0000 dotted 2px", "-2px"); |
}, |
switchOff: function() |
{ |
this.setOutline("", ""); |
} |
}; |
+ |
+exports.Flasher = Flasher; |