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: Created July 28, 2015, 9:51 a.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 | « no previous file | lib/inspectorObserver.js » ('j') | lib/inspectorObserver.js » ('J')
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 * 22 * NodeData object *
23 *******************/ 23 *******************/
24 24
25 function NodeData(node, parentNode) { 25 function NodeData(node, parentNode)
26 {
27 function findElement(node, property)
Thomas Greiner 2015/07/28 13:52:18 Detail: Note that if you'd make this function iter
28 {
29 let value = node[property];
30 if (typeof value == "function")
31 value = value.call(node);
32
33 if (value && value.nodeType != Ci.nsIDOMNode.ELEMENT_NODE)
34 value = findElement(value, property);
35
36 return value;
37 }
38
26 this.tagName = {value: node.tagName, checked: false}; 39 this.tagName = {value: node.tagName, checked: false};
27 40
28 if (typeof parentNode == "undefined") 41 if (typeof parentNode == "undefined")
29 parentNode = (node.parentNode && node.parentNode.nodeType == node.ELEMENT_NO DE ? new NodeData(node.parentNode) : null); 42 {
43 let parent = findElement(node, "parentNode");
44 parentNode = (parent ? new NodeData(parent) : null);
45 }
30 this.parentNode = parentNode; 46 this.parentNode = parentNode;
31 47
32 var prevSibling = node.previousSibling; 48 let prevSibling = findElement(node, "prevSibling");
Thomas Greiner 2015/07/28 13:52:18 This string should say "previousSibling" from what
33 while (prevSibling && prevSibling.nodeType != node.ELEMENT_NODE)
34 prevSibling = prevSibling.previousSibling;
35 this.prevSibling = (prevSibling ? new NodeData(prevSibling, this.parentNode) : null); 49 this.prevSibling = (prevSibling ? new NodeData(prevSibling, this.parentNode) : null);
36 50
37 if (parentNode && !prevSibling) 51 if (parentNode && !prevSibling)
38 this.firstChild = {checked: false}; 52 this.firstChild = {checked: false};
39 53
40 var nextSibling = node.nextSibling; 54 let nextSibling = findElement(node, "nextSibling");
41 while (nextSibling && nextSibling.nodeType != node.ELEMENT_NODE)
42 nextSibling = nextSibling.nextSibling;
43 if (parentNode && !nextSibling) 55 if (parentNode && !nextSibling)
44 this.lastChild = {checked: false}; 56 this.lastChild = {checked: false};
45 57
46 this.attributes = []; 58 this.attributes = [];
47 for (var i = 0; i < node.attributes.length; i++) { 59 for (var i = 0; i < node.attributes.length; i++) {
48 var attribute = node.attributes[i]; 60 var attribute = node.attributes[i];
49 var data = {name: attribute.name, value: attribute.value, selected: attribut e.value, checked: false}; 61 var data = {name: attribute.name, value: attribute.value, selected: attribut e.value, checked: false};
50 if (data.name == "id" || data.name == "class") 62 if (data.name == "id" || data.name == "class")
51 this.attributes.unshift(data); 63 this.attributes.unshift(data);
52 else 64 else
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 133
122 function TreeView_getCellProperties(row, col) { 134 function TreeView_getCellProperties(row, col) {
123 this.getRowProperties(row); 135 this.getRowProperties(row);
124 } 136 }
125 137
126 /********************* 138 /*********************
127 * General functions * 139 * General functions *
128 *********************/ 140 *********************/
129 141
130 function init() { 142 function init() {
131 var element = window.arguments[0]; 143 let element = window.arguments[0];
132 doc = element.ownerDocument; 144 doc = window.arguments[1] || element.ownerDocument;
133 var wnd = doc.defaultView; 145 let domain = window.arguments[2] || doc.defaultView.location.hostname;
134 146
135 // Check whether element hiding group is disabled 147 // Check whether element hiding group is disabled
136 let subscription = AdblockPlus.getSubscription("~eh~"); 148 let subscription = AdblockPlus.getSubscription("~eh~");
137 if (subscription && subscription.disabled) 149 if (subscription && subscription.disabled)
138 { 150 {
139 let warning = document.getElementById("groupDisabledWarning"); 151 let warning = document.getElementById("groupDisabledWarning");
140 if (/\?1\?/.test(warning.textContent)) 152 if (/\?1\?/.test(warning.textContent))
141 warning.textContent = warning.textContent.replace(/\?1\?/g, subscription.t itle); 153 warning.textContent = warning.textContent.replace(/\?1\?/g, subscription.t itle);
142 warning.hidden = false; 154 warning.hidden = false;
143 } 155 }
(...skipping 18 matching lines...) Expand all
162 bestAttr = nodeData.attributes[i]; 174 bestAttr = nodeData.attributes[i];
163 } 175 }
164 } 176 }
165 if (bestAttr) 177 if (bestAttr)
166 { 178 {
167 bestAttr.selected = bestAttr.value; 179 bestAttr.selected = bestAttr.value;
168 bestAttr.checked = true; 180 bestAttr.checked = true;
169 } 181 }
170 } 182 }
171 183
172 let domain = wnd.location.hostname;
173 let selectedDomain; 184 let selectedDomain;
174 switch (Prefs.composer_defaultDomain) 185 switch (Prefs.composer_defaultDomain)
175 { 186 {
176 case 0: 187 case 0:
177 selectedDomain = ""; 188 selectedDomain = "";
178 break; 189 break;
179 case 1: 190 case 1:
180 try 191 try
181 { 192 {
182 // EffectiveTLDService will throw for IP addresses, just go to the next case then 193 // 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); 246 var escapedName = escapeName(attr.name);
236 if (attr.selected != "") 247 if (attr.selected != "")
237 { 248 {
238 var op = "*="; 249 var op = "*=";
239 if (attr.selected == attr.value) 250 if (attr.selected == attr.value)
240 op = "="; 251 op = "=";
241 else if (attr.value.substr(0, attr.selected.length) == attr.selected) 252 else if (attr.value.substr(0, attr.selected.length) == attr.selected)
242 op = "^="; 253 op = "^=";
243 else if (attr.value.substr(attr.value.length - attr.selected.length) = = attr.selected) 254 else if (attr.value.substr(attr.value.length - attr.selected.length) = = attr.selected)
244 op = "$="; 255 op = "$=";
245 256
246 let useFallback = false; 257 let useFallback = false;
247 if (attr.name == "id" && op == "=") 258 if (attr.name == "id" && op == "=")
248 expression += "#" + escapeName(attr.selected).replace(/^([^a-zA-Z\\] )/, escapeChar).replace(/\\(\s)$/, escapeChar); 259 expression += "#" + escapeName(attr.selected).replace(/^([^a-zA-Z\\] )/, escapeChar).replace(/\\(\s)$/, escapeChar);
249 else if (attr.name == "class" && /\S/.test(attr.selected)) 260 else if (attr.name == "class" && /\S/.test(attr.selected))
250 { 261 {
251 let knownClasses = new Set(attr.value.split(/\s+/)); 262 let knownClasses = new Set(attr.value.split(/\s+/));
252 let classes = attr.selected.split(/\s+/).filter(cls => cls != ""); 263 let classes = attr.selected.split(/\s+/).filter(cls => cls != "");
253 if (classes.every(cls => knownClasses.has(cls))) 264 if (classes.every(cls => knownClasses.has(cls)))
254 expression += "." + classes.map(escapeName).join("."); 265 expression += "." + classes.map(escapeName).join(".");
255 else 266 else
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 639
629 fillAttributes(item.nodeData); 640 fillAttributes(item.nodeData);
630 } 641 }
631 642
632 function addExpression() 643 function addExpression()
633 { 644 {
634 AdblockPlus.addPatterns([document.getElementById("expression").value]); 645 AdblockPlus.addPatterns([document.getElementById("expression").value]);
635 646
636 togglePreview(false); 647 togglePreview(false);
637 } 648 }
OLDNEW
« no previous file with comments | « no previous file | lib/inspectorObserver.js » ('j') | lib/inspectorObserver.js » ('J')

Powered by Google App Engine
This is Rietveld