Skip to content

Commit 9ac6b20

Browse files
authored
Merge branch 'main' into feature/review-tr-styles
2 parents 31497ad + 61b0d0f commit 9ac6b20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1884
-1606
lines changed

assets-src/js/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {formErrorSummary} from "./main/form-error-summary";
66
import {navigation} from "./main/navigation";
77
import {responsiveTables} from "./main/responsive-tables";
88
import {flashes} from "./main/flashes";
9+
import {headingAnchors} from './main/heading-anchors';
910

1011
function domLoadedActions() {
1112
accountMenu();
@@ -15,6 +16,7 @@ function domLoadedActions() {
1516
formErrorSummary();
1617
responsiveTables();
1718
flashes();
19+
headingAnchors();
1820

1921
/* Create a navDoubleLevel object and initiate double-level navigation for a <ul> with the correct data-component attribute */
2022
const navDoubleIntro = document.querySelector('ul[data-component="nav-double-intro"]');

assets-src/js/main/account-menu.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {translate} from "./translations";
33
let accountMenu = function () {
44

55
let userInfo = null;
6+
let maxWidth = 1120;
67

78
const buildAccountMenu = function(userInfo) {
89
if (userInfo == null || userInfo.length < 1) {
@@ -54,7 +55,8 @@ let accountMenu = function () {
5455
toggleButton.innerHTML = '<span class="sr-only">' + translate.translate('my-account', languageCode) + ' <span class="visuallyhidden">(' + translate.translate( 'logged-in' , languageCode) + ')</span></span><div class="avatar avatar--small icon"><img alt="" src="' + userInfo.avatar.thumbnail + '"/></div>';
5556

5657
// Media query event handler
57-
let mq = window.matchMedia('(min-width: 71.25em)');
58+
let mqValue = maxWidth / 16;
59+
let mq = window.matchMedia('(min-width: ' + mqValue + 'em)');
5860
mq.addListener(insertAccountBtn);
5961
insertAccountBtn(mq);
6062

assets-src/js/main/flashes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const flashes = (function () {
2727
}
2828

2929
html += '<div class="l-box note note--' + type + '" role="' + (type === 'error' ? 'alert' : 'status')
30-
+ '" aria-labelledby="' + type + '-summary-title" tabindex="-1" data-component = "' + type + '-summary" >';
30+
+ '" aria-labelledby="' + type + '-summary-title" tabindex="-1" ' +
31+
'data-component = "' + type + '-summary" data-anchor="no">';
3132
html += '<h2 id="' + type + '-summary-title" class="txt-saturn">' + flashes['title-' + type] + '</h2>';
3233
html += '<ul class="clean-list" role="list">';
3334
for (let i in flashes[type]) {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Add anchor links to any H2 - H6 within the <main> element that:
3+
* - have an id
4+
* - are not children of a <nav> element
5+
* - do not have an ancestor with the data-anchor="no" attribute, with
6+
* the `hidden` attribute or with the .visuallyhidden class
7+
* - do not themselves have the data-anchor="no" attribute, the `hidden`
8+
* attribute or the .visuallyhidden class
9+
*
10+
* Generate the anchor using the existing heading ID value.
11+
*/
12+
13+
import {translate} from './translations';
14+
15+
let headingAnchors = function () {
16+
17+
let languageCode = document.documentElement.lang;
18+
19+
// Only add heading anchor links on "full" sites
20+
if (languageCode === 'en' || languageCode === 'ja' || languageCode === 'zh-hans') {
21+
22+
let headingsArray= Array.from(document.querySelectorAll('main h2[id], main h3[id], main h4[id], main h5[id], main h6[id]'));
23+
24+
if (headingsArray.length > 0) {
25+
26+
// Filter out headings that:
27+
// - Are not children of <nav>
28+
// - Do not have an ancestor with the data-anchor="no" attribute
29+
// - Do not have an ancestor with the `hidden` attribute
30+
// - Do not have an ancestor with the `.visuallyhidden` class
31+
// - Do not themselves have the data-anchor="no" attribute
32+
// - Do not themselves have the `hidden` attribute
33+
// - Do not themselves have the `.visuallyhidden` class
34+
let targetedHeadings = headingsArray.filter(function(heading) {
35+
let insideNav = heading.closest('nav') !== null;
36+
let parentHasDataAttribute = heading.closest('[data-anchor="no"]') !== null;
37+
let hiddenParent = heading.closest('[hidden]') !== null;
38+
let visuallyhiddenParent = heading.closest('.visuallyhidden') !== null;
39+
let hasDataAttribute = heading.getAttribute('data-anchor') === 'no';
40+
let isHidden = heading.getAttribute('hidden');
41+
let isVisuallyhidden = heading.classList.contains('visuallyhidden');
42+
43+
return !insideNav && !parentHasDataAttribute && !hiddenParent && !visuallyhiddenParent && !hasDataAttribute && !isHidden && !isVisuallyhidden;
44+
});
45+
46+
if (targetedHeadings.length > 0) {
47+
targetedHeadings.forEach(function(heading) {
48+
49+
let anchor = document.createElement('a');
50+
51+
anchor.setAttribute('href', '#' + heading.id);
52+
anchor.setAttribute('class', 'heading-anchor');
53+
anchor.innerHTML = '<span aria-hidden="true">&sect;</span>'
54+
+'<span class="visuallyhidden">'
55+
+ translate.translate('anchor', languageCode) + '</span>';
56+
heading.append('\xa0');
57+
heading.appendChild(anchor);
58+
59+
});
60+
}
61+
62+
}
63+
64+
}
65+
66+
}
67+
68+
export {headingAnchors};

assets-src/js/main/translations.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const translate = {
4040
},
4141
'en': {
4242
'admin': 'Admin',
43+
'anchor': 'anchor',
4344
'backToMainMenu': 'Back to main menu',
4445
'cancelReply': 'Cancel reply',
4546
'controlsDescription': 'carousel controls',
@@ -116,6 +117,7 @@ const translate = {
116117
},
117118
'ja': {
118119
'admin': 'アドミン',
120+
'anchor': '__anchor',
119121
'backToMainMenu': 'メインメニューに戻る',
120122
'cancelReply': '返信をキャンセル',
121123
'controlsDescription': 'コントロールの説明',
@@ -154,6 +156,7 @@ const translate = {
154156
},
155157
'zh-hans': {
156158
'admin': '管理',
159+
'anchor': '__anchor',
157160
'backToMainMenu': '返回主目录',
158161
'cancelReply': '取消回复',
159162
'controlsDescription': '轮播图控件',

assets-src/styles/sass/30-base/_links.scss

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ a.with-icon--after {
1818
border: 0;
1919
color: $link-color;
2020
cursor: pointer;
21-
padding-left: rem(2);
22-
padding-right: rem(2);
21+
padding-inline: rem(2);
2322
text-decoration: underline; /* 1 */
2423
text-decoration-skip-ink: auto; // Not supported by Safari
2524
text-underline-offset: 0.25em; // Supported by Safari
@@ -48,4 +47,27 @@ a.with-icon--after {
4847
color: $black;
4948
outline-width: 0; /* 2 */
5049
}
50+
}
51+
52+
.heading-anchor {
53+
@extend a, :not([class]);
54+
55+
color: $storm-gray;
56+
font-weight: normal;
57+
opacity: 0.82;
58+
text-underline-offset: auto;
59+
60+
&:visited {
61+
color: $storm-gray;
62+
}
63+
64+
&:hover {
65+
color: $storm-gray;
66+
opacity: 1;
67+
}
68+
69+
&:focus {
70+
color: $black;
71+
opacity: 1;
72+
}
5173
}

assets-src/styles/sass/30-base/_print.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ footer {
723723
.banner,
724724
#lang-nav,
725725
.logo-link .visuallyhidden,
726+
.heading-anchor,
726727
[data-trigger],
727728
[data-toggle],
728729
#global-nav ul,

design-system-config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
'Styles' => '/styles/',
1818
'Layouts' => '/layouts/',
1919
'Components' => '/components/',
20-
'Third party plugins' => '/third-party-plugins/',
20+
'Scripts' => '/scripts/',
2121
'Templates' => '/templates/',
2222
],
2323
'templates_path' => 'design-system-templates',

design-system-templates/base.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
{% block breadcrumbs %}
6969
{% endblock %}
7070

71-
<main id="main">
71+
<main id="main" {% block extra_main_attributes %}{% endblock %}>
7272
{% block content %}
7373
{% endblock %}
7474
</main>

design-system-templates/components/activity.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</div>
3838
</li>
3939
<li>
40-
<div class="card card--event workshop" data-component="card">
40+
<div class="card card--event workshop" data-component="card" data-anchor="no">
4141
<div class="card__text">
4242
<h3 class="card__heading"><a href="path/to/page" class="card__link">How do you want to pay?</a></h3>
4343
<p class="txt-pluto with-icon--before"><img class="icon" src="/dist/assets/svg/calendar.svg" width="15" height="15" alt aria-hidden="true" /> <time datetime="2020-11-15">15 November 2020</time></p>
@@ -46,7 +46,7 @@
4646
</div>
4747
</li>
4848
<li>
49-
<div class="card card--event talk" data-component="card">
49+
<div class="card card--event talk" data-component="card" data-anchor="no">
5050
<div class="card__text">
5151
<h3 class="card__heading"><a href="path/to/page" class="card__link">Cognitive AI - mimicking how we think</a></h3>
5252
<p class="txt-pluto with-icon--before"><img class="icon" src="/dist/assets/svg/calendar.svg" width="15" height="15" alt aria-hidden="true" /> <time datetime="2020-12-20">20 December 2020</time></p>

0 commit comments

Comments
 (0)