From 2caeb0d288171cb2001f3bc7e6a16d00fb461fa0 Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Tue, 9 Dec 2014 20:56:42 -0800 Subject: [PATCH] feat(propertiesPane): add back properties pane Closes #160 --- devtoolsBackground.js | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/devtoolsBackground.js b/devtoolsBackground.js index 05d49cf..178cc9a 100644 --- a/devtoolsBackground.js +++ b/devtoolsBackground.js @@ -1,8 +1,44 @@ var panels = 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 = window.angular.element($0).scope(); + // 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 {}; + } +}; + +panels.elements.createSidebarPane( + "AngularJS Properties", + function (sidebar) { + panels.elements.onSelectionChanged.addListener(function updateElementProperties() { + sidebar.setExpression("(" + getPanelContents.toString() + ")()"); + }); + }); + var angularPanel = panels.create( "AngularJS", "img/angular.png", "panel/app.html" ); -