From 72144e8b2be99bd277b4aaab18d23ad7cb763c40 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Fri, 8 May 2015 11:47:40 -0400 Subject: [PATCH] docs - follow a version throughout the site fixes #548 --- docs/site/components/docs/docs-services.js | 6 +++++- docs/site/components/docs/docs.js | 18 +++++++++--------- .../components/subpage/subpage-directive.js | 4 ++-- docs/site/home.html | 2 +- docs/site/home.js | 8 ++++---- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/docs/site/components/docs/docs-services.js b/docs/site/components/docs/docs-services.js index cadf03f722e..0d753916bd3 100644 --- a/docs/site/components/docs/docs-services.js +++ b/docs/site/components/docs/docs-services.js @@ -1,9 +1,13 @@ angular.module('gcloud.docs') - .factory('getLinks', function(versions, pages) { + .factory('getLinks', function($rootScope, versions, pages) { 'use strict'; // `version` is the current version being browsed. return function(version) { + if (!version) { + version = $rootScope.ACTIVE_VERSION || $rootScope.latestVersion; + } + var baseUrl = '#/docs/' + version; var VERSIONS = pages.VERSIONS; diff --git a/docs/site/components/docs/docs.js b/docs/site/components/docs/docs.js index 2de5a16a872..66e38296f8f 100644 --- a/docs/site/components/docs/docs.js +++ b/docs/site/components/docs/docs.js @@ -256,10 +256,6 @@ angular return a.constructor ? -1: a.name > b.name ? 1 : -1; } - function getLinks($route, getLinks) { - return getLinks($route.current.params.version); - } - $routeProvider .when('/docs', { redirectTo: '/docs/' + versions[0] @@ -271,17 +267,17 @@ angular .when('/docs/:version', { controller: 'DocsCtrl', templateUrl: 'site/components/docs/docs.html', - resolve: { methods: getMethods, links: getLinks } + resolve: { methods: getMethods } }) .when('/docs/:version/:module', { controller: 'DocsCtrl', templateUrl: 'site/components/docs/docs.html', - resolve: { methods: getMethods, links: getLinks } + resolve: { methods: getMethods } }) .when('/docs/:version/:module/:class', { controller: 'DocsCtrl', templateUrl: 'site/components/docs/docs.html', - resolve: { methods: getMethods, links: getLinks } + resolve: { methods: getMethods } }); }) @@ -290,22 +286,27 @@ angular $rootScope.$on('$routeChangeStart', function(event, route) { var url = $location.path(); + if (url.indexOf('/docs/') === -1 || (!route.params || !route.params.version)) { // This isn't a `docs` route or it's not one that expects a version. // No need to re-direct request. return; } + if (versions.indexOf(route.params.version) === -1) { // No version specified where one was expected. // Route to same url with latest version prepended. event.preventDefault(); $route.reload(); $location.path(url.replace('docs/', 'docs/' + versions[0] + '/')); + return; } + + $rootScope.ACTIVE_VERSION = route.params.version; }); }) - .controller('DocsCtrl', function($location, $scope, $routeParams, methods, $http, links, versions) { + .controller('DocsCtrl', function($location, $scope, $routeParams, methods, $http, versions) { 'use strict'; $scope.isActiveUrl = function(url) { @@ -340,7 +341,6 @@ angular $scope.methods = methods; $scope.version = $routeParams.version; $scope.versions = versions; - $scope.links = links; }) .controller('HistoryCtrl', function($scope, versions) { diff --git a/docs/site/components/subpage/subpage-directive.js b/docs/site/components/subpage/subpage-directive.js index 9b6e9da4ad1..5cde1597ade 100644 --- a/docs/site/components/subpage/subpage-directive.js +++ b/docs/site/components/subpage/subpage-directive.js @@ -1,6 +1,6 @@ angular .module('gcloud.subpage', ['gcloud.header']) - .directive('subpage', function($location, $parse, getLinks) { + .directive('subpage', function($rootScope, $location, $parse, getLinks) { 'use strict'; return { @@ -8,7 +8,7 @@ angular templateUrl: 'site/components/subpage/subpage.html', link: function($scope, elem, attrs) { $scope.title = attrs.title; - $scope.links = getLinks('master'); + $scope.links = getLinks(); $scope.headerTemplateUrl = attrs.headerTemplateurl; if (attrs.isActiveUrl) { diff --git a/docs/site/home.html b/docs/site/home.html index 79d059e8d28..2c3ab3f3321 100755 --- a/docs/site/home.html +++ b/docs/site/home.html @@ -24,7 +24,7 @@

One-line npm install