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

Unified Diff: chrome/content/composer.js

Issue 29322778: Issue 2816 - Partial fix for EHH button in inspector tool, preview functionality still broken (Closed)
Patch Set: Created July 28, 2015, 9:51 a.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
« no previous file with comments | « no previous file | lib/inspectorObserver.js » ('j') | lib/inspectorObserver.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/content/composer.js
===================================================================
--- a/chrome/content/composer.js
+++ b/chrome/content/composer.js
@@ -17,34 +17,46 @@ let doc;
let abpURL = Cc["@adblockplus.org/abp/public;1"].getService(Ci.nsIURI);
Cu.import(abpURL.spec);
/*******************
* NodeData object *
*******************/
-function NodeData(node, parentNode) {
+function NodeData(node, parentNode)
+{
+ function findElement(node, property)
Thomas Greiner 2015/07/28 13:52:18 Detail: Note that if you'd make this function iter
+ {
+ let value = node[property];
+ if (typeof value == "function")
+ value = value.call(node);
+
+ if (value && value.nodeType != Ci.nsIDOMNode.ELEMENT_NODE)
+ value = findElement(value, property);
+
+ return value;
+ }
+
this.tagName = {value: node.tagName, checked: false};
if (typeof parentNode == "undefined")
- parentNode = (node.parentNode && node.parentNode.nodeType == node.ELEMENT_NODE ? new NodeData(node.parentNode) : null);
+ {
+ let parent = findElement(node, "parentNode");
+ parentNode = (parent ? new NodeData(parent) : null);
+ }
this.parentNode = parentNode;
- var prevSibling = node.previousSibling;
- while (prevSibling && prevSibling.nodeType != node.ELEMENT_NODE)
- prevSibling = prevSibling.previousSibling;
+ let prevSibling = findElement(node, "prevSibling");
Thomas Greiner 2015/07/28 13:52:18 This string should say "previousSibling" from what
this.prevSibling = (prevSibling ? new NodeData(prevSibling, this.parentNode) : null);
if (parentNode && !prevSibling)
this.firstChild = {checked: false};
- var nextSibling = node.nextSibling;
- while (nextSibling && nextSibling.nodeType != node.ELEMENT_NODE)
- nextSibling = nextSibling.nextSibling;
+ let nextSibling = findElement(node, "nextSibling");
if (parentNode && !nextSibling)
this.lastChild = {checked: false};
this.attributes = [];
for (var i = 0; i < node.attributes.length; i++) {
var attribute = node.attributes[i];
var data = {name: attribute.name, value: attribute.value, selected: attribute.value, checked: false};
if (data.name == "id" || data.name == "class")
@@ -123,19 +135,19 @@ function TreeView_getCellProperties(row,
this.getRowProperties(row);
}
/*********************
* General functions *
*********************/
function init() {
- var element = window.arguments[0];
- doc = element.ownerDocument;
- var wnd = doc.defaultView;
+ let element = window.arguments[0];
+ doc = window.arguments[1] || element.ownerDocument;
+ let domain = window.arguments[2] || doc.defaultView.location.hostname;
// Check whether element hiding group is disabled
let subscription = AdblockPlus.getSubscription("~eh~");
if (subscription && subscription.disabled)
{
let warning = document.getElementById("groupDisabledWarning");
if (/\?1\?/.test(warning.textContent))
warning.textContent = warning.textContent.replace(/\?1\?/g, subscription.title);
@@ -164,17 +176,16 @@ function init() {
}
if (bestAttr)
{
bestAttr.selected = bestAttr.value;
bestAttr.checked = true;
}
}
- let domain = wnd.location.hostname;
let selectedDomain;
switch (Prefs.composer_defaultDomain)
{
case 0:
selectedDomain = "";
break;
case 1:
try
@@ -237,17 +248,17 @@ function updateExpression()
{
var op = "*=";
if (attr.selected == attr.value)
op = "=";
else if (attr.value.substr(0, attr.selected.length) == attr.selected)
op = "^=";
else if (attr.value.substr(attr.value.length - attr.selected.length) == attr.selected)
op = "$=";
-
+
let useFallback = false;
if (attr.name == "id" && op == "=")
expression += "#" + escapeName(attr.selected).replace(/^([^a-zA-Z\\])/, escapeChar).replace(/\\(\s)$/, escapeChar);
else if (attr.name == "class" && /\S/.test(attr.selected))
{
let knownClasses = new Set(attr.value.split(/\s+/));
let classes = attr.selected.split(/\s+/).filter(cls => cls != "");
if (classes.every(cls => knownClasses.has(cls)))
« no previous file with comments | « no previous file | lib/inspectorObserver.js » ('j') | lib/inspectorObserver.js » ('J')

Powered by Google App Engine
This is Rietveld