-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add show and hide for tags on homepage (#64)
* add show and hide for tags on homepage * Move tags JS to separate init function * Remove unused template comment * Clean up template whitespace * Remove unused tag__body class * Only add event listener if the element is on the page * JS styleguide tweaks * Tweak tag toggle text and styles * Add support for no-JS browsing in tags logic * Clean up HTML of unnecessary tag attributes * Change implementation so speed is the same regardless of number of tags * Fix rendering of tags in no-JS mode * Add ARIA attributes to facilitate tags toggle for screen readers * Extract tags toggle code to separate file * Clean up unused/duplicate HTML and CSS * Order tags by item count * Use slug instead of name for tag filtering Fix #44 * Extract tag to specific template * Use slug instead of name for tag filtering Missing from f62c2eb. Fix #44
- Loading branch information
1 parent
1693818
commit 923e070
Showing
9 changed files
with
89 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Toggles the visibility of the whole tag list. | ||
* By default only a subset of all tags is shown. | ||
*/ | ||
const toggleTagsVisibility = (tagsContainer, e) => { | ||
const tagsToggle = e.target; | ||
const wasVisible = JSON.parse(tagsToggle.getAttribute('aria-expanded')); | ||
const isVisible = !wasVisible; | ||
tagsToggle.setAttribute('aria-expanded', isVisible); | ||
tagsContainer.setAttribute('aria-hidden', !isVisible); | ||
|
||
// First toggle hide/show in the inner element, then toggle the animation. | ||
tagsContainer.children[0].classList.toggle('u-hide', !isVisible); | ||
tagsContainer.classList.toggle('tags__additional--show', isVisible) | ||
tagsToggle.innerHTML = isVisible ? 'Show fewer tags' : 'Show more tags'; | ||
}; | ||
|
||
export default { | ||
init() { | ||
const tagsToggle = document.querySelector('[data-tags-toggle]'); | ||
const tagsContainer = document.querySelector('[data-tags-additional]'); | ||
|
||
if (tagsToggle) { | ||
tagsToggle.addEventListener('click', toggleTagsVisibility.bind(null, tagsContainer)); | ||
} | ||
}, | ||
}; |
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,23 @@ | ||
.js .tags__additional { | ||
opacity: 0; | ||
transition: opacity .75s; | ||
|
||
&.tags__additional--show { | ||
opacity: 1; | ||
} | ||
} | ||
|
||
.tag__button { | ||
border: none; | ||
background: none; | ||
font-size: .75rem; | ||
padding: 0; | ||
color: $color-base-link; | ||
|
||
&:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
@include hover(background-color, transparent); | ||
@include hover(color, $color-base-link-hover); | ||
} |
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
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,4 @@ | ||
<a href="/?tag={{ tag.slug }}" class="btn -tag"> | ||
{{ tag.name }} | ||
{% if tag.count %}<span>{{ tag.count }}</span>{% endif %} | ||
</a> |
This file was deleted.
Oops, something went wrong.
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