Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 163b762

Browse files
Splaktarjelbourn
authored andcommitted
docs: properly format anchor names and hrefs (#11648)
anchor names should not include any path info hrefs need to include the baseURL in addition to the path Fixes #11644. Relates to #11634. Relates to #11285.
1 parent d3773a5 commit 163b762

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

docs/app/js/anchor.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
return;
2626
}
2727

28-
var anchorEl = $compile('<a class="docs-anchor" ng-href="{{ name }}" name="{{ name }}"></a>')(scope);
28+
var anchorEl = $compile('<a class="docs-anchor" ng-href="{{ href }}" name="{{ name }}"></a>')(scope);
2929

3030
// Wrap contents inside of the anchor element.
3131
anchorEl.append(element.contents());
@@ -40,16 +40,23 @@
4040
* Creates URL from the text content of the element and writes it into the scope.
4141
*/
4242
function createContentURL() {
43-
var path = scope.$root.$location ? scope.$root.$location.path() : '';
43+
var path = '';
4444
var name = element.text();
45+
// Use $window.location.pathname to get the path with the baseURL included.
46+
// $location.path() does not include the baseURL. This is important to support how the docs
47+
// are deployed with baseURLs like /latest, /HEAD, /1.1.13, etc.
48+
if (scope.$root.$window && scope.$root.$window.location) {
49+
path = scope.$root.$window.location.pathname;
50+
}
4551
name = name
4652
.trim() // Trim text due to browsers extra whitespace.
4753
.replace(/'/g, '') // Transform apostrophes words to a single one.
4854
.replace(unsafeCharRegex, '-') // Replace unsafe chars with a dash symbol.
4955
.replace(/-{2,}/g, '-') // Remove repeating dash symbols.
5056
.replace(/^-|-$/g, '') // Remove preceding or ending dashes.
5157
.toLowerCase(); // Link should be lower-case for accessible URL.
52-
scope.name = path + '#' + name;
58+
scope.name = name;
59+
scope.href = path + '#' + name;
5360
}
5461
}
5562
}

docs/app/js/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ function(SERVICES, COMPONENTS, DEMOS, PAGES,
148148
AngularyticsProvider.setEventHandlers(['GoogleUniversal']);
149149
}])
150150

151-
.run(['$rootScope', '$location', 'Angularytics', function($rootScope, $location, Angularytics) {
151+
.run(['$rootScope', '$window', 'Angularytics', function($rootScope, $window, Angularytics) {
152152
Angularytics.init();
153-
$rootScope.$location = $location;
153+
$rootScope.$window = $window;
154154
}])
155155

156156
.factory('menu', [
@@ -453,7 +453,7 @@ function(SERVICES, COMPONENTS, DEMOS, PAGES, $location, $rootScope, $http, $wind
453453
type: "link"
454454
};
455455

456-
if (path == '/') {
456+
if (path === '/') {
457457
self.selectSection(introLink);
458458
self.selectPage(introLink, introLink);
459459
return;

0 commit comments

Comments
 (0)