forked from juggy/ember_inspector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevtools.js
55 lines (48 loc) · 1.43 KB
/
devtools.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(function(){
var getSelectedEmberView = function() {
// _V is a global of the selected view for experimentation in the console
_V = undefined;
var level;
function findView(elm, n) {
if (elm == null) { return undefined; }
level = n || 0;
var found = Ember.View.views[elm.id];
if (found == null) {
level++;
found = findView(elm.parentElement, level);
}
return found;
}
function findViewProperty(view, propertyName) {
var property = null, parentView = view;
while (!property && parentView) {
property = parentView.get(propertyName);
parentView = parentView.get('parentView');
}
return property;
}
var view = findView($0),
data = { __proto__: null };
if (view) {
_V = view;
if (level > 0) { data.distance = level; }
data.id = view.get('elementId');
data.type = view.toString().match(/^<(.*):/)[1];
data.view = view;
var controller = findViewProperty(view, 'controller');
if (controller) data.controllerName = controller.constructor.toString();
data.templateName = findViewProperty(view, 'templateName');
}
return data;
};
chrome.devtools.panels.elements.createSidebarPane(
"Ember View",
function(sidebar) {
function updatePanel() {
sidebar.setExpression("(" + getSelectedEmberView.toString() + ")()");
}
updatePanel();
chrome.devtools.panels.elements.onSelectionChanged.addListener(updatePanel);
}
);
})();