astro-accelerator 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.3.6",
2
+ "version": "0.3.7",
3
3
  "author": "Steve Fenton",
4
4
  "name": "astro-accelerator",
5
5
  "description": "A super-lightweight, accessible, SEO-friendly starter project for Astro",
@@ -16,7 +16,7 @@ import { getFocusableElement, trapFocusForward, trapReverseFocus } from './focus
16
16
  * @param {string} resizedEventName
17
17
  */
18
18
  function addMobileNav(resizedEventName) {
19
- const icons = qsa('[data-navigationid');
19
+ const icons = qsa('[data-navigationid]');
20
20
  for (let icon of icons) {
21
21
  addMobileNavigation(icon, resizedEventName);
22
22
  }
@@ -37,7 +37,7 @@ function addMobileNav(resizedEventName) {
37
37
  */
38
38
  function addMobileNavigation(icon, resizedEventName) {
39
39
  icon.tabIndex = 0;
40
- const navigationSelector = icon.dataset.navigationid;
40
+ const navigationSelector = icon.dataset.navigationid || '';
41
41
  const iconType = icon.firstElementChild && icon.firstElementChild.tagName == 'svg'
42
42
  ? 'svg'
43
43
  : 'element';
@@ -46,6 +46,9 @@ function addMobileNav(resizedEventName) {
46
46
  const overlay = document.createElement('div');
47
47
  const dataOpen = 'data-open';
48
48
 
49
+ icon.setAttribute('aria-expanded', 'false');
50
+ icon.setAttribute('aria-controls', navigationSelector);
51
+
49
52
  // Focus trap (forwards the tab / shift-tab back to the menu)
50
53
  icon.addEventListener('keydown', function(e) {
51
54
  if (icon.getAttribute(dataOpen) === dataOpen) {
@@ -86,6 +89,7 @@ function addMobileNav(resizedEventName) {
86
89
  overlay.innerHTML = menuElement.outerHTML;
87
90
  overlay.className = 'overlay overlay-menu';
88
91
  overlay.style.display = 'block';
92
+ menuElement.style.display = 'none';
89
93
 
90
94
  qsa('[id]', overlay).forEach((elem) => {
91
95
  elem.id = 'overlay__' + elem.id
@@ -119,10 +123,13 @@ function addMobileNav(resizedEventName) {
119
123
 
120
124
  document.body.appendChild(overlay);
121
125
  icon.setAttribute(dataOpen, dataOpen);
126
+ icon.setAttribute('aria-expanded', 'true');
122
127
  focusElements.first.focus();
123
128
  }
124
129
 
125
130
  function closeMobileMenu() {
131
+ const menuElement = qs('#' + navigationSelector);
132
+ menuElement.style.display = 'initial';
126
133
  document.body.style.overflow = 'auto';
127
134
  document.documentElement.style.paddingInlineEnd = '0';
128
135
 
@@ -134,6 +141,7 @@ function addMobileNav(resizedEventName) {
134
141
 
135
142
  icon.innerHTML = originalIcon;
136
143
  icon.removeAttribute(dataOpen);
144
+ icon.setAttribute('aria-expanded', 'false');
137
145
  }
138
146
 
139
147
  icon.addEventListener('click', function (e) {
@@ -13,7 +13,7 @@ function enhanceSearchIcon() {
13
13
  const form = doc.querySelector('#site-search');
14
14
  const input = form.querySelector('#site-search-query');
15
15
  const results = doc.querySelector('#site-search-results');
16
-
16
+ icon.setAttribute('aria-expanded', 'false');
17
17
 
18
18
  input?.setAttribute('autofocus', 'autofocus');
19
19
 
@@ -26,8 +26,7 @@ function enhanceSearchIcon() {
26
26
  <line x1="18" y1="6" x2="6" y2="18"></line>
27
27
  <line x1="6" y1="6" x2="18" y2="18"></line>
28
28
  </svg>`;
29
- close.addEventListener('click', () => dialog.close());
30
-
29
+
31
30
  const script = doc.querySelector('script[src*="/search.js"]');
32
31
  const scr = document.createElement('script');
33
32
  for (let att, i = 0, atts = script.attributes, n = atts.length; i < n; i++){
@@ -45,8 +44,12 @@ function enhanceSearchIcon() {
45
44
  icon.addEventListener('click', (e) => {
46
45
  e.preventDefault();
47
46
  dialog.showModal();
47
+ icon.setAttribute('aria-expanded', 'true');
48
48
  return false;
49
- })
49
+ });
50
+
51
+ close.addEventListener('click', () => dialog.close());
52
+ dialog.addEventListener('close', () => icon.setAttribute('aria-expanded', 'false'));
50
53
  });
51
54
  }
52
55
  }
@@ -25,7 +25,7 @@ const search = accelerator.posts.all().filter(PostFiltering.isSearch).shift() ??
25
25
  stats.stop();
26
26
  ---
27
27
  <header class="site-header">
28
- <a href="#site-nav" data-navigationid="site-nav" class="navigation-icon" title={ _(Translations.header.open_menu) }><svg xmlns="http://www.w3.org/2000/svg"
28
+ <a href="#site-nav" data-navigationid="site-nav" class="navigation-icon" title={ _(Translations.header.toggle_menu) }><svg xmlns="http://www.w3.org/2000/svg"
29
29
  width="40" height="40" viewBox="0 0 24 24" stroke-width="1.5"
30
30
  fill="none" stroke-linecap="round" stroke-linejoin="round">
31
31
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
@@ -35,7 +35,7 @@ stats.stop();
35
35
  </svg></a>
36
36
  <a href={ (SITE.subfolder ?? '') + '/' } class="site-title" translate="no">{ SITE.title }</a>
37
37
  {search != null &&
38
- <a href={ accelerator.urlFormatter.formatAddress(search.url) } class="search-icon" title={ _(Translations.header.open_search) }><svg xmlns="http://www.w3.org/2000/svg"
38
+ <a href={ accelerator.urlFormatter.formatAddress(search.url) } class="search-icon" title={ _(Translations.header.toggle_search) }><svg xmlns="http://www.w3.org/2000/svg"
39
39
  width="40" height="40" viewBox="0 0 24 24" stroke-width="1"
40
40
  fill="none" stroke-linecap="round" stroke-linejoin="round">
41
41
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
@@ -51,7 +51,6 @@ stats.stop();
51
51
  <Header frontmatter={ frontmatter } headings={ headings } lang={ lang } />
52
52
  <Breadcrumbs frontmatter={ frontmatter } headings={ headings } lang={ lang } breadcrumbs={ breadcrumbs } />
53
53
  <div class="content-group">
54
- <Navigation lang={ lang } />
55
54
  <main id="site-main">
56
55
  <article itemscope itemtype="https://schema.org/Article">
57
56
  <header>
@@ -70,6 +69,7 @@ stats.stop();
70
69
  </div>
71
70
  </article>
72
71
  </main>
72
+ <Navigation lang={ lang } />
73
73
  </div>
74
74
  <Footer frontmatter={ frontmatter } headings={ headings } lang={ lang }>
75
75
  <Copyright frontmatter={ frontmatter } headings={ headings } lang={ lang } />
@@ -4,7 +4,7 @@
4
4
  "en": "Breadcrumb"
5
5
  },
6
6
  "site_navigation": {
7
- "en": "Site Navigation"
7
+ "en": "Site"
8
8
  },
9
9
  "toc": {
10
10
  "en": "Table of contents"
@@ -34,11 +34,11 @@
34
34
  }
35
35
  },
36
36
  "header": {
37
- "open_menu": {
38
- "en": "Open menu"
37
+ "toggle_menu": {
38
+ "en": "Toggle menu"
39
39
  },
40
- "open_search": {
41
- "en": "Open site search"
40
+ "toggle_search": {
41
+ "en": "Toggle site search"
42
42
  }
43
43
  },
44
44
  "navigation": {