style(docs): change "this" to "scope" in the controller

This commit is contained in:
Igor Minar 2011-10-21 07:56:03 -07:00
parent 9b85757102
commit 6eb1179505

View file

@ -2,53 +2,52 @@ DocsController.$inject = ['$location', '$browser', '$window', '$cookies'];
function DocsController($location, $browser, $window, $cookies) { function DocsController($location, $browser, $window, $cookies) {
window.$root = this.$root; window.$root = this.$root;
var self = this, var scope = this,
OFFLINE_COOKIE_NAME = 'ng-offline', OFFLINE_COOKIE_NAME = 'ng-offline',
DOCS_PATH = /^\/(api)|(guide)|(cookbook)|(misc)|(tutorial)/, DOCS_PATH = /^\/(api)|(guide)|(cookbook)|(misc)|(tutorial)/,
INDEX_PATH = /^(\/|\/index[^\.]*.html)$/; INDEX_PATH = /^(\/|\/index[^\.]*.html)$/;
this.$location = $location; scope.$location = $location;
scope.versionNumber = angular.version.full;
self.versionNumber = angular.version.full; scope.version = angular.version.full + " " + angular.version.codeName;
self.version = angular.version.full + " " + angular.version.codeName; scope.subpage = false;
self.subpage = false; scope.offlineEnabled = ($cookies[OFFLINE_COOKIE_NAME] == angular.version.full);
self.offlineEnabled = ($cookies[OFFLINE_COOKIE_NAME] == angular.version.full);
if (!$location.path() || INDEX_PATH.test($location.path())) { if (!$location.path() || INDEX_PATH.test($location.path())) {
$location.path('/api').replace(); $location.path('/api').replace();
} }
this.$watch('$location.path()', function(scope, path) { scope.$watch('$location.path()', function(scope, path) {
// ignore non-doc links which are used in examples // ignore non-doc links which are used in examples
if (DOCS_PATH.test(path)) { if (DOCS_PATH.test(path)) {
var parts = path.split('/'); var parts = path.split('/');
self.sectionId = parts[1]; scope.sectionId = parts[1];
self.partialId = parts[2] || 'index'; scope.partialId = parts[2] || 'index';
self.pages = angular.Array.filter(NG_PAGES, {section:self.sectionId}); scope.pages = angular.Array.filter(NG_PAGES, {section: scope.sectionId});
var i = self.pages.length; var i = scope.pages.length;
while (i--) { while (i--) {
if (self.pages[i].id == self.partialId) { if (scope.pages[i].id == scope.partialId) {
self.partialTitle = self.pages[i].name; scope.partialTitle = scope.pages[i].name;
break; break;
} }
} }
if (i<0) { if (i<0) {
self.partialTitle = 'Error: Page Not Found!'; scope.partialTitle = 'Error: Page Not Found!';
delete self.partialId; delete scope.partialId;
} }
} }
}); });
this.getUrl = function(page){ scope.getUrl = function(page) {
return page.section + '/' + page.id; return page.section + '/' + page.id;
}; };
this.getCurrentPartial = function() { scope.getCurrentPartial = function() {
return this.partialId ? ('./partials/' + this.sectionId + '/' + this.partialId + '.html') : ''; return this.partialId ? ('./partials/' + this.sectionId + '/' + this.partialId + '.html') : '';
}; };
this.getClass = function(page) { scope.getClass = function(page) {
var depth = page.depth, var depth = page.depth,
cssClass = 'level-' + depth + (page.name == this.partialId ? ' selected' : ''); cssClass = 'level-' + depth + (page.name == this.partialId ? ' selected' : '');
@ -58,28 +57,28 @@ function DocsController($location, $browser, $window, $cookies) {
return cssClass; return cssClass;
}; };
this.selectedSection = function(section) { scope.selectedSection = function(section) {
return section == self.sectionId ? 'current' : ''; return section == scope.sectionId ? 'current' : '';
}; };
this.selectedPartial = function(partial) { scope.selectedPartial = function(partial) {
return partial.id == self.partialId ? 'current' : ''; return partial.id == scope.partialId ? 'current' : '';
}; };
this.afterPartialLoaded = function() { scope.afterPartialLoaded = function() {
SyntaxHighlighter.highlight(); SyntaxHighlighter.highlight();
$window.scrollTo(0,0); $window.scrollTo(0,0);
$window._gaq.push(['_trackPageview', $location.path()]); $window._gaq.push(['_trackPageview', $location.path()]);
}; };
this.getFeedbackUrl = function() { scope.getFeedbackUrl = function() {
return "mailto:angular@googlegroups.com?" + return "mailto:angular@googlegroups.com?" +
"subject=" + escape("Feedback on " + $location.absUrl()) + "&" + "subject=" + escape("Feedback on " + $location.absUrl()) + "&" +
"body=" + escape("Hi there,\n\nI read " + $location.absUrl() + " and wanted to ask ...."); "body=" + escape("Hi there,\n\nI read " + $location.absUrl() + " and wanted to ask ....");
}; };
/** stores a cookie that is used by apache to decide which manifest ot send */ /** stores a cookie that is used by apache to decide which manifest ot send */
this.enableOffline = function() { scope.enableOffline = function() {
//The cookie will be good for one year! //The cookie will be good for one year!
var date = new Date(); var date = new Date();
date.setTime(date.getTime()+(365*24*60*60*1000)); date.setTime(date.getTime()+(365*24*60*60*1000));
@ -94,14 +93,14 @@ function DocsController($location, $browser, $window, $cookies) {
// bind escape to hash reset callback // bind escape to hash reset callback
angular.element(window).bind('keydown', function(e) { angular.element(window).bind('keydown', function(e) {
if (e.keyCode === 27) { if (e.keyCode === 27) {
self.subpage = false; scope.subpage = false;
self.$eval(); scope.$eval();
} }
}); });
} }
// prevent compilation of code // prevent compilation of code
angular.widget('code', function(element){ angular.widget('code', function(element) {
element.attr('ng:non-bindable', 'true'); element.attr('ng:non-bindable', 'true');
}); });