code cleanup, work on issuing warning for code.angularjs.org hosed ang.js

test-unit-sauce
Brian Ford 12 years ago
parent c49a7c45e5
commit 4612fbe753

@ -6,7 +6,10 @@ panelApp.controller('OptionsCtrl', function OptionsCtrl($scope, appContext, chro
app: false app: false
}; };
// TODO: refactor //TODO: improve look of highlighting; for instance, if an element is bound and a scope,
// you will only see the most recently applied outline
// TODO: refactor; remove chromeExtension calls in favor of adding methods to appContext
$scope.$watch('debugger.scopes', function (newVal, oldVal) { $scope.$watch('debugger.scopes', function (newVal, oldVal) {
if (newVal) { if (newVal) {
chromeExtension.eval(function () { chromeExtension.eval(function () {
@ -66,6 +69,7 @@ panelApp.controller('OptionsCtrl', function OptionsCtrl($scope, appContext, chro
var styleSheet = document.styleSheets[document.styleSheets.length - 1]; var styleSheet = document.styleSheets[document.styleSheets.length - 1];
styleSheet.insertRule(selector + '{' + rule + '}', styleSheet.cssRules.length); styleSheet.insertRule(selector + '{' + rule + '}', styleSheet.cssRules.length);
}; };
// TODO: rules for ng-app (is it added as a class?)
addCssRule('[ng-app]', 'border: 1px solid green'); addCssRule('[ng-app]', 'border: 1px solid green');
//addCssRule('ng-app:', 'border: 1px solid green'); //addCssRule('ng-app:', 'border: 1px solid green');
addCssRule('[app-run]', 'border: 1px solid green'); addCssRule('[app-run]', 'border: 1px solid green');
@ -96,4 +100,9 @@ panelApp.controller('OptionsCtrl', function OptionsCtrl($scope, appContext, chro
}, function (version) { }, function (version) {
$scope.version = version; $scope.version = version;
}); });
appContext.getAngularSrc(function (status) {
$scope.status = status;
});
}); });

@ -55,7 +55,6 @@ panelApp.directive('d3', function($compile, d3) {
toAdd.forEach(function (a) { toAdd.forEach(function (a) {
classes.push({ classes.push({
name: a, name: a,
size: 0,
imports: [] imports: []
}); });
}); });
@ -123,21 +122,39 @@ panelApp.directive('d3', function($compile, d3) {
.append("svg:g") .append("svg:g")
.attr("transform", "translate(" + rx + "," + ry + ")"); .attr("transform", "translate(" + rx + "," + ry + ")");
svg.append("svg:path")
.attr("class", "arc")
.attr("d", d3.svg.arc().outerRadius(ry - 120).innerRadius(0).startAngle(0).endAngle(2 * Math.PI))
.on("mousedown", mousedown);
// Render the data whenever "val" changes // Render the data whenever "val" changes
// -------------------------------------- // --------------------------------------
scope.$watch('val', function (newVal, oldVal) { scope.$watch('val', function (newVal, oldVal) {
var classes = newVal; var classes;
if (oldVal || !classes || classes.length === 0) { if (!newVal || newVal.length === 0) {
svg.selectAll('*').remove();
return; return;
} }
//div[0].innerHTML = ''; if (oldVal && oldVal.length === newVal.length) {
var changed = false;
for (i = 0; i < oldVal.length; i++) {
if (oldVal[i].name !== newVal[i].name || newVal[i].imports.length !== oldVal[i].imports.length) {
changed = true;
break;
}
}
if (!changed) {
return;
}
}
classes = newVal.slice(0);
classes.sort(function (a, b) {
return .5 - (a.name < b.name);
});
svg.selectAll('*').remove();
svg.append("svg:path")
.attr("class", "arc")
.attr("d", d3.svg.arc().outerRadius(ry - 120).innerRadius(0).startAngle(0).endAngle(2 * Math.PI))
.on("mousedown", mousedown);
var nodes = cluster.nodes(packages.root(classes)), var nodes = cluster.nodes(packages.root(classes)),
links = packages.imports(nodes), links = packages.imports(nodes),

@ -117,49 +117,23 @@ var inject = function () {
}()); }());
} }
var module = angular.module; var ng = angular.module('ng');
angular.module = function (moduleName) { ng.config(function ($provide) {
//console.log(arguments); [
var mod = module.apply(this, arguments);
var methods = [
'constant',
'controller',
'directive',
'factory',
'filter',
'provider', 'provider',
'service', 'factory',
'value' 'service'
]; ].forEach(function (met) {
methods.forEach(function (met) { var temp = $provide[met];
var temp = mod[met]; $provide[met] = function (thingName, definition) {
mod[met] = function (thingName, definition) {
var def;
if (typeof definition === 'function') {
def = annotate(definition);
} else {
def = definition.slice(0);
def.pop();
}
debug.deps.push({ debug.deps.push({
name: thingName, name: thingName,
type: met, imports: annotate(definition)
size: def.length,
imports: def
}); });
return temp.apply(this, arguments); return temp.apply(this, arguments);
} };
}); });
//console.log(mod);
return mod;
};
var ng = angular.module('ng');
ng.config(function ($provide) {
$provide.decorator('$rootScope', function ($delegate) { $provide.decorator('$rootScope', function ($delegate) {
var watchFnToHumanReadableString = function (fn) { var watchFnToHumanReadableString = function (fn) {

@ -229,6 +229,30 @@ panelApp.factory('appContext', function(chromeExtension) {
return _debugCache.deps; return _debugCache.deps;
}, },
getAngularSrc: function (cb) {
chromeExtension.eval("function (window, args) {" +
"if (!window.angular) {" +
"return 'info';" +
"}" +
"var elts = window.angular.element('script[src]');" +
"var re = /\/angular(-\d+(\.(\d+))+(rc)?)?(\.min)?\.js$/;" +
"var elt;" +
"for (i = 0; i < elts.length; i++) {" +
"elt = elts[i];" +
"if (re.exec(elt.src)) {" +
"if (elt.src.indexOf('code.angularjs.org') !== -1) {" +
"return 'error';" +
"} else if (elt.src.indexOf('ajax.googleapis.com') !== -1) {" +
"return 'good';" +
"} else {" +
"return 'info';" +
"}" +
"}" +
"}" +
"return 'info';" +
"}", cb);
},
// Actions // Actions
// ------- // -------

@ -1,7 +1,7 @@
{ {
"name": "AngularJS Batarang", "name": "AngularJS Batarang",
"version": "0.1", "version": "0.1",
"description": "Extends the Developer Tools, adding a tools for debugging and profiling AngularJS applications.", "description": "Extends the Developer Tools, adding tools for debugging and profiling AngularJS applications.",
"background": { "background": {
"page": "background.html" "page": "background.html"
}, },

@ -76,12 +76,13 @@
<div ng-class="{hidden: !enable}" class="row-fluid"> <div ng-class="{hidden: !enable}" class="row-fluid">
<div class="span6"> <div class="span6">
<h3>Watch Tree</h3> <h3>Watch Tree</h3>
<div class="well" style="height: 400px; overflow-y: auto;"> <div class="well well-top" style="height: 400px; overflow-y: auto;">
<wtree val="trees[selectedRoot]" inspect="inspect"></wtree>
</div>
<div class="well well-bottom">
<label for="select-root" ng-class="{hidden: roots.length <= 1}">Root <label for="select-root" ng-class="{hidden: roots.length <= 1}">Root
<select id="select-root" ng-options="p.value as p.label for p in roots" ng-model="selectedRoot"></select> <select id="select-root" ng-options="p.value as p.label for p in roots" ng-model="selectedRoot"></select>
</label> </label>
<wtree val="trees[selectedRoot]" inspect="inspect"></wtree>
</div> </div>
</div> </div>
@ -154,7 +155,9 @@
<div class="span6"> <div class="span6">
<h2>Info</h2> <h2>Info</h2>
<div class="well"> <div class="well">
Angular version: {{version}} <p>Angular version: {{version}}</p>
<p>Angular CDN status: {{status}}</p>
<p><button ng-click="check">check</button></p>
</div> </div>
</div> </div>