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

Side by Side Diff: chrome/content/composer.js

Issue 29322778: Issue 2816 - Partial fix for EHH button in inspector tool, preview functionality still broken (Closed)
Patch Set: Unified code paths Created July 29, 2015, 12:23 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/actor.jsm ('k') | chrome/content/frameScript.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 Source Code is subject to the terms of the Mozilla Public License 2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at 3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/. 4 * http://mozilla.org/MPL/2.0/.
5 */ 5 */
6 6
7 let {Prefs} = require("prefs"); 7 let {Prefs} = require("prefs");
8 8
9 let domainData; 9 let domainData;
10 let nodeData; 10 let nodeData;
11 let selectedNode = null; 11 let selectedNode = null;
12 let advancedMode = false; 12 let advancedMode = false;
13 let treeView = null; 13 let treeView = null;
14 let stylesheetData; 14 let stylesheetData;
15 let previewStyle = null; 15 let previewStyle = null;
16 let doc; 16 let doc;
17 17
18 let abpURL = Cc["@adblockplus.org/abp/public;1"].getService(Ci.nsIURI); 18 let abpURL = Cc["@adblockplus.org/abp/public;1"].getService(Ci.nsIURI);
19 Cu.import(abpURL.spec); 19 Cu.import(abpURL.spec);
20 20
21 /******************* 21 /*******************
22 * NodeData object *
23 *******************/
24
25 function NodeData(node, parentNode) {
26 this.tagName = {value: node.tagName, checked: false};
27
28 if (typeof parentNode == "undefined")
29 parentNode = (node.parentNode && node.parentNode.nodeType == node.ELEMENT_NO DE ? new NodeData(node.parentNode) : null);
30 this.parentNode = parentNode;
31
32 var prevSibling = node.previousSibling;
33 while (prevSibling && prevSibling.nodeType != node.ELEMENT_NODE)
34 prevSibling = prevSibling.previousSibling;
35 this.prevSibling = (prevSibling ? new NodeData(prevSibling, this.parentNode) : null);
36
37 if (parentNode && !prevSibling)
38 this.firstChild = {checked: false};
39
40 var nextSibling = node.nextSibling;
41 while (nextSibling && nextSibling.nodeType != node.ELEMENT_NODE)
42 nextSibling = nextSibling.nextSibling;
43 if (parentNode && !nextSibling)
44 this.lastChild = {checked: false};
45
46 this.attributes = [];
47 for (var i = 0; i < node.attributes.length; i++) {
48 var attribute = node.attributes[i];
49 var data = {name: attribute.name, value: attribute.value, selected: attribut e.value, checked: false};
50 if (data.name == "id" || data.name == "class")
51 this.attributes.unshift(data);
52 else
53 this.attributes.push(data);
54 }
55
56 if (this.attributes.length >= 2 && this.attributes[1].name == "id") {
57 // Make sure ID attribute comes first
58 var tmp = this.attributes[1];
59 this.attributes[1] = this.attributes[0];
60 this.attributes[0] = tmp;
61 }
62
63 this.customCSS = {selected: "", checked: false};
64 }
65
66 /*******************
67 * TreeView object * 22 * TreeView object *
68 *******************/ 23 *******************/
69 24
70 function TreeView(tree) { 25 function TreeView(tree) {
71 var origView = tree.view; 26 var origView = tree.view;
72 this.getRowProperties = TreeView_getRowProperties; 27 this.getRowProperties = TreeView_getRowProperties;
73 this.getCellProperties = TreeView_getCellProperties; 28 this.getCellProperties = TreeView_getCellProperties;
74 29
75 createQIProxy(this, origView); 30 createQIProxy(this, origView);
76 31
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 75 }
121 76
122 function TreeView_getCellProperties(row, col) { 77 function TreeView_getCellProperties(row, col) {
123 this.getRowProperties(row); 78 this.getRowProperties(row);
124 } 79 }
125 80
126 /********************* 81 /*********************
127 * General functions * 82 * General functions *
128 *********************/ 83 *********************/
129 84
130 function init() { 85 function init()
131 var element = window.arguments[0]; 86 {
132 doc = element.ownerDocument; 87 nodeData = window.arguments[0];
133 var wnd = doc.defaultView; 88 let domain = window.arguments[1];
134 89
135 // Check whether element hiding group is disabled 90 // Check whether element hiding group is disabled
136 let subscription = AdblockPlus.getSubscription("~eh~"); 91 let subscription = AdblockPlus.getSubscription("~eh~");
137 if (subscription && subscription.disabled) 92 if (subscription && subscription.disabled)
138 { 93 {
139 let warning = document.getElementById("groupDisabledWarning"); 94 let warning = document.getElementById("groupDisabledWarning");
140 if (/\?1\?/.test(warning.textContent)) 95 if (/\?1\?/.test(warning.textContent))
141 warning.textContent = warning.textContent.replace(/\?1\?/g, subscription.t itle); 96 warning.textContent = warning.textContent.replace(/\?1\?/g, subscription.t itle);
142 warning.hidden = false; 97 warning.hidden = false;
143 } 98 }
144 99
145 nodeData = new NodeData(element);
146 nodeData.tagName.checked = true; 100 nodeData.tagName.checked = true;
147 if (nodeData.attributes.length > 0) 101 if (nodeData.attributes.length > 0)
148 { 102 {
149 let maxLen = 0; 103 let maxLen = 0;
150 let bestAttr = null; 104 let bestAttr = null;
151 for (let i = 0; i < nodeData.attributes.length; i++) 105 for (let i = 0; i < nodeData.attributes.length; i++)
152 { 106 {
153 let len = nodeData.attributes[i].value.length; 107 let len = nodeData.attributes[i].value.length;
154 if ((nodeData.attributes[i].name == "id" || nodeData.attributes[i].name == "class") && len) 108 if ((nodeData.attributes[i].name == "id" || nodeData.attributes[i].name == "class") && len)
155 { 109 {
156 len = 0x7FFFFFFF; 110 len = 0x7FFFFFFF;
157 nodeData.tagName.checked = false; 111 nodeData.tagName.checked = false;
158 } 112 }
159 if (len > maxLen) 113 if (len > maxLen)
160 { 114 {
161 maxLen = len; 115 maxLen = len;
162 bestAttr = nodeData.attributes[i]; 116 bestAttr = nodeData.attributes[i];
163 } 117 }
164 } 118 }
165 if (bestAttr) 119 if (bestAttr)
166 { 120 {
167 bestAttr.selected = bestAttr.value; 121 bestAttr.selected = bestAttr.value;
168 bestAttr.checked = true; 122 bestAttr.checked = true;
169 } 123 }
170 } 124 }
171 125
172 let domain = wnd.location.hostname;
173 let selectedDomain; 126 let selectedDomain;
174 switch (Prefs.composer_defaultDomain) 127 switch (Prefs.composer_defaultDomain)
175 { 128 {
176 case 0: 129 case 0:
177 selectedDomain = ""; 130 selectedDomain = "";
178 break; 131 break;
179 case 1: 132 case 1:
180 try 133 try
181 { 134 {
182 // EffectiveTLDService will throw for IP addresses, just go to the next case then 135 // EffectiveTLDService will throw for IP addresses, just go to the next case then
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 var escapedName = escapeName(attr.name); 188 var escapedName = escapeName(attr.name);
236 if (attr.selected != "") 189 if (attr.selected != "")
237 { 190 {
238 var op = "*="; 191 var op = "*=";
239 if (attr.selected == attr.value) 192 if (attr.selected == attr.value)
240 op = "="; 193 op = "=";
241 else if (attr.value.substr(0, attr.selected.length) == attr.selected) 194 else if (attr.value.substr(0, attr.selected.length) == attr.selected)
242 op = "^="; 195 op = "^=";
243 else if (attr.value.substr(attr.value.length - attr.selected.length) = = attr.selected) 196 else if (attr.value.substr(attr.value.length - attr.selected.length) = = attr.selected)
244 op = "$="; 197 op = "$=";
245 198
246 let useFallback = false; 199 let useFallback = false;
247 if (attr.name == "id" && op == "=") 200 if (attr.name == "id" && op == "=")
248 expression += "#" + escapeName(attr.selected).replace(/^([^a-zA-Z\\] )/, escapeChar).replace(/\\(\s)$/, escapeChar); 201 expression += "#" + escapeName(attr.selected).replace(/^([^a-zA-Z\\] )/, escapeChar).replace(/\\(\s)$/, escapeChar);
249 else if (attr.name == "class" && /\S/.test(attr.selected)) 202 else if (attr.name == "class" && /\S/.test(attr.selected))
250 { 203 {
251 let knownClasses = new Set(attr.value.split(/\s+/)); 204 let knownClasses = new Set(attr.value.split(/\s+/));
252 let classes = attr.selected.split(/\s+/).filter(cls => cls != ""); 205 let classes = attr.selected.split(/\s+/).filter(cls => cls != "");
253 if (classes.every(cls => knownClasses.has(cls))) 206 if (classes.every(cls => knownClasses.has(cls)))
254 expression += "." + classes.map(escapeName).join("."); 207 expression += "." + classes.map(escapeName).join(".");
255 else 208 else
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 581
629 fillAttributes(item.nodeData); 582 fillAttributes(item.nodeData);
630 } 583 }
631 584
632 function addExpression() 585 function addExpression()
633 { 586 {
634 AdblockPlus.addPatterns([document.getElementById("expression").value]); 587 AdblockPlus.addPatterns([document.getElementById("expression").value]);
635 588
636 togglePreview(false); 589 togglePreview(false);
637 } 590 }
OLDNEW
« no previous file with comments | « chrome/content/actor.jsm ('k') | chrome/content/frameScript.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld