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

Delta Between Two Patch Sets: chrome/content/composer.js

Issue 29322778: Issue 2816 - Partial fix for EHH button in inspector tool, preview functionality still broken (Closed)
Left Patch Set: Created July 28, 2015, 9:51 a.m.
Right Patch Set: Preemptively fixed some nits and compatibility info Created July 29, 2015, 12:41 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « chrome/content/actor.jsm ('k') | chrome/content/frameScript.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 {
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
39 this.tagName = {value: node.tagName, checked: false};
40
41 if (typeof parentNode == "undefined")
42 {
43 let parent = findElement(node, "parentNode");
44 parentNode = (parent ? new NodeData(parent) : null);
45 }
46 this.parentNode = parentNode;
47
48 let prevSibling = findElement(node, "prevSibling");
Thomas Greiner 2015/07/28 13:52:18 This string should say "previousSibling" from what
49 this.prevSibling = (prevSibling ? new NodeData(prevSibling, this.parentNode) : null);
50
51 if (parentNode && !prevSibling)
52 this.firstChild = {checked: false};
53
54 let nextSibling = findElement(node, "nextSibling");
55 if (parentNode && !nextSibling)
56 this.lastChild = {checked: false};
57
58 this.attributes = [];
59 for (var i = 0; i < node.attributes.length; i++) {
60 var attribute = node.attributes[i];
61 var data = {name: attribute.name, value: attribute.value, selected: attribut e.value, checked: false};
62 if (data.name == "id" || data.name == "class")
63 this.attributes.unshift(data);
64 else
65 this.attributes.push(data);
66 }
67
68 if (this.attributes.length >= 2 && this.attributes[1].name == "id") {
69 // Make sure ID attribute comes first
70 var tmp = this.attributes[1];
71 this.attributes[1] = this.attributes[0];
72 this.attributes[0] = tmp;
73 }
74
75 this.customCSS = {selected: "", checked: false};
76 }
77
78 /*******************
79 * TreeView object * 22 * TreeView object *
80 *******************/ 23 *******************/
81 24
82 function TreeView(tree) { 25 function TreeView(tree) {
83 var origView = tree.view; 26 var origView = tree.view;
84 this.getRowProperties = TreeView_getRowProperties; 27 this.getRowProperties = TreeView_getRowProperties;
85 this.getCellProperties = TreeView_getCellProperties; 28 this.getCellProperties = TreeView_getCellProperties;
86 29
87 createQIProxy(this, origView); 30 createQIProxy(this, origView);
88 31
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 75 }
133 76
134 function TreeView_getCellProperties(row, col) { 77 function TreeView_getCellProperties(row, col) {
135 this.getRowProperties(row); 78 this.getRowProperties(row);
136 } 79 }
137 80
138 /********************* 81 /*********************
139 * General functions * 82 * General functions *
140 *********************/ 83 *********************/
141 84
142 function init() { 85 function init()
143 let element = window.arguments[0]; 86 {
144 doc = window.arguments[1] || element.ownerDocument; 87 nodeData = window.arguments[0];
145 let domain = window.arguments[2] || doc.defaultView.location.hostname; 88 let host = window.arguments[1];
146 89
147 // Check whether element hiding group is disabled 90 // Check whether element hiding group is disabled
148 let subscription = AdblockPlus.getSubscription("~eh~"); 91 let subscription = AdblockPlus.getSubscription("~eh~");
149 if (subscription && subscription.disabled) 92 if (subscription && subscription.disabled)
150 { 93 {
151 let warning = document.getElementById("groupDisabledWarning"); 94 let warning = document.getElementById("groupDisabledWarning");
152 if (/\?1\?/.test(warning.textContent)) 95 if (/\?1\?/.test(warning.textContent))
153 warning.textContent = warning.textContent.replace(/\?1\?/g, subscription.t itle); 96 warning.textContent = warning.textContent.replace(/\?1\?/g, subscription.t itle);
154 warning.hidden = false; 97 warning.hidden = false;
155 } 98 }
156 99
157 nodeData = new NodeData(element);
158 nodeData.tagName.checked = true; 100 nodeData.tagName.checked = true;
159 if (nodeData.attributes.length > 0) 101 if (nodeData.attributes.length > 0)
160 { 102 {
161 let maxLen = 0; 103 let maxLen = 0;
162 let bestAttr = null; 104 let bestAttr = null;
163 for (let i = 0; i < nodeData.attributes.length; i++) 105 for (let i = 0; i < nodeData.attributes.length; i++)
164 { 106 {
165 let len = nodeData.attributes[i].value.length; 107 let len = nodeData.attributes[i].value.length;
166 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)
167 { 109 {
(...skipping 17 matching lines...) Expand all
185 switch (Prefs.composer_defaultDomain) 127 switch (Prefs.composer_defaultDomain)
186 { 128 {
187 case 0: 129 case 0:
188 selectedDomain = ""; 130 selectedDomain = "";
189 break; 131 break;
190 case 1: 132 case 1:
191 try 133 try
192 { 134 {
193 // 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
194 let effectiveTLD = Cc["@mozilla.org/network/effective-tld-service;1"].ge tService(Ci.nsIEffectiveTLDService); 136 let effectiveTLD = Cc["@mozilla.org/network/effective-tld-service;1"].ge tService(Ci.nsIEffectiveTLDService);
195 selectedDomain = effectiveTLD.getPublicSuffixFromHost(domain); 137 selectedDomain = effectiveTLD.getPublicSuffixFromHost(host);
196 break; 138 break;
197 } catch (e) {} 139 } catch (e) {}
198 case 2: 140 case 2:
199 try 141 try
200 { 142 {
201 // EffectiveTLDService will throw for IP addresses, just go to the next case then 143 // EffectiveTLDService will throw for IP addresses, just go to the next case then
202 let effectiveTLD = Cc["@mozilla.org/network/effective-tld-service;1"].ge tService(Ci.nsIEffectiveTLDService); 144 let effectiveTLD = Cc["@mozilla.org/network/effective-tld-service;1"].ge tService(Ci.nsIEffectiveTLDService);
203 selectedDomain = effectiveTLD.getBaseDomainFromHost(domain); 145 selectedDomain = effectiveTLD.getBaseDomainFromHost(host);
204 break; 146 break;
205 } catch (e) {} 147 } catch (e) {}
206 case 3: 148 case 3:
207 selectedDomain = domain.replace(/^www\./, ""); 149 selectedDomain = host.replace(/^www\./, "");
208 break; 150 break;
209 default: 151 default:
210 selectedDomain = domain; 152 selectedDomain = host;
211 break; 153 break;
212 } 154 }
213 domainData = {value: domain, selected: selectedDomain}; 155 domainData = {value: host, selected: selectedDomain};
214 156
215 fillDomains(domainData); 157 fillDomains(domainData);
216 fillNodes(nodeData); 158 fillNodes(nodeData);
217 setAdvancedMode(document.documentElement.getAttribute("advancedMode") == "true "); 159 setAdvancedMode(document.documentElement.getAttribute("advancedMode") == "true ");
218 updateExpression(); 160 updateExpression();
219 161
220 setTimeout(function() { 162 setTimeout(function() {
221 document.getElementById("domainGroup").selectedItem.focus(); 163 document.getElementById("domainGroup").selectedItem.focus();
222 if (document.getElementById("preview").checked) 164 if (document.getElementById("preview").checked)
223 togglePreview(true); 165 togglePreview(true);
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 581
640 fillAttributes(item.nodeData); 582 fillAttributes(item.nodeData);
641 } 583 }
642 584
643 function addExpression() 585 function addExpression()
644 { 586 {
645 AdblockPlus.addPatterns([document.getElementById("expression").value]); 587 AdblockPlus.addPatterns([document.getElementById("expression").value]);
646 588
647 togglePreview(false); 589 togglePreview(false);
648 } 590 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld