-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
127 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Fix for accessibiliy violation: "Provide a mechanism for skipping past repetitive content" | ||
document.addEventListener('DOMContentLoaded', function() { | ||
function insertSkipLink(element) { | ||
const skipLink = document.createElement('div'); | ||
// Create an anchor element with the href pointing to the main content | ||
const anchor = document.createElement('a'); | ||
anchor.classList.add('skip-to-content'); | ||
anchor.href = '#content'; | ||
anchor.innerHTML = 'Skip to Main Content'; | ||
anchor.setAttribute("tabindex", "0"); | ||
skipLink.appendChild(anchor); | ||
if (element.children.length > 1) { | ||
element.insertBefore(skipLink, element.children[1]); | ||
} else { | ||
element.appendChild(skipLink); | ||
} | ||
} | ||
|
||
function handleChanges(mutationsList) { | ||
for (const mutation of mutationsList) { | ||
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { | ||
// Check added nodes for elements with class 'sideMenuPart' and without class 'hidden' | ||
mutation.addedNodes.forEach(function(node) { | ||
if (node.nodeType === 1 && node.classList.contains('sideMenuPart') && !node.classList.contains('hidden')) { | ||
insertSkipLink(node); | ||
} | ||
}); | ||
} else if (mutation.type === 'attributes' && mutation.target.classList.contains('sideMenuPart') && !mutation.target.classList.contains('hidden')) { | ||
// Handle changes in the 'class' attribute of existing elements | ||
// Check if the element is 'sideMenuPart' and not 'hidden' | ||
insertSkipLink(mutation.target); | ||
} | ||
} | ||
} | ||
|
||
const observer = new MutationObserver(handleChanges); | ||
const observerConfig = { | ||
childList: true, | ||
subtree: true, | ||
attributes: true, | ||
attributeFilter: ['class'] | ||
}; | ||
observer.observe(document.body, observerConfig); | ||
}); | ||
|
||
// Fix for accessibilty violation: "Ensure all interactive functionality is operable with the keyboard" | ||
window.onload = function() { | ||
const navButtons = document.querySelectorAll('.navButton'); | ||
|
||
navButtons.forEach(function(navButton) { | ||
// Make the navButton focusable, add accessibility information | ||
navButton.setAttribute('tabindex', '0'); | ||
navButton.setAttribute('role', 'button'); | ||
navButton.setAttribute('aria-expanded', 'false'); | ||
|
||
// Grab the page ID, use it for aria-label and aria-controls | ||
const sectionName = navButton.parentElement.parentElement.getAttribute('pageid') | ||
// Remove the page ID suffix auto-generated by Dokka | ||
const cleanedSectionName = sectionName.substring(0, sectionName.indexOf("////PointingToDeclaration")) | ||
navButton.setAttribute('aria-label', cleanedSectionName); | ||
|
||
const sectionID = navButton.parentElement.parentElement.id | ||
navButton.setAttribute('aria-controls', sectionID); | ||
|
||
// Add event listener for Enter and Space keys | ||
navButton.addEventListener('keydown', function(event) { | ||
if (event.key === 'Enter' || event.key === ' ') { | ||
event.preventDefault(); // Prevent the default action to avoid navigation | ||
this.click(); // Trigger the onclick event | ||
} | ||
}); | ||
|
||
// Update aria-expanded attribute on click | ||
navButton.addEventListener('click', function() { | ||
const isExpanded = navButton.getAttribute('aria-expanded') === 'true'; | ||
navButton.setAttribute('aria-expanded', (!isExpanded).toString()); | ||
}); | ||
}); | ||
} | ||
|
||
// Fix for accessibility violation: "Ensure pages reflow without requiring two-dimensional scrolling without loss of content or functionality" | ||
document.addEventListener('DOMContentLoaded', function() { | ||
const MIN_WINDOW_SIZE = 550 | ||
|
||
// Function to insert 'toggle content' button | ||
function insertToggleContentButton(element) { | ||
const toggleContent = document.createElement('button'); | ||
toggleContent.className = 'aws-toggle-content-btn'; | ||
toggleContent.textContent = '☰'; | ||
|
||
const initiallyVisible = window.innerWidth >= MIN_WINDOW_SIZE | ||
|
||
toggleContent.setAttribute('aria-expanded', initiallyVisible.toString()); | ||
toggleContent.setAttribute('aria-label', 'Toggle code block for' + element.getAttribute("data-togglable")); | ||
toggleContent.setAttribute('aria-controls', element.id); | ||
|
||
// Set initial visibility based on window size | ||
element.style.display = initiallyVisible ? 'block' : 'none' | ||
|
||
// Toggle visibility onclick | ||
toggleContent.onclick = function() { | ||
const isExpanded = toggleContent.getAttribute('aria-expanded') === 'true'; | ||
toggleContent.setAttribute('aria-expanded', (!isExpanded).toString()); | ||
element.style.display = isExpanded ? 'none' : 'block' | ||
}; | ||
|
||
element.parentNode.insertBefore(toggleContent, element); | ||
} | ||
|
||
document.querySelectorAll('.content[data-togglable]').forEach(insertToggleContentButton); | ||
|
||
// Update content visibility on resize | ||
window.addEventListener('resize', function() { | ||
document.querySelectorAll('.content[data-togglable]').forEach(function(element) { | ||
const toggleContent = element.previousSibling; | ||
if (window.innerWidth < MIN_WINDOW_SIZE) { | ||
element.style.display = 'none'; | ||
toggleContent.setAttribute('aria-expanded', 'false'); | ||
} else { | ||
element.style.display = 'block'; | ||
toggleContent.setAttribute('aria-expanded', 'true'); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters