forked from danharper/backbone_inspector
/
devtools.js
43 lines (39 loc) · 1.04 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
(function(){
var getSelectedBackboneView = 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 = BackboneViews[elm.getAttribute('data-bb-view')];
if (found == null) {
level++;
found = findView(elm.parentElement, level);
}
return found;
}
var view = findView($0),
data = { __proto__: null };
if (view) {
_V = view;
if (level > 0) { data.distance = level; }
data.id = view.cid;
data.view = view;
data.options = view.options;
data.collection = view.collection;
data.model = view.model;
}
return data;
};
chrome.devtools.panels.elements.createSidebarPane(
"Backbone View",
function(sidebar) {
function updatePanel() {
sidebar.setExpression("(" + getSelectedBackboneView.toString() + ")()");
}
updatePanel();
chrome.devtools.panels.elements.onSelectionChanged.addListener(updatePanel);
}
);
})();