forked from angular/batarang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devtoolsBackground.js
58 lines (50 loc) · 1.5 KB
/
devtoolsBackground.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
56
57
var panels = chrome && chrome.devtools && chrome.devtools.panels;
// The function below is executed in the context of the inspected page.
var getPanelContents = function () {
if (window.angular && $0) {
//TODO: can we move this scope export into updateElementProperties
var scope = getScope($0);
// Export $scope to the console
window.$scope = scope;
return (function (scope) {
var panelContents = {
__private__: {}
};
for (prop in scope) {
if (scope.hasOwnProperty(prop)) {
if (prop.substr(0, 2) === '$$') {
panelContents.__private__[prop] = scope[prop];
} else {
panelContents[prop] = scope[prop];
}
}
}
return panelContents;
}(scope));
} else {
return {};
}
function getScope(node) {
var scope = window.angular.element(node).scope();
if (!scope) {
// Might be a child of a DocumentFragment...
while (node && node.nodeType === 1) node = node.parentNode;
if (node && node.nodeType === 11) node = (node.parentNode || node.host);
return getScope(node);
}
return scope;
}
};
panels && panels.elements.createSidebarPane(
"$scope",
function (sidebar) {
panels.elements.onSelectionChanged.addListener(function updateElementProperties() {
sidebar.setExpression("(" + getPanelContents.toString() + ")()");
});
// Angular panel
var angularPanel = panels.create(
"AngularJS",
"img/angular.png",
"panel/app.html"
);
});