Skip to content

Commit

Permalink
Fix "Ensure pages reflow without requiring two-dimensional scrolling …
Browse files Browse the repository at this point in the history
…without loss of content or functionality"
  • Loading branch information
lauzadis committed Jul 1, 2024
1 parent ad984ba commit f09bf02
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/dokka-presets/css/aws-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,24 @@ div .compiler-info, .fold-button, .run-button {
height: auto;
opacity: 1;
z-index: 999; /* Ensure the skip link is on top of other content */
}

.content .symbol .monospace {
white-space: pre-wrap;
word-wrap: break-word;
overflow-wrap: break-word;
}

.aws-toggle-content-btn {
font-size: 24px;
background: none;
border: none;
cursor: pointer;
padding: 8px;
}

@media (max-width: 320px) {
.content[data-togglable] {
display: none;
}
}
52 changes: 52 additions & 0 deletions docs/dokka-presets/templates/base.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,58 @@
}
</script>

<script>
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);
if (!initiallyVisible) {
element.style.display = 'none';
}
toggleContent.onclick = function() {
const isExpanded = toggleContent.getAttribute('aria-expanded') === 'true';
toggleContent.setAttribute('aria-expanded', (!isExpanded).toString());
if (isExpanded) {
element.style.display = 'none';
} else {
element.style.display = 'block';
}
};
// Insert the hamburger button before the content element
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');
}
});
});
});
</script>
</head>
<body>
<div class="root">
Expand Down

0 comments on commit f09bf02

Please sign in to comment.