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

Commit 4148550

Browse files
Splaktarjelbourn
authored andcommitted
docs: links from header directives are not compatible with base URL (#11634)
fix a11y contrast issue with visited header links on toolbars Fixes #11285
1 parent da45942 commit 4148550

File tree

3 files changed

+64
-60
lines changed

3 files changed

+64
-60
lines changed

docs/app/css/style.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ body.docs-body {
2929
height: auto;
3030
}
3131

32-
.docs-anchor {
32+
.docs-anchor,
33+
.docs-anchor:visited {
3334
color: inherit;
3435
}
3536

@@ -54,7 +55,6 @@ body.docs-body {
5455
border-top: 1px solid #ddd;
5556
}
5657

57-
5858
.training_link {
5959
color: #D32F2F;
6060
text-transform: none;

docs/app/js/anchor.js

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,60 @@
1-
(function() {
2-
angular
3-
.module('docsApp')
4-
.directive('h4', MdAnchorDirective)
5-
.directive('h3', MdAnchorDirective)
6-
.directive('h2', MdAnchorDirective)
7-
.directive('h1', MdAnchorDirective);
8-
9-
function MdAnchorDirective($mdUtil, $compile) {
10-
11-
/** @const @type {RegExp} */
12-
var unsafeCharRegex = /[&\s+$,:;=?@"#{}|^~[`%!'\]./()*\\]/g;
13-
14-
return {
15-
restrict: 'E',
16-
scope: {},
17-
require: '^?mdContent',
18-
link: postLink
19-
};
20-
21-
function postLink(scope, element, attr, ctrl) {
22-
23-
// Only create anchors when being inside of a md-content.
24-
if (!ctrl) {
25-
return;
26-
}
27-
28-
var anchorEl = $compile('<a class="docs-anchor" ng-href="#{{ name }}" name="{{ name }}"></a>')(scope);
29-
30-
// Wrap contents inside of the anchor element.
31-
anchorEl.append(element.contents());
32-
33-
// Append the anchor element to the directive element.
34-
element.append(anchorEl);
35-
36-
// Delay the URL creation, because the inner text might be not interpolated yet.
37-
$mdUtil.nextTick(createContentURL);
38-
39-
/**
40-
* Creates URL from the text content of the element and writes it into the scope.
41-
*/
42-
function createContentURL() {
43-
scope.name = element.text()
44-
.trim() // Trim text due to browsers extra whitespace.
45-
.replace(/'/g, '') // Transform apostrophes words to a single one.
46-
.replace(unsafeCharRegex, '-') // Replace unsafe chars with a dash symbol.
47-
.replace(/-{2,}/g, '-') // Remove repeating dash symbols.
48-
.replace(/^-|-$/g, '') // Remove preceding or ending dashes.
49-
.toLowerCase(); // Link should be lower-case for accessible URL.
50-
}
51-
}
52-
}
53-
54-
// Manually specify $inject because Strict DI is enabled.
55-
MdAnchorDirective.$inject = ['$mdUtil', '$compile'];
56-
57-
})();
1+
(function() {
2+
angular
3+
.module('docsApp')
4+
.directive('h4', MdAnchorDirective)
5+
.directive('h3', MdAnchorDirective)
6+
.directive('h2', MdAnchorDirective)
7+
.directive('h1', MdAnchorDirective);
8+
9+
function MdAnchorDirective($mdUtil, $compile, $rootScope) {
10+
11+
/** @const @type {RegExp} */
12+
var unsafeCharRegex = /[&\s+$,:;=?@"#{}|^~[`%!'\]./()*\\]/g;
13+
14+
return {
15+
restrict: 'E',
16+
scope: {},
17+
require: '^?mdContent',
18+
link: postLink
19+
};
20+
21+
function postLink(scope, element, attr, ctrl) {
22+
23+
// Only create anchors when being inside of a md-content.
24+
if (!ctrl) {
25+
return;
26+
}
27+
28+
var anchorEl = $compile('<a class="docs-anchor" ng-href="{{ name }}" name="{{ name }}"></a>')(scope);
29+
30+
// Wrap contents inside of the anchor element.
31+
anchorEl.append(element.contents());
32+
33+
// Append the anchor element to the directive element.
34+
element.append(anchorEl);
35+
36+
// Delay the URL creation, because the inner text might be not interpolated yet.
37+
$mdUtil.nextTick(createContentURL);
38+
39+
/**
40+
* Creates URL from the text content of the element and writes it into the scope.
41+
*/
42+
function createContentURL() {
43+
var path = scope.$root.$location ? scope.$root.$location.path() : '';
44+
var name = element.text();
45+
name = name
46+
.trim() // Trim text due to browsers extra whitespace.
47+
.replace(/'/g, '') // Transform apostrophes words to a single one.
48+
.replace(unsafeCharRegex, '-') // Replace unsafe chars with a dash symbol.
49+
.replace(/-{2,}/g, '-') // Remove repeating dash symbols.
50+
.replace(/^-|-$/g, '') // Remove preceding or ending dashes.
51+
.toLowerCase(); // Link should be lower-case for accessible URL.
52+
scope.name = path + '#' + name;
53+
}
54+
}
55+
}
56+
57+
// Manually specify $inject because Strict DI is enabled.
58+
MdAnchorDirective.$inject = ['$mdUtil', '$compile'];
59+
60+
})();

docs/app/js/app.js

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

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

155156
.factory('menu', [

0 commit comments

Comments
 (0)