diff options
| author | Matias Niemelä | 2013-06-13 22:37:13 -0400 | 
|---|---|---|
| committer | Misko Hevery | 2013-06-17 22:17:44 -0700 | 
| commit | 46dfb92afd185c93f60ca90a72653f33d7cb18e8 (patch) | |
| tree | 51862e5793866ffbb34c16e5053376af5932e2c6 /docs/src/templates/js/docs.js | |
| parent | ef22968810d555f78d3bbf7b5428757690c8cc70 (diff) | |
| download | angular.js-46dfb92afd185c93f60ca90a72653f33d7cb18e8.tar.bz2 | |
feat(ngdocs): provide support for user to jump between different versions of the angularjs documentation
Diffstat (limited to 'docs/src/templates/js/docs.js')
| -rw-r--r-- | docs/src/templates/js/docs.js | 66 | 
1 files changed, 62 insertions, 4 deletions
| diff --git a/docs/src/templates/js/docs.js b/docs/src/templates/js/docs.js index 97fea067..ae0f1e58 100644 --- a/docs/src/templates/js/docs.js +++ b/docs/src/templates/js/docs.js @@ -4,6 +4,64 @@ var docsApp = {    serviceFactory: {}  }; +docsApp.controller.DocsVersionsCtrl = ['$scope', '$window', 'NG_VERSIONS', function($scope, $window, NG_VERSIONS) { +  $scope.versions = expandVersions(NG_VERSIONS); +  $scope.version  = ($scope.version || angular.version.full).match(/^([\d\.]+\d+)/)[1]; //match only the number +   +  $scope.jumpToDocsVersion = function(value) { +    var isLastStable, +        version, +        versions = $scope.versions; +    for(var i=versions.length-1;i>=0;i--) { +      var v = versions[i]; +      if(v.version == value) { +        var next = versions[i - 1]; +        isLastStable = v.stable && (!next || next && !next.stable); +        version = v; +        break; +      } +    }; + +    if(version && version.version >= '1.0.0') { +      //the older versions have a different path to the docs within their repo directory +      var docsPath = version.version < '1.0.2' ? 'docs-' + version.version : 'docs'; + +      //the last stable version should redirect to docs.angularjs.org instead of code.angularjs.org +      var url = 'http://' + +                  (isLastStable ? +                    'docs.angularjs.org' : +                    'code.angularjs.org/' + version.version + '/' + docsPath); + +      $window.location = url; +    } +  }; + +  function expandVersions(angularVersions) { +    var unstableVersionStart = 0; +    angularVersions.forEach(function(version) { +      var split = version.split('.'); +      unstableVersionStart = split[1] % 2 == 1 ? +                        Math.max(unstableVersionStart, parseInt(split[0] + '' + split[1])) : +                        unstableVersionStart; +    }); + +    var versions = []; +    for(var i=angularVersions.length-1;i>=0;i--) { +      var version = angularVersions[i]; +      var split = version.split('.'); +      var stable = parseInt(split[0] + '' + split[1]) < unstableVersionStart; +      versions.push({ +        version : version, +        stable : stable, +        title : 'AngularJS - v' + version, +        group : (stable ? 'Stable' : 'Unstable') +      }); +    }; + +    return versions; +  }; +}]; +  docsApp.controller.DocsNavigationCtrl = ['$scope', 'fullTextSearch', '$location', function($scope, fullTextSearch, $location) {    fullTextSearch.init();    $scope.search = function(q) { @@ -47,7 +105,7 @@ docsApp.controller.DocsNavigationCtrl = ['$scope', 'fullTextSearch', '$location'    };  }]; -docsApp.serviceFactory.fullTextSearch = ['$q', '$rootScope', function($q, $rootScope) { +docsApp.serviceFactory.fullTextSearch = ['$q', '$rootScope', 'NG_PAGES', function($q, $rootScope, NG_PAGES) {    return {      dbName : 'docs',      indexName : 'docsindex', @@ -374,7 +432,7 @@ docsApp.serviceFactory.openJsFiddle = function(templateMerge, formPostData, angu  }; -docsApp.serviceFactory.sections = function sections() { +docsApp.serviceFactory.sections = ['NG_PAGES', function sections(NG_PAGES) {    var sections = {      guide: [],      api: [], @@ -407,7 +465,7 @@ docsApp.serviceFactory.sections = function sections() {    });    return sections; -}; +}];  docsApp.controller.DocsController = function($scope, $location, $window, $cookies, sections) { @@ -706,7 +764,7 @@ docsApp.controller.DocsController = function($scope, $location, $window, $cookie  }; -angular.module('docsApp', ['ngResource', 'ngRoute', 'ngCookies', 'ngSanitize', 'bootstrap', 'bootstrapPrettify']). +angular.module('docsApp', ['ngResource', 'ngRoute', 'ngCookies', 'ngSanitize', 'bootstrap', 'bootstrapPrettify', 'docsData']).    config(function($locationProvider) {      $locationProvider.html5Mode(true).hashPrefix('!');    }). | 
