diff --git a/docs/components/docs/docs.html b/docs/components/docs/docs.html index e472d1f30e6..87805578a3a 100644 --- a/docs/components/docs/docs.html +++ b/docs/components/docs/docs.html @@ -48,11 +48,19 @@

{{module[0].toUpperCase() + module.substr(1)}}

-
+

{{method.name}}

-

+

+ {{method.name}}

diff --git a/docs/components/docs/docs.js b/docs/components/docs/docs.js index f21ac9abe98..dc365bac7ac 100644 --- a/docs/components/docs/docs.js +++ b/docs/components/docs/docs.js @@ -100,6 +100,25 @@ angular }; } + function setMethod($location, methodName) { + return function(methods) { + var methodExists = methods.some(function(methodObj) { + return methodName === methodObj.name; + }); + if (methodExists) { + methods.singleMethod = methodName; + return methods; + } else { + $location.path('/docs/' + module + '/' + cl); + } + }; + } + + var MODULE_TO_CLASSES = { + datastore: ['dataset', 'query'], + storage: [] + }; + $routeProvider .when('/docs', { controller: 'DocsCtrl', @@ -107,7 +126,13 @@ angular resolve: { methods: function($http, $sce) { return $http.get('json/index.json') - .then(filterDocJson($sce)); + .then(filterDocJson($sce)) + .then(function(methods) { + // Prevent displaying permalinks. + // ** Can remove when PubSub api is documented ** + methods.noPermalink = true; + return methods; + }); } } }) @@ -126,11 +151,34 @@ angular controller: 'DocsCtrl', templateUrl: 'components/docs/docs.html', resolve: { - methods: function($q, $http, $route, $sce) { + methods: function($q, $http, $route, $sce, $location) { var module = $route.current.params.module; var cl = $route.current.params.class; + if (MODULE_TO_CLASSES[module].length > 0) { + return $http + .get('json/' + module + '/' + cl + '.json') + .then(filterDocJson($sce)); + } else { + // This is not a class, this is the name of a method. + var method = cl; + return $http.get('json/' + module + '/index.json') + .then(filterDocJson($sce)) + .then(setMethod($location, method)); + } + } + } + }) + .when('/docs/:module/:class/:method', { + controller: 'DocsCtrl', + templateUrl: 'components/docs/docs.html', + resolve: { + methods: function($q, $http, $route, $sce, $location) { + var module = $route.current.params.module; + var cl = $route.current.params.class; + var method = $route.current.params.method; return $http.get('json/' + module + '/' + cl + '.json') - .then(filterDocJson($sce)); + .then(filterDocJson($sce)) + .then(setMethod($location, method)); } } }); @@ -139,13 +187,20 @@ angular 'use strict'; $scope.isActiveUrl = function(url) { - return url.replace(/^#/, '') === $location.path(); + var current = $location.path().replace('/' + methods.singleMethod, ''); + var link = url + .replace(/^#/, '') + .replace('/' + methods.singleMethod, ''); + return current === link; }; $scope.isActiveDoc = function(doc) { return doc.toLowerCase() === $routeParams.module; }; + $scope.activeUrl = '#' + $location.path(); + $scope.singleMethod = methods.singleMethod; + $scope.noPermalink = methods.singleMethod || methods.noPermalink; $scope.methods = methods; $scope.module = $routeParams.module; $scope.pages = [ diff --git a/docs/css/main.css b/docs/css/main.css index ba25cef60b3..3fb0dd203bd 100755 --- a/docs/css/main.css +++ b/docs/css/main.css @@ -564,6 +564,28 @@ h1, h2, h3, h4, h5, h6 { border-bottom: 1px solid rgba(0,0,0,0.05); } +.method-heading { + position: relative; +} + +.permalink { + display: none; + position: absolute; + padding: 0 7px; + left: -24px; + text-decoration: none; + color: #2b70e2; +} + +.permalink:hover { + color: #4285f4; + display: block; +} + +.method-heading:hover .permalink { + display: block; +} + /* Page Title */ diff --git a/docs/home.js b/docs/home.js index e16ef133783..201dd9b54ce 100644 --- a/docs/home.js +++ b/docs/home.js @@ -7,4 +7,16 @@ angular .when('/', { templateUrl: 'home.html' }); + }) + .run(function($rootScope, $location) { + 'use strict'; + + $rootScope.$on('$routeChangeStart', function(event) { + var hash = $location.hash(); + if (hash) { + event.preventDefault(); + $location.hash(''); + $location.replace().path($location.path() + '/' + hash); + } + }); });