mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-04-16 04:41:03 +00:00
fix:docs: properly distinguish between being offline and 404
This commit is contained in:
parent
c5f3a413bc
commit
1e8448b9e5
2 changed files with 14 additions and 26 deletions
|
|
@ -15,7 +15,18 @@ function DocsController($location, $browser, $window) {
|
|||
self.sectionId = parts[1];
|
||||
self.partialId = parts[2] || 'index';
|
||||
self.pages = angular.Array.filter(NG_PAGES, {section:self.sectionId});
|
||||
self.partialTitle = (angular.Array.filter(self.pages, function(doc){return doc.id == self.partialId;})[0]||{}).name || 'Error: Page Not Found!';
|
||||
|
||||
var i = self.pages.length;
|
||||
while (i--) {
|
||||
if (self.pages[i].id == self.partialId) {
|
||||
self.partialTitle = self.pages[i].name
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i<0) {
|
||||
self.partialTitle = 'Error: Page Not Found!';
|
||||
delete self.partialId;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -24,7 +35,7 @@ function DocsController($location, $browser, $window) {
|
|||
};
|
||||
|
||||
this.getCurrentPartial = function(){
|
||||
return './' + this.sectionId + '/' + this.partialId + '.html';
|
||||
return this.partialId ? ('./' + this.sectionId + '/' + this.partialId + '.html') : '';
|
||||
};
|
||||
|
||||
this.getClass = function(page) {
|
||||
|
|
@ -84,26 +95,3 @@ function TutorialInstructionsCtrl($cookieStore) {
|
|||
$cookieStore.put('selEnv', id);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Display 404 page and suggest new link if possible
|
||||
*/
|
||||
angular.service('$xhr.error', function($location) {
|
||||
function suggestLink(wrongLink) {
|
||||
var link = wrongLink.replace(/^!\/?/, '');
|
||||
|
||||
if (link.match(/^angular/)) return 'api/' + link;
|
||||
else if (link.match(/^cookbook/)) return link.replace('cookbook.', 'cookbook/');
|
||||
}
|
||||
|
||||
return function(request, response) {
|
||||
var suggestion = suggestLink($location.hashPath),
|
||||
HTML_404 = '<h1>Error: Page Not Found</h1>' +
|
||||
'<p>Sorry this page has not been found.</p>';
|
||||
|
||||
if (suggestion)
|
||||
HTML_404 += '<p>Looks like you are using an old link. Please update your bookmark to: <a href="#!/' + suggestion + '">' + suggestion + '</a></p>';
|
||||
|
||||
request.callback(200, HTML_404);
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<h2>OFFLINE</h2>
|
||||
|
||||
<p>This page if unavailable because your are offline.</p>
|
||||
<p>This page is currently unavailable because your are offline.</p>
|
||||
<p>Please connect to the Internet and reload the page.</p>
|
||||
|
|
|
|||
Loading…
Reference in a new issue