[Pkg-mozext-commits] [adblock-plus-element-hiding-helper] 08/483: Allow composition of complex rules
David Prévot
taffit at moszumanska.debian.org
Thu Jan 22 21:41:21 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus-element-hiding-helper.
commit 39c5b7a2274661bc08f241ddce15759dd24fd9ea
Author: Wladimir Palant <trev at gtchat.de>
Date: Mon Jan 8 16:40:26 2007 +0000
Allow composition of complex rules
--HG--
extra : convert_revision : svn%3Ad8bf93c1-8190-44a8-bb31-1ea94378a4df/trunk%40605
---
chrome/content/composer.js | 147 +++++++++++++++++++++++++++++++++++++--
chrome/content/composer.xul | 18 ++++-
chrome/locale/en-US/composer.dtd | 3 +
3 files changed, 161 insertions(+), 7 deletions(-)
diff --git a/chrome/content/composer.js b/chrome/content/composer.js
index 12fb34e..8bc254f 100644
--- a/chrome/content/composer.js
+++ b/chrome/content/composer.js
@@ -33,9 +33,9 @@ function NodeData(node, parentNode) {
parentNode = (node.parentNode && node.parentNode.nodeType == node.ELEMENT_NODE ? new NodeData(node.parentNode) : null);
this.parentNode = parentNode;
- var prevSibling = node.prevSibling;
+ var prevSibling = node.previousSibling;
while (prevSibling && prevSibling.nodeType != node.ELEMENT_NODE)
- prevSibling = prevSibling.prevSibling;
+ prevSibling = prevSibling.previousSibling;
this.prevSibling = (prevSibling ? new NodeData(prevSibling, this.parentNode) : null);
this.attributes = [];
@@ -89,6 +89,8 @@ function init() {
var selectedDomain = domain.replace(/^www\./, "");
domainData = {value: domain, selected: selectedDomain};
+ fillNodes(nodeData);
+
updateExpression();
setTimeout(function() {
@@ -147,8 +149,60 @@ function updateExpression() {
if (simpleMode)
expression = domainData.selected + "#" + nodeData.expressionSimple;
else {
- expression = domainData.selected + "##" + nodeData.expressionRaw;
- // TBD
+ expression = nodeData.expressionRaw;
+
+ var isParent = false;
+ var isRemoteParent = false;
+ var siblingCount = 0;
+ var firstRun = true;
+
+ var curData = nodeData;
+ while (curData) {
+ if (!firstRun && curData.expressionRaw != "*") {
+ var parentRelation = "";
+ if (isRemoteParent)
+ parentRelation = " ";
+ else if (isParent)
+ parentRelation = " > ";
+
+ var siblingRelation = "";
+ for (var i = 0; i < siblingCount; i++)
+ siblingRelation += "* + ";
+ siblingRelation = siblingRelation.replace(/^\*/, '');
+
+ var relation;
+ if (parentRelation != "" && siblingRelation != "")
+ relation = siblingRelation + "*" + parentRelation;
+ else if (parentRelation != "")
+ relation = parentRelation;
+ else
+ relation = siblingRelation;
+
+ expression = curData.expressionRaw + relation + expression;
+
+ isParent = false;
+ isRemoteParent = false;
+ siblingCount = 0;
+ }
+ firstRun = false;
+
+ if (curData.prevSibling) {
+ siblingCount++;
+ curData = curData.prevSibling;
+ }
+ else if (curData.parentNode) {
+ siblingCount = 0;
+ if (isParent)
+ isRemoteParent = true;
+ else
+ isParent = true;
+ curData = curData.parentNode;
+ }
+ else
+ curData = null;
+ }
+
+ expression = domainData.selected + "##" + expression;
}
document.getElementById("expression").value = expression;
@@ -178,6 +232,75 @@ function fillDomains(domainData) {
}
}
+function fillNodes(nodeData) {
+ var curContainer = document.createElement("treechildren");
+ var curChildren = null;
+ var selectedItem = null;
+ while (nodeData) {
+ var id = "";
+ var className = "";
+ var i = 0;
+ if (nodeData.attributes.length > i && nodeData.attributes[i].name == "id")
+ id = nodeData.attributes[i++].value;
+ if (nodeData.attributes.length > i && nodeData.attributes[i].name == "class")
+ className = nodeData.attributes[i++].value;
+
+ var item = document.createElement("treeitem");
+ var row = document.createElement("treerow");
+
+ var cell = document.createElement("treecell");
+ cell.setAttribute("label", nodeData.tagName.value);
+ row.appendChild(cell);
+
+ var cell = document.createElement("treecell");
+ cell.setAttribute("label", id);
+ row.appendChild(cell);
+
+ var cell = document.createElement("treecell");
+ cell.setAttribute("label", className);
+ row.appendChild(cell);
+
+ item.appendChild(row);
+ item.nodeData = nodeData;
+ if (!selectedItem)
+ selectedItem = item;
+
+ if (curChildren) {
+ item.appendChild(curChildren);
+ item.setAttribute("container", "true");
+ item.setAttribute("open", "true");
+ }
+ curChildren = null;
+
+ if (curContainer.firstChild)
+ curContainer.insertBefore(item, curContainer.firstChild);
+ else
+ curContainer.appendChild(item);
+
+ if (nodeData.prevSibling)
+ nodeData = nodeData.prevSibling;
+ else if (nodeData.parentNode) {
+ curChildren = curContainer;
+ curContainer = document.createElement("treechildren");
+ nodeData = nodeData.parentNode;
+ }
+ else
+ nodeData = null;
+ }
+
+ var tree = document.getElementById("nodes-tree");
+ var body = tree.treeBoxObject.treeBody;
+ while (curContainer.firstChild)
+ body.appendChild(curContainer.firstChild);
+
+ // Select current item
+ if (selectedItem) {
+ var selectedIndex = tree.view.getIndexOfItem(selectedItem);
+ tree.treeBoxObject.ensureRowIsVisible(selectedIndex);
+ tree.view.selection.select(selectedIndex);
+ }
+}
+
function fillAttributes(nodeData) {
var template = document.getElementById("attribute-template");
selectedNode = nodeData;
@@ -232,6 +355,22 @@ function toggleAttr(node) {
updateExpression();
}
+function updateNodeSelection() {
+ var tree = document.getElementById("nodes-tree");
+ var selection = tree.view.selection;
+ if (selection.count < 1)
+ return;
+
+ var min = {};
+ selection.getRangeAt(0, min, {});
+
+ var item = tree.view.getItemAtIndex(min.value);
+ if (!item || !item.nodeData)
+ return;
+
+ fillAttributes(item.nodeData);
+}
+
function addExpression() {
var abp = Components.classes["@mozilla.org/adblockplus;1"]
.createInstance(Components.interfaces.nsIAdblockPlus);
diff --git a/chrome/content/composer.xul b/chrome/content/composer.xul
index cf426f5..7669ce2 100644
--- a/chrome/content/composer.xul
+++ b/chrome/content/composer.xul
@@ -37,7 +37,8 @@
buttons="accept,cancel"
width="600px"
height="400px"
- persist="screenX screenY width height sizemode"
+ persist="screenX screenY width height sizemode advancedMode"
+ advancedMode="false"
buttonlabelaccept="&accept.label;"
windowtype="ehh:composer">
<script type="application/x-javascript" src="composer.js"/>
@@ -48,7 +49,7 @@
</vbox>
<hbox id="choices" flex="1">
- <groupbox id="domain" flex="1">
+ <groupbox id="domain" orient="vertical">
<caption label="&domain.label;"/>
<scrollbox flex="1" orient="vertical">
<radiogroup id="domainGroup">
@@ -56,8 +57,19 @@
</radiogroup>
</scrollbox>
</groupbox>
- <groupbox id="attributes" flex="1">
+ <groupbox id="attributes" flex="2" orient="horizontal">
<caption label="&attributes.label;"/>
+ <tree id="nodes-tree" width="300" seltype="single" enableColumnDrag="true" onselect="updateNodeSelection()" persist="width">
+ <treecols>
+ <treecol id="nodes-tree-node" label="&nodes-tree.node.label;" primary="true" flex="2" persist="width ordinal hidden"/>
+ <splitter class="tree-splitter"/>
+ <treecol id="nodes-tree-id" label="&nodes-tree.id.label;" flex="1" persist="width ordinal hidden"/>
+ <splitter class="tree-splitter"/>
+ <treecol id="nodes-tree-class" label="&nodes-tree.class.label;" flex="1" persist="width ordinal hidden"/>
+ </treecols>
+ <treechildren/>
+ </tree>
+ <splitter/>
<scrollbox flex="1" orient="vertical">
<checkbox id="attribute-template" label="&attributes.tagname.label;" hidden="true" oncommand="toggleAttr(this)"/>
</scrollbox>
diff --git a/chrome/locale/en-US/composer.dtd b/chrome/locale/en-US/composer.dtd
index 0cc8e2e..5084f99 100644
--- a/chrome/locale/en-US/composer.dtd
+++ b/chrome/locale/en-US/composer.dtd
@@ -27,5 +27,8 @@
<!ENTITY expression.label "Filter rule">
<!ENTITY domain.label "Bind to domain">
<!ENTITY domain.none.label "Any domain (not recommended)">
+<!ENTITY nodes-tree.node.label "Node">
+<!ENTITY nodes-tree.id.label "id">
+<!ENTITY nodes-tree.class.label "class">
<!ENTITY attributes.label "Require attributes">
<!ENTITY attributes.tagname.label "Tag name:">
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus-element-hiding-helper.git
More information about the Pkg-mozext-commits
mailing list