Skip to content

Commit b56f71c

Browse files
author
Chris K
committed
Template for event listener tooltip.
1 parent 5fb175e commit b56f71c

File tree

4 files changed

+102
-12
lines changed

4 files changed

+102
-12
lines changed

src/ecma-debugger/dominspection/inspectabledomnode.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.FRAME_ELEMENT = 12;
2929
cls.EcmascriptDebugger["6.0"].InspectableDOMNode.MATCH_REASON = 13;
3030
cls.EcmascriptDebugger["6.0"].InspectableDOMNode.PSEUDO_ELEMENT = 14;
3131
cls.EcmascriptDebugger["6.0"].InspectableDOMNode.PSEUDO_NODE = 0;
32+
cls.EcmascriptDebugger["6.0"].InspectableDOMNode.EVENT_LISTENER_LIST = 15;
3233

3334
cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
3435
{
@@ -62,7 +63,8 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
6263
BEFORE_ALIKES = [BEFORE, FIRST_LETTER, FIRST_LINE],
6364
AFTER_ALIKES = [AFTER],
6465
ERROR_MSG = 0,
65-
PSEUDO_NAME = {};
66+
PSEUDO_NAME = {},
67+
EVENT_LISTENER_LIST = cls.EcmascriptDebugger["6.0"].InspectableDOMNode.EVENT_LISTENER_LIST;
6668

6769
PSEUDO_NAME[BEFORE] = "before";
6870
PSEUDO_NAME[AFTER] = "after";
@@ -437,12 +439,27 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
437439
{
438440
return Boolean(this._data && this._data.length);
439441
}
442+
443+
this.get_node = function(node_id)
444+
{
445+
if (this.has_data())
446+
{
447+
for (var i = 0; this._data[i] && this._data[i][ID] != node_id; i++);
448+
return this._data[i];
449+
}
450+
return null;
451+
};
440452

441453
this.has_node = function(node_id)
442454
{
443-
for (var i = 0; this._data[i] && this._data[i][ID] != node_id; i++);
444-
return Boolean(this._data[i]);
445-
}
455+
return Boolean(this.get_node(node_id));
456+
};
457+
458+
this.get_ev_listeners = function(node_id)
459+
{
460+
var node = this.get_node(node_id);
461+
return node && node[EVENT_LISTENER_LIST] || [];
462+
};
446463

447464
this.get_data = this.getData = function()
448465
{

src/ecma-debugger/evlistenertooltip/evlistenertemplates.js

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,88 @@
1212
var ORIGIN_EVENT_TARGET = 1;
1313
var ORIGIN_ATTRIBUTE = 2;
1414
var POSITION = 2;
15+
var SCRIPT_ID = 0;
16+
var LINE_NUMBER = 1;
1517
var USE_CAPTURE = 3;
1618
var LISTENER_OBJECT_ID = 4;
1719
var LISTENER_SCRIPT_DATA = 5;
1820

21+
/*
22+
matchReason: TRAVERSAL (1)
23+
pseudoElementList:
24+
eventListenerList:
25+
eventener:
26+
eventType: "click"
27+
origin: EVENT_TARGET (1)
28+
position:
29+
scriptID: 2544
30+
lineNumber: 19
31+
useCapture: 0
32+
listenerObjectID: 17
33+
*/
34+
1935
var ret = [];
2036
var row =
2137
["tr",
2238
["td",
23-
["h2", listener[EVENT_TYPE], "class", "evl-type"]],
39+
["h2", listener[EVENT_TYPE], "class", "ev-type"]],
2440
["td", listener[USE_CAPTURE] ? "capturing phase" : "bubbling phase"]];
25-
ret push(row);
41+
ret.push(row);
42+
row =
43+
["tr",
44+
["td", listener[ORIGIN] == ORIGIN_EVENT_TARGET ?
45+
"event target handler" :
46+
"attribute handler",
47+
"colspan", "2", "class", "ev-origin"]];
48+
ret.push(row);
49+
var position = listener[POSITION];
50+
var script_id = position && position[SCRIPT_ID];
51+
var script = window.runtimes.getScript(script_id);
52+
if (script)
53+
{
54+
row =
55+
["tr",
56+
["td", "added:"],
57+
this.ev_script_link(script, position[LINE_NUMBER]),
58+
"handler", "show-log-entry-source",
59+
"data-scriptid", String(script_id),
60+
"data-scriptline", String(position[LINE_NUMBER]),
61+
"class", "ev-added"];
62+
ret.push(row);
63+
}
2664
return ret;
65+
};
2766

28-
}
67+
this.ev_script_link = function(script, line_number)
68+
{
69+
var script_type = this._script_type_map[script.script_type] ||
70+
script.script_type;
71+
if (script.uri)
72+
{
73+
var is_linked = script.script_type == "linked";
74+
var ret =
75+
["td",
76+
["span", script.filename + ":" + line_number,
77+
"data-tooltip", is_linked && "js-script-select",
78+
"data-tooltip-text", is_linked && script.uri,
79+
"class", "file-line"]];
80+
}
81+
else
82+
{
83+
var rt = window.runtimes.getRuntime(script.runtime_id);
84+
if (rt)
85+
{
86+
var ret =
87+
["td",
88+
["span", rt.filename + ":" + line_number,
89+
"data-tooltip", "js-script-select",
90+
"data-tooltip-text", rt.uri,
91+
"class", "file-line"]];
92+
}
93+
}
94+
95+
ret.push("script-id", String(script.script_id));
96+
return ret;
97+
};
2998

3099
}).apply(window.templates || (window.templates = {}));

src/ecma-debugger/evlistenertooltip/evlistenertooltip.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ cls.EvListenerTooltip = function()
6868
{
6969

7070
_hide_tooltip();
71-
_tooltip.show(["span", "hello"]);
72-
73-
71+
var model = window.dominspections[target.get_ancestor_attr("data-model-id")];
72+
var node_id = target.get_ancestor_attr("ref-id");
73+
if (model && node_id)
74+
{
75+
var listeners = model.get_ev_listeners(node_id);
76+
var tmpl = window.templates.ev_listeners(listeners);
77+
_tooltip.show(tmpl);
78+
}
7479
};
7580

7681
var _init = function(view)

src/ui-scripts/tooltip/tooltip.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
{
1313
color: #000;
1414
background-color: #aac2f2;
15-
padding: 1px;
16-
margin: -1px;
15+
box-shadow: 0 0 0 1px #aac2f2;
1716
}
1817

1918
.basic-tooltip

0 commit comments

Comments
 (0)