-
Notifications
You must be signed in to change notification settings - Fork 9
add functionality and styles for toggling page content #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
eshaben
wants to merge
5
commits into
main
Choose a base branch
from
eshaben/page-level-toggle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b4b7adf
add functionality and styles for toggling page content
eshaben 919ae02
update mobile styling
eshaben 3181756
take into account resizing screens
eshaben 642ee04
move labels outside of tabbed element and into header wrapper
eshaben fbd9b25
Update material-overrides/toggle-page.html
eshaben File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,98 @@ | ||
| /** Page-level toggle **/ | ||
| .h1-wrapper { | ||
| display: flex; | ||
| gap: 3em; | ||
| flex-direction: row; | ||
| justify-content: space-between; | ||
| margin-bottom: 1.25em; | ||
| } | ||
|
|
||
| .md-typeset .h1-wrapper h1 { | ||
| margin: 0; | ||
| } | ||
|
|
||
| /* Make the labels container look like a pill toggle */ | ||
| .js .md-typeset .h1-wrapper .tabbed-labels { | ||
| position: relative; | ||
| background: var(--athens-gray); | ||
| border-radius: 2em; | ||
| width: fit-content; | ||
| min-width: 132px; | ||
| height: min-content; | ||
| } | ||
|
|
||
| .md-typeset .h1-wrapper .tabbed-labels > label { | ||
| flex: 1; | ||
| text-align: center; | ||
| cursor: pointer; | ||
| z-index: 1; | ||
| padding: 0.5em 1em; | ||
| } | ||
|
|
||
| .md-typeset .h1-wrapper .tabbed-labels > label > [href]:first-child, | ||
| .md-typeset .h1-wrapper .tabbed-labels > label a { | ||
| color: var(--black); | ||
| text-decoration: none; | ||
| display: block; | ||
| } | ||
|
|
||
| /* Slider background */ | ||
| .js .md-typeset .h1-wrapper .tabbed-labels:before { | ||
| content: ""; | ||
| position: absolute; | ||
| top: 0.2em; | ||
| left: 0.2em; | ||
| width: calc(50% - 0.2em); | ||
| height: calc(100% - 0.4em); | ||
| background: var(--pink); | ||
eshaben marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| border-radius: 2em; | ||
| transition: transform 0.3s ease; | ||
| z-index: 0; | ||
| } | ||
|
|
||
| .js .md-typeset .h1-wrapper .tabbed-labels.option-2-active::before { | ||
| transform: translateX(100%); | ||
| } | ||
|
|
||
| .js .md-typeset .h1-wrapper .tabbed-labels.option-1-active::before { | ||
| transform: translateX(0); | ||
| } | ||
|
|
||
| .js .md-typeset .h1-wrapper .tabbed-labels.option-1-active label:nth-child(1) a, | ||
| .js | ||
| .md-typeset | ||
| .h1-wrapper | ||
| .tabbed-labels.option-2-active | ||
| label:nth-child(2) | ||
| a { | ||
| color: var(--md-default-bg-color); | ||
| } | ||
|
|
||
| .md-typeset .page-level-options > .tabbed-content { | ||
| border: none; | ||
| border-radius: unset; | ||
| margin-top: -1em; | ||
| } | ||
|
|
||
| .md-typeset .page-level-options .tabbed-block > *, | ||
| .md-typeset .page-level-options .tabbed-block > .tabbed-set { | ||
| margin-left: unset; | ||
| margin-right: unset; | ||
| } | ||
|
|
||
| .md-typeset .page-toggle .tabbed-set, | ||
| .md-typeset .page-level-options .tabbed-block h1 { | ||
| margin-top: 0; | ||
| } | ||
|
|
||
| .hidden-toc { | ||
| display: none; | ||
| } | ||
|
|
||
| @media screen and (max-width: 768px) { | ||
| .h1-wrapper { | ||
| flex-direction: column-reverse; | ||
| flex-wrap: wrap; | ||
| gap: 1em; | ||
| } | ||
| } | ||
This file contains hidden or 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,101 @@ | ||
| {% extends "main.html" %} | ||
|
|
||
| {% block styles %} | ||
| {{ super() }} | ||
| <link rel="stylesheet" href="{{ 'assets/stylesheets/toggle-page.css' | url }}"> | ||
| {% endblock %} | ||
|
|
||
| {% block content %} | ||
| <div class="page-toggle"> | ||
| {% set content = page.content %} | ||
| {# Create wrapper for the h1 #} | ||
| {% if '<h1' in content %} | ||
| {% set content = content.replace('<h1', '<div class="h1-wrapper"><h1', 1) %} | ||
| {% set content = content.replace('</h1>', '</h1></div>', 1) %} | ||
| {% endif %} | ||
|
|
||
| {# Find and move the first tabbed-labels div into the h1-wrapper #} | ||
| {% if 'class="tabbed-labels"' in content %} | ||
| {% set labels_start = content.find('<div class="tabbed-labels"') %} | ||
| {% if labels_start != -1 %} | ||
| {% set after_start = content[labels_start:] %} | ||
| {% set first_close = after_start.find('</div>') %} | ||
eshaben marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {% if first_close != -1 %} | ||
| {% set labels_end = labels_start + first_close + 6 %} | ||
| {% set before_labels = content[:labels_start] %} | ||
| {% set labels_div = content[labels_start:labels_end] %} | ||
| {% set after_labels = content[labels_end:] %} | ||
|
|
||
| {# Remove the labels div from its original position #} | ||
| {% set content_without_labels = before_labels + after_labels %} | ||
|
|
||
| {# Find the h1-wrapper closing div and insert labels before it #} | ||
| {% if '</div>' in content_without_labels %} | ||
| {% set wrapper_close_pos = content_without_labels.find('</div>') %} | ||
| {% set before_wrapper_close = content_without_labels[:wrapper_close_pos] %} | ||
| {% set after_wrapper_close = content_without_labels[wrapper_close_pos:] %} | ||
| {% set content = before_wrapper_close + labels_div + after_wrapper_close %} | ||
| {% endif %} | ||
| {% endif %} | ||
| {% endif %} | ||
| {% endif %} | ||
|
|
||
| {{ content | safe }} | ||
| </div> | ||
| {% endblock %} | ||
|
|
||
| {% block scripts %} | ||
| {{ super() }} | ||
| <script> | ||
| document.addEventListener('DOMContentLoaded', () => { | ||
| const tabbedSet = document.querySelector('.tabbed-set'); | ||
| if (!tabbedSet) return; | ||
|
|
||
| tabbedSet.classList.add('page-level-options'); | ||
|
|
||
| const inputs = tabbedSet.querySelectorAll('input[name="__tabbed_1"]'); | ||
eshaben marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const labels = document.querySelector('.tabbed-labels'); | ||
| const tocItems = document.querySelectorAll('.md-nav--secondary .md-nav__item'); | ||
|
|
||
| // Update TOC visibility based on active tab | ||
| const updateToc = () => { | ||
| const tabbedBlocks = tabbedSet.querySelectorAll(':scope > .tabbed-content > .tabbed-block'); | ||
|
|
||
| tabbedBlocks.forEach((block) => { | ||
| const isHidden = window.getComputedStyle(block).display === 'none'; | ||
| const h2s = block.querySelectorAll('h2'); | ||
|
|
||
| h2s.forEach((h2) => { | ||
| const id = h2.id; | ||
| if (!id) return; | ||
| tocItems.forEach((item) => { | ||
| const link = item.querySelector('.md-nav__link'); | ||
| if (!link?.href.includes(id)) return; | ||
| item.classList.toggle('hidden-toc', isHidden); | ||
| }); | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| // Update tab label states | ||
| const updateLabels = () => { | ||
| if (labels) { | ||
| labels.classList.toggle('option-1-active', inputs[0]?.checked); | ||
| labels.classList.toggle('option-2-active', inputs[1]?.checked); | ||
| } | ||
| }; | ||
|
|
||
| // Initialize | ||
| updateToc(); | ||
| updateLabels(); | ||
|
|
||
| // Watch for changes | ||
| inputs.forEach((input) => | ||
| input.addEventListener('change', () => { | ||
| updateLabels(); | ||
| updateToc(); | ||
| }) | ||
| ); | ||
| }); | ||
| </script> | ||
| {% endblock %} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.