|
1 | | -<div class="tableOfContentsWrapper"> |
2 | | - <div class="tableOfContentsContainer open mobileForceHide" id="tocContainer-{$idPrefix}"> |
3 | | - <div class="tableOfContentsHeader"> |
4 | | - <span class="tableOfContentsTitle">{lang}wcf.message.toc{/lang}</span> |
5 | | - <span class="jsOnly">[<a href="#" class="jsTableOfContentsHide">{lang}wcf.message.toc.hide{/lang}</a><a href="#" class="jsTableOfContentsShow">{lang}wcf.message.toc.show{/lang}</a>]</span> |
| 1 | +<div class="tableOfContents__wrapper"> |
| 2 | + <nav class="tableOfContents__container" aria-labelledby="tocTitle-{$idPrefix}"> |
| 3 | + <div class="tableOfContents__header"> |
| 4 | + <h2 class="tableOfContents__title" id="tocTitle-{$idPrefix}">{lang}wcf.message.toc{/lang}</h2> |
| 5 | + |
| 6 | + <button type="button" |
| 7 | + aria-expanded="true" |
| 8 | + aria-controls="toc-{$idPrefix}" |
| 9 | + class="tableOfContents__toggle button small" |
| 10 | + id="tocToggle-{$idPrefix}" |
| 11 | + > |
| 12 | + {lang}wcf.message.toc.hide{/lang} |
| 13 | + </button> |
6 | 14 | </div> |
7 | | - <ol class="tableOfContents tocLevel1"> |
| 15 | + <ul class="tableOfContents tableOfContents--level1" id="toc-{$idPrefix}"> |
8 | 16 | {foreach from=$items item=item} |
9 | 17 | <li> |
10 | | - <span class="tocItemTitle"><a href="#{$item->getID()}">{$item->getTitle()}</a></span> |
| 18 | + <a class="tableOfContents__item" href="#{$item->getID()}">{$item->getTitle()}</a> |
11 | 19 |
|
12 | | - {if $item->hasChildren()}<ol class="tableOfContents tocLevel{$item->getDepth() + 1}">{else}</li>{/if} |
| 20 | + {if $item->hasChildren()}<ul class="tableOfContents tableOfContents--level{$item->getDepth() + 1}">{else}</li>{/if} |
13 | 21 |
|
14 | 22 | {if !$item->hasChildren() && $item->isLastSibling()} |
15 | | - {unsafe:"</ol></li>"|str_repeat:$item->getOpenParentNodes()} |
| 23 | + {unsafe:"</ul></li>"|str_repeat:$item->getOpenParentNodes()} |
16 | 24 | {/if} |
17 | 25 | {/foreach} |
18 | | - </ol> |
19 | | - </div> |
20 | | -</div> |
21 | | -<script data-relocate="true"> |
22 | | - require(['Ui/Screen'], function(UiScreen) { |
23 | | - var container = elById('tocContainer-{$idPrefix}'); |
24 | | - elBySelAll('.jsTableOfContentsHide, .jsTableOfContentsShow', container, function(button) { |
25 | | - button.addEventListener('click', function(event) { |
26 | | - event.preventDefault(); |
27 | | - |
28 | | - container.classList.toggle('open'); |
| 26 | + </ul> |
| 27 | + </nav> |
| 28 | + <script> |
| 29 | + { |
| 30 | + const button = document.getElementById('tocToggle-{$idPrefix}'); |
| 31 | + button.addEventListener('click', () => { |
| 32 | + toggle(); |
29 | 33 | }); |
30 | | - }); |
31 | | - |
32 | | - if (UiScreen.is('screen-sm-down')) { |
33 | | - container.classList.remove('open'); |
| 34 | + |
| 35 | + function toggle() { |
| 36 | + const hidden = button.getAttribute('aria-expanded') === 'true'; |
| 37 | + button.setAttribute('aria-expanded', hidden ? 'false' : 'true'); |
| 38 | + button.textContent = hidden ? '{jslang}wcf.message.toc.show{/jslang}' : '{jslang}wcf.message.toc.hide{/jslang}'; |
| 39 | + document.getElementById(button.getAttribute('aria-controls')).hidden = hidden; |
| 40 | + } |
| 41 | + |
| 42 | + if (window.matchMedia('(max-width: 768px)').matches) { |
| 43 | + toggle(); |
| 44 | + } |
34 | 45 | } |
35 | | - |
36 | | - container.classList.remove('mobileForceHide'); |
37 | | - }); |
38 | | -</script> |
| 46 | + </script> |
| 47 | +</div> |
0 commit comments