astro-accelerator 0.0.41 → 0.0.43

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.0.41",
2
+ "version": "0.0.43",
3
3
  "author": "Steve Fenton",
4
4
  "name": "astro-accelerator",
5
5
  "description": "A super-lightweight, accessible, SEO-friendly starter project for Astro",
package/public/js/main.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { addIntersectionObserver, addListImageIntersectionObserver } from './modules/animation.js';
3
3
  import { addResizedEvent } from './modules/resizing.js';
4
4
  import { addStickyNavigation } from './modules/nav-sticky.js';
5
- import { addMobileNavigation } from './modules/nav-mobile.js';
5
+ import { addMobileNav } from './modules/nav-mobile.js';
6
6
  import { setClickableBlocks } from './modules/click-blocks.js';
7
7
  import { setExternalLinkAttributes } from './modules/external-links.js';
8
8
 
@@ -11,7 +11,7 @@ const resizedEventName = addResizedEvent();
11
11
  setClickableBlocks();
12
12
  setExternalLinkAttributes();
13
13
  addStickyNavigation('.site-header', '#site-nav', '#site-nav > ul', resizedEventName);
14
- addMobileNavigation('.navigation-icon', '#site-nav', resizedEventName);
14
+ addMobileNav(resizedEventName);
15
15
  addIntersectionObserver('.anim-show-parent img, .anim-show-parent > *:not(h1, h2, h3, h4, h5, h6)');
16
16
  addListImageIntersectionObserver('.post-list img');
17
17
 
@@ -13,12 +13,26 @@ import { getFocusableElement, trapFocusForward, trapReverseFocus } from './focus
13
13
  * The mobile navigation intercepts the bookmark link and opens the navigation in a modal
14
14
  * overlay, trapping keyboard focus until the overlay is closed.
15
15
  *
16
- * @param {string} iconSelector
17
- * @param {string} navigationSelector
18
16
  * @param {string} resizedEventName
19
17
  */
20
- function addMobileNavigation(iconSelector, navigationSelector, resizedEventName) {
21
- const icon = qs(iconSelector);
18
+ function addMobileNav(resizedEventName) {
19
+ const icons = qsa('[data-navigationid');
20
+ for (let icon of icons) {
21
+ addMobileNavigation(icon, resizedEventName);
22
+ }
23
+ }
24
+
25
+ /**
26
+ * @param {HTMLElement} icon
27
+ * @param {string} resizedEventName
28
+ */
29
+ function addMobileNavigation(icon, resizedEventName) {
30
+ icon.tabIndex = 0;
31
+ const navigationSelector = icon.dataset.navigationid;
32
+ const iconType = icon.firstElementChild && icon.firstElementChild.tagName == 'svg'
33
+ ? 'svg'
34
+ : 'element';
35
+
22
36
  const originalIcon = icon.innerHTML;
23
37
  const overlay = document.createElement('div');
24
38
  const dataOpen = 'data-open';
@@ -52,7 +66,7 @@ import { getFocusableElement, trapFocusForward, trapReverseFocus } from './focus
52
66
 
53
67
  function openMobileMenu(){
54
68
  document.body.style.overflow = 'hidden';
55
- const menuElement = qs(navigationSelector);
69
+ const menuElement = qs('#' + navigationSelector);
56
70
 
57
71
  overlay.innerHTML = menuElement.outerHTML;
58
72
  overlay.className = 'overlay overlay-menu';
@@ -63,12 +77,10 @@ import { getFocusableElement, trapFocusForward, trapReverseFocus } from './focus
63
77
  });
64
78
 
65
79
  // Modal Accessibility
66
- const title = qs('.site-nav-title', overlay);
67
- title.setAttribute('id', 'modal-title');
68
- title.setAttribute('tabindex', '-1');
80
+ const title = menuElement.getAttribute('aria-label') ?? '';
69
81
  overlay.setAttribute('role', 'dialog');
70
82
  overlay.setAttribute('aria-modal', 'true');
71
- overlay.setAttribute('aria-labelledby', 'modal-title');
83
+ overlay.setAttribute('aria-label', title);
72
84
 
73
85
  // Trap Focus to Visible Overlay
74
86
  const focusElements = getFocusableElement(overlay);
@@ -80,13 +92,15 @@ import { getFocusableElement, trapFocusForward, trapReverseFocus } from './focus
80
92
  trapFocusForward(e, icon);
81
93
  });
