expand: a11y and remove jQuery #339 #452

This commit is contained in:
Sören Weber 2023-02-03 08:57:55 +01:00
parent 322a86ae47
commit 00faf15af5
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
7 changed files with 111 additions and 52 deletions

View file

@ -20,14 +20,16 @@ This document shows you what's new in the latest release. For a detailed list of
## 5.11.0 (not yet released) ## 5.11.0 (not yet released)
- {{% badge style="note" title=" " %}}Change{{% /badge %}} The JavaScript code for handling image lightboxes (was [Featherlight](https://noelboss.github.io/featherlight)) was replaced by a CSS-only solution. - {{% badge style="note" title=" " %}}Change{{% /badge %}} In the effort to comply with WCAG standards, the implementation of the [`expand` shortcode]({{% relref "shortcodes/expand" %}}) was changed. The functionality of the new implementation does not work with old browsers (Internet Explorer 11).
- {{% badge style="note" title=" " %}}Change{{% /badge %}} The JavaScript code for handling image lightboxes (provided by [Featherlight](https://noelboss.github.io/featherlight)) was replaced by a CSS-only solution.
This also changed the [lightbox effects]({{% relref "cont/markdown#lightbox" %}}) parameter from `featherlight=false` to `lightbox=false`. Nevertheless you don't need to change anything as the old name will be used as a fallback. This also changed the [lightbox effects]({{% relref "cont/markdown#lightbox" %}}) parameter from `featherlight=false` to `lightbox=false`. Nevertheless you don't need to change anything as the old name will be used as a fallback.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} [GitHub releases](https://github.com/McShelby/hugo-theme-relearn/tags) are also now tagged for the main version (eg. `1.2.x`) and major version (eg. `1.x`) making it easier for you to pin the theme to a certain version.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Translation for Czech. This language is not supported for search. - {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Translation for Czech. This language is not supported for search.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} [GitHub releases](https://github.com/McShelby/hugo-theme-relearn/tags) are also now tagged for the main version (eg. `1.2.x`) and major version (eg. `1.x`) making it easier for you to pin the theme to a certain version.
--- ---
## 5.10.0 (2023-01-25) ## 5.10.0 (2023-01-25)
@ -132,7 +134,7 @@ This document shows you what's new in the latest release. For a detailed list of
## 5.3.0 (2022-10-07) ## 5.3.0 (2022-10-07)
- {{% badge style="note" title=" " %}}Change{{% /badge %}} In the effort to comply with WCAG standards, the implementation of the collapsible menu was changed. Although the functionality of the new implementation works with old browsers (Internet Explorer 11), the display of the expander icons does not and is limited to modern browsers. - {{% badge style="note" title=" " %}}Change{{% /badge %}} In the effort to comply with WCAG standards, the implementation of the collapsible menu was changed. The functionality of the new implementation does not work with old browsers (Internet Explorer 11).
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} [Image formatting]({{% relref "cont/markdown#add-css-classes" %}}) has two new classes to align images to the `left` or `right`. Additionally, the already existing `inline` option is now documented. - {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} [Image formatting]({{% relref "cont/markdown#add-css-classes" %}}) has two new classes to align images to the `left` or `right`. Additionally, the already existing `inline` option is now documented.

View file

@ -7,6 +7,10 @@ The `expand` shortcode displays an expandable/collapsible section of text.
{{% expand title="Expand me..." %}}Thank you!{{% /expand %}} {{% expand title="Expand me..." %}}Thank you!{{% /expand %}}
{{% notice note %}}
This only works in modern browsers.
{{% /notice %}}
## Usage ## Usage
While the examples are using shortcodes with named parameter you are free to use positional as well or also call this shortcode from your own partials. While the examples are using shortcodes with named parameter you are free to use positional as well or also call this shortcode from your own partials.

View file

@ -8,19 +8,16 @@
{{- end }} {{- end }}
{{- $direction := T "Reading-direction" | default "ltr" }} {{- $direction := T "Reading-direction" | default "ltr" }}
{{- with $context }} {{- with $context }}
<div class="expand {{- $id := partial "make-random-md5.hugo" }}
{{- if $expanded }} expand-expanded{{ end -}} <div class="expand">
"> <input type="checkbox" id="expand-{{ $id }}" aria-controls="expandcontent-{{ $id }}" {{ if $expanded }} checked{{ end }}>
{{- $c:=""}}{{/* things are getting complicated when search tries to open the expand box while jquery sets the display CSS on the element */}} <label class="expand-label" for="expand-{{ $id }}" >
<a class="expand-label" onclick="$t=$(this); if($t.parent('.expand-expanded.expand-marked').length){ $t.next().css('display','none') }else if($t.parent('.expand-marked').length){ $t.next().css('display','block') }else{ $t.next('.expand-content').slideToggle(100); } $t.parent().toggleClass('expand-expanded');">
<i class="fas fa-chevron-down"></i> <i class="fas fa-chevron-down"></i>
<i class="fas fa-chevron-left expand-rtl direction-{{ $direction }}"></i> <i class="fas fa-chevron-left expand-rtl direction-{{ $direction }}"></i>
<i class="fas fa-chevron-right expand-ltr direction-{{ $direction }}"></i> <i class="fas fa-chevron-right expand-ltr direction-{{ $direction }}"></i>
{{ $title }} {{ $title }}
</a> </label>
<div class="expand-content" style="display: <div id="expandcontent-{{ $id }}" class="expand-content">
{{- if $expanded }} block{{ else }} none{{ end -}}
;">
{{ $content | safeHTML }} {{ $content | safeHTML }}
</div> </div>
</div> </div>

View file

@ -29,14 +29,17 @@
div.attachments .box-content { div.attachments .box-content {
padding-left: 1.75rem; padding-left: 1.75rem;
} }
.expand > .expand-label > .expand-rtl.direction-rtl { .expand > label {
display: none; left: 0;
} }
.expand > .expand-label > .expand-ltr.direction-rtl { .expand > input + label > .fa-chevron-left {
display: inline-block; display: none !important;
} }
.expand.expand-expanded > .expand-label > .fa-chevron-right { .expand > input + label > .fa-chevron-right {
display: none; display: inline-block !important;
}
.expand > input:checked + label > .fa-chevron-right {
display: none !important;
} }
#body .tab-nav-button { #body .tab-nav-button {
margin-left: 4px; margin-left: 4px;
@ -184,6 +187,18 @@
font-family: "Work Sans", "Helvetica", "Tahoma", "Geneva", "Arial", sans-serif; /* var(--MAIN-TITLES-TEXT-font) */ font-family: "Work Sans", "Helvetica", "Tahoma", "Geneva", "Arial", sans-serif; /* var(--MAIN-TITLES-TEXT-font) */
} }
.expand > label {
color: #486ac9; /* var(--MAIN-LINK-color) */
}
.expand > label:hover {
color: #202891; /* var(--MAIN-LINK-HOVER-color) */
}
.expand > label:after {
color: #202891; /* var(--MAIN-LINK-HOVER-color) */
}
div.box { div.box {
background-color: rgba( 128, 128, 128, 1 ); /* var(--INTERNAL-BOX-NEUTRAL-color) */ background-color: rgba( 128, 128, 128, 1 ); /* var(--INTERNAL-BOX-NEUTRAL-color) */
} }

View file

@ -1031,50 +1031,70 @@ option {
.expand { .expand {
margin-bottom: 1rem; margin-bottom: 1rem;
margin-top: 1rem; margin-top: 1rem;
position: relative;
} }
.expand-label { .expand > input {
-webkit-appearance: none;
appearance: none;
cursor: pointer; cursor: pointer;
} }
.expand-label > .fas { .expand > label {
cursor: pointer;
display: inline;
font-weight: 300;
inset-inline-start: 0;
line-height: 1.1;
margin-top: .2rem;
position: absolute;
}
.expand > label:after {
background-color: var(--INTERNAL-MAIN-LINK-HOVER-color);
content: "";
display: block;
height: 1px;
width: 0%;
transition: width 0.5s ease;
}
.expand > label:hover:after {
width: 100%;
}
.expand > label > .fas {
font-size: .8rem; font-size: .8rem;
width: .6rem; width: .6rem;
} }
.expand-content { .expand > .expand-content {
margin-top: .5rem; margin-top: .5rem;
} }
/* closed expander */
/* expander collapsed, default */ .expand > input + label + div {
.expand > .expand-label > .fa-chevron-down {
display: none;
}
.expand > .expand-label > .fa-chevron-left,
.expand > .expand-label > .fa-chevron-right {
display: inline-block;
}
/* expander expanded, controlled by expand.html */
.expand.expand-expanded > .expand-label > .fa-chevron-down {
display: inline-block;
}
.expand.expand-expanded > .expand-label > .fa-chevron-left,
.expand.expand-expanded > .expand-label > .fa-chevron-right {
display: none; display: none;
} }
/* expander expand collapsed marked, must override logic of expand.html, controlled by theme.js */ .expand > input + label > .fa-chevron-down {
.expand:not(.expand-expanded).expand-marked > .expand-label > .fa-chevron-down {
display: inline-block;
}
.expand:not(.expand-expanded).expand-marked > .expand-label > .fa-chevron-left,
.expand:not(.expand-expanded).expand-marked > .expand-label > .fa-chevron-right {
display: none; display: none;
} }
.expand:not(.expand-expanded).expand-marked > .expand-content { .expand > input + label > .fa-chevron-left,
/* this will disable jquery's animation */ .expand > input + label > .fa-chevron-right {
display: block !important; display: inline-block;
}
/* open expander */
.expand > input:checked + label + div {
display: block;
}
.expand > input:checked + label > .fa-chevron-down {
display: inline-block;
}
.expand > input:checked + label > .fa-chevron-left,
.expand > input:checked + label > .fa-chevron-right {
display: none;
} }
/* turn off unsuitable expander for this reading direction */ /* turn off unsuitable expander for this reading direction */

View file

@ -368,6 +368,18 @@ pre .copy-to-clipboard-button:hover {
color: var(--INTERNAL-CODE-BLOCK-BG-color); color: var(--INTERNAL-CODE-BLOCK-BG-color);
} }
.expand > label {
color: var(--INTERNAL-MAIN-LINK-color);
}
.expand > label:hover {
color: var(--INTERNAL-MAIN-LINK-HOVER-color);
}
.expand > label:after {
background-color: var(--INTERNAL-MAIN-LINK-HOVER-color);
}
#homelinks { #homelinks {
background-color: var(--INTERNAL-MENU-HEADER-BORDER-color); background-color: var(--INTERNAL-MENU-HEADER-BORDER-color);
border-color: var(--INTERNAL-MENU-HEADER-BORDER-color); border-color: var(--INTERNAL-MENU-HEADER-BORDER-color);

View file

@ -793,7 +793,12 @@ function mark() {
var parent = markedElements[i].parentNode; var parent = markedElements[i].parentNode;
while( parent && parent.classList ){ while( parent && parent.classList ){
if( parent.classList.contains( 'expand' ) ){ if( parent.classList.contains( 'expand' ) ){
parent.classList.add( 'expand-marked' ); var expandInputs = parent.querySelectorAll( 'input:not(.expand-marked)' );
if( expandInputs.length ){
expandInputs[0].classList.add( 'expand-marked' );
expandInputs[0].dataset.checked = expandInputs[0].checked ? 'true' : 'false';
expandInputs[0].checked = true;
}
} }
if( parent.tagName.toLowerCase() === 'li' ){ if( parent.tagName.toLowerCase() === 'li' ){
var toggleInputs = parent.querySelectorAll( 'input.toggle:not(.menu-marked)' ); var toggleInputs = parent.querySelectorAll( 'input.toggle:not(.menu-marked)' );
@ -880,8 +885,13 @@ function unmark() {
toggleInputs[0].classList.remove( 'menu-marked' ); toggleInputs[0].classList.remove( 'menu-marked' );
} }
} }
if( parent.classList.contains( 'expand-marked' ) ){ if( parent.classList.contains( 'expand' ) ){
parent.classList.remove( 'expand-marked' ); var expandInputs = parent.querySelectorAll( 'input.expand-marked' );
if( expandInputs.length ){
expandInputs[0].checked = expandInputs[0].dataset.checked === 'true';
expandInputs[0].dataset.checked = null;
expandInputs[0].classList.remove( 'expand-marked' );
}
} }
parent = parent.parentNode; parent = parent.parentNode;
} }
@ -909,7 +919,6 @@ function unhighlight( es, options ){
} }
}; };
// replace jQuery.createPseudo with https://stackoverflow.com/a/66318392 // replace jQuery.createPseudo with https://stackoverflow.com/a/66318392
function elementContains( txt, e ){ function elementContains( txt, e ){
var regex = RegExp( txt, 'i' ); var regex = RegExp( txt, 'i' );