Skip to content

Commit 692046b

Browse files
committed
Fix Show DOM properties action for jQuery data
1 parent d7720a0 commit 692046b

File tree

1 file changed

+50
-43
lines changed

1 file changed

+50
-43
lines changed

lib/inspector-overlay.js

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,15 @@ const InspectorOverlay = Class(
141141
},
142142

143143
onMarkupViewContainerCreated: function(eventId, container) {
144-
Trace.sysout("InspectorOverlay.onMarkupViewContainerCreated; ", arguments);
144+
//Trace.sysout("InspectorOverlay.onMarkupViewContainerCreated;");
145145

146+
// Create a little data-icon indicating that the rendered element
147+
// has jQuery.data associated. Clickin on the icon opens a tooltip
148+
// with more details.
146149
let nodeFront = container.node;
147-
let hasJQueryData = false;
148-
149-
// nodeFront.getFormProperty has been introduced in Bug 1036949
150-
// xxxHonza: Checking existence of the method can be removed
151-
// as soon as Fx42 is the minimum required version.
152-
if (nodeFront.getFormProperty) {
153-
hasJQueryData = nodeFront.getFormProperty("hasJQueryData");
154-
} else if (nodeFront._form.props) {
155-
hasJQueryData = nodeFront._form.props.hasJQueryData;
156-
}
157-
158-
if (!hasJQueryData) {
159-
return;
150+
if (this.hasJQueryData(nodeFront)) {
151+
this.createDataIcon(container.elt);
160152
}
161-
162-
this.createDataIcon(container.elt);
163153
},
164154

165155
createDataIcon: function(element) {
@@ -208,17 +198,7 @@ const InspectorOverlay = Class(
208198

209199
// Get node front for the clicked element.
210200
let nodeFront = this.panel.selection.nodeFront;
211-
212-
// Use jQuery actor front to get fresh jQuery data
213-
// for the clicked node (for the selection).
214-
let toolboxOverlay = this.context.getOverlay(ToolboxOverlayId);
215-
if (!toolboxOverlay) {
216-
TraceError.sysout("InspectorOverlay.onClickTooltip; ERROR no " +
217-
"toolbox overlay!", this.context);
218-
return;
219-
}
220-
221-
toolboxOverlay.front.getJQueryData(nodeFront).then(response => {
201+
this.getJQueryData(nodeFront).then(response => {
222202
// Create jQuery data tooltip object.
223203
let dataTooltip = new DataTooltip({
224204
toolbox: this.toolbox,
@@ -235,31 +215,36 @@ const InspectorOverlay = Class(
235215
showDOMProperties: function() {
236216
let original = this.showDOMPropertiesOriginal;
237217

238-
// The user needs to click on the jQueryData element (an envelope)
218+
// The user needs to click on a little icon indicating
219+
// jQuery.data in the element in order to show properties
220+
// for the jQuery.data
239221
let target = this.panel.panelDoc.popupNode;
240222
if (!target.classList.contains("fireQueryData")) {
241223
return original.apply(this.panel, arguments);
242224
}
243225

244-
// There must be jQuery data associated with the node.
226+
// Make sure there are jQuery data associated with the node.
245227
let nodeFront = this.panel.selection.nodeFront;
246-
let jQueryData = nodeFront._form.jQueryData;
247-
if (!jQueryData) {
228+
if (!this.hasJQueryData(nodeFront)) {
248229
return original.apply(this.panel, arguments);
249230
}
250231

251-
Trace.sysout("InspectorOverlay.showDOMProperties;", jQueryData);
252-
253-
// Display clicked jQuery data instead of element properties.
254-
this.toolbox.openSplitConsole().then(() => {
255-
let panel = this.toolbox.getPanel("webconsole");
256-
let output = panel.hud.ui.output;
257-
258-
output.openVariablesView({
259-
label: "jQuery.data",
260-
//objectActor: dataGrip,
261-
rawObject: jQueryData,
262-
autofocus: true,
232+
// Alright, get jQuery.data from the backend and display
233+
// them in the VariablesView (Console panel's side panel).
234+
this.getJQueryData(nodeFront).then(response => {
235+
this.toolbox.openSplitConsole().then(() => {
236+
Trace.sysout("InspectorOverlay.showDOMProperties;", response);
237+
238+
let panel = this.toolbox.getPanel("webconsole");
239+
let output = panel.hud.ui.output;
240+
241+
// Retrieved 'response.jQueryData' is a grip object.
242+
output.openVariablesView({
243+
label: "jQuery.data",
244+
objectActor: response.jQueryData,
245+
//rawObject: raw e.g. JSON object, would go here,
246+
autofocus: true,
247+
});
263248
});
264249
});
265250
},
@@ -310,6 +295,28 @@ const InspectorOverlay = Class(
310295
this.createDataIcon(element);
311296
}
312297
},
298+
299+
// Helpers for jQuery.data
300+
301+
hasJQueryData: function(nodeFront) {
302+
let hasJQueryData;
303+
304+
// nodeFront.getFormProperty has been introduced in Bug 1036949
305+
// xxxHonza: Checking existence of the method can be removed
306+
// as soon as Fx42 is the minimum required version.
307+
if (nodeFront.getFormProperty) {
308+
hasJQueryData = nodeFront.getFormProperty("hasJQueryData");
309+
} else if (nodeFront._form.props) {
310+
hasJQueryData = nodeFront._form.props.hasJQueryData;
311+
}
312+
313+
return hasJQueryData;
314+
},
315+
316+
getJQueryData: function(nodeFront) {
317+
let toolboxOverlay = this.context.getOverlay(ToolboxOverlayId);
318+
return toolboxOverlay.front.getJQueryData(nodeFront);
319+
}
313320
});
314321

315322
// Patching MarkupView (fire a new "container-created" event)

0 commit comments

Comments
 (0)