82
94
 
83
- icon.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg"
84
- width="40" height="40" viewBox="0 0 24 24" stroke-width="1.5"
85
- fill="none" stroke-linecap="round" stroke-linejoin="round">
86
- <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
87
- <line x1="18" y1="6" x2="6" y2="18" />
88
- <line x1="6" y1="6" x2="18" y2="18" />
89
- </svg>`;
95
+ if (iconType === 'svg') {
96
+ icon.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg"
97
+ width="40" height="40" viewBox="0 0 24 24" stroke-width="1.5"
98
+ fill="none" stroke-linecap="round" stroke-linejoin="round">
99
+ <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
100
+ <line x1="18" y1="6" x2="6" y2="18" />
101
+ <line x1="6" y1="6" x2="18" y2="18" />
102
+ </svg>`;
103
+ }
90
104
 
91
105
  document.body.appendChild(overlay);
92
106
  icon.setAttribute(dataOpen, dataOpen);
@@ -119,4 +133,4 @@ import { getFocusableElement, trapFocusForward, trapReverseFocus } from './focus
119
133
  })
120
134
  }
121
135
 
122
- export { addMobileNavigation };
136
+ export { addMobileNav };
@@ -34,8 +34,9 @@ function addStickyNavigation(headerSelector, navigationSelector, navigationListS
34
34
  if (dimensions.navigationHeight < ((dimensions.browserHeight - dimensions.headerHeight) - buffer)
35
35
  && dimensions.browserWidth > 860) {
36
36
  console.log('Navigation: Sticky Mode');
37
- navigation.classList.add(className)
38
- navigation.style.top = dimensions.headerHeight.toString() + 'px';
37
+ navigation.classList.add(className);
38
+ const top = navigation.parentElement?.offsetTop ?? 220;
39
+ navigation.style.top = top + 'px';
39
40
  } else {
40
41
  console.log('Navigation: Fixed Mode');
41
42
  navigation.classList.remove(className);
@@ -41,7 +41,7 @@ const authorImage = authorList?.image?.src
41
41
  <a href={ accelerator.urlFormatter.addSlashToAddress(authorList.mainAuthor.url) + '1/' } itemprop="author">{ authorList.mainAuthor.frontmatter.title }</a>
42
42
  }{authorList.contributors.map((writer) => (
43
43
  <a href={ accelerator.urlFormatter.addSlashToAddress(writer.url) + '1/' } itemprop="contributor">{ writer.frontmatter.title }</a>
44
- ))}.
44
+ ))}
45
45
  <br /><time datetime={ frontmatter.pubDate.toString() } itemprop="datePublished">
46
46
  { accelerator.dateFormatter.formatDate(frontmatter.pubDate, lang) }
47
47
  </time>
@@ -21,7 +21,7 @@ const accelerator = new Accelerator(SITE);
21
21
  const search = accelerator.posts.all().filter(PostFiltering.isSearch).shift() ?? null;
22
22
  ---
23
23
  <header class="site-header">
24
- <a href="#site-nav" class="navigation-icon" title={ _(Translations.header.open_menu) }><svg xmlns="http://www.w3.org/2000/svg"
24
+ <a href="#site-nav" data-navigationid="site-nav" class="navigation-icon" title={ _(Translations.header.open_menu) }><svg xmlns="http://www.w3.org/2000/svg"
25
25
  width="40" height="40" viewBox="0 0 24 24" stroke-width="1.5"
26
26
  fill="none" stroke-linecap="round" stroke-linejoin="round">
27
27
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/>