Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
docs(docs): preserve path to current doc page when switching versions
Browse files Browse the repository at this point in the history
Preserve URL path when switching between doc versions.

Closes #4661
Closes #5773
  • Loading branch information
sebholstein authored and petebacondarwin committed Jan 14, 2014
1 parent e324c14 commit 02a4582
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions docs/src/templates/js/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ var docsApp = {
filter: {}
};

docsApp.controller.DocsVersionsCtrl = ['$scope', '$window', 'NG_VERSIONS', 'NG_VERSION', function($scope, $window, NG_VERSIONS, NG_VERSION) {
docsApp.controller.DocsVersionsCtrl = ['$scope', '$rootScope', '$window', 'NG_VERSIONS', 'NG_VERSION', function($scope, $rootScope, $window, NG_VERSIONS, NG_VERSION) {
$scope.docs_versions = NG_VERSIONS;
$scope.docs_version = NG_VERSIONS[0];

$scope.jumpToDocsVersion = function(version) {
$window.location = version.url;
var currentPagePath = '';

// preserve URL path when switching between doc versions
if (angular.isObject($rootScope.currentPage) && $rootScope.currentPage.section && $rootScope.currentPage.id) {
currentPagePath = '/' + $rootScope.currentPage.section + '/' + $rootScope.currentPage.id;
}

$window.location = version.url + currentPagePath;
};
}];

Expand Down Expand Up @@ -645,7 +653,7 @@ docsApp.serviceFactory.sections = ['NG_PAGES', function sections(NG_PAGES) {
}];


docsApp.controller.DocsController = function($scope, $location, $window, $cookies, sections) {
docsApp.controller.DocsController = function($scope, $rootScope, $location, $window, $cookies, sections) {
$scope.fold = function(url) {
if(url) {
$scope.docs_fold = '/notes/' + url;
Expand Down Expand Up @@ -736,9 +744,9 @@ docsApp.controller.DocsController = function($scope, $location, $window, $cookie
sectionName = SECTION_NAME[sectionId] || sectionId,
page = sections.getPage(sectionId, partialId);

$scope.currentPage = sections.getPage(sectionId, partialId);
$rootScope.currentPage = sections.getPage(sectionId, partialId);

if (!$scope.currentPage) {
if (!$rootScope.currentPage) {
$scope.partialTitle = 'Error: Page Not Found!';
}

Expand Down

0 comments on commit 02a4582

Please sign in to comment.