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

docs: properly format anchor names and hrefs #11648

Merged
merged 1 commit into from
Feb 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions docs/app/js/anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
return;
}

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

// Wrap contents inside of the anchor element.
anchorEl.append(element.contents());
Expand All @@ -40,16 +40,23 @@
* Creates URL from the text content of the element and writes it into the scope.
*/
function createContentURL() {
var path = scope.$root.$location ? scope.$root.$location.path() : '';
var path = '';
var name = element.text();
// Use $window.location.pathname to get the path with the baseURL included.
// $location.path() does not include the baseURL. This is important to support how the docs
// are deployed with baseURLs like /latest, /HEAD, /1.1.13, etc.
if (scope.$root.$window && scope.$root.$window.location) {
path = scope.$root.$window.location.pathname;
}
name = name
.trim() // Trim text due to browsers extra whitespace.
.replace(/'/g, '') // Transform apostrophes words to a single one.
.replace(unsafeCharRegex, '-') // Replace unsafe chars with a dash symbol.
.replace(/-{2,}/g, '-') // Remove repeating dash symbols.
.replace(/^-|-$/g, '') // Remove preceding or ending dashes.
.toLowerCase(); // Link should be lower-case for accessible URL.
scope.name = path + '#' + name;
scope.name = name;
scope.href = path + '#' + name;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions docs/app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ function(SERVICES, COMPONENTS, DEMOS, PAGES,
AngularyticsProvider.setEventHandlers(['GoogleUniversal']);
}])

.run(['$rootScope', '$location', 'Angularytics', function($rootScope, $location, Angularytics) {
.run(['$rootScope', '$window', 'Angularytics', function($rootScope, $window, Angularytics) {
Angularytics.init();
$rootScope.$location = $location;
$rootScope.$window = $window;
}])

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

if (path == '/') {
if (path === '/') {
self.selectSection(introLink);
self.selectPage(introLink, introLink);
return;
Expand Down