Debian Codegraph @

resources/src/mediawiki.toc/toc.js

raw symbols SCIP
1 ( function () {
2 'use strict';
3
4 function initToc( tocNode ) {
5 const toggleNode = tocNode.querySelector( '.toctogglecheckbox' );
6
7 if ( !toggleNode ) {
8 return;
9 }
10
11 let hidden = false;
12
13 toggleNode.addEventListener( 'change', () => {
14 hidden = !hidden;
15 mw.cookie.set( 'hidetoc', hidden ? '1' : null );
16 toggleNode.setAttribute( 'aria-label', hidden ?
17 mw.message( 'table-of-contents-show-button-aria-label' ).plain() :
18 mw.message( 'table-of-contents-hide-button-aria-label' ).plain()
19 );
20 } );
21
22 // Initial state
23 if ( mw.cookie.get( 'hidetoc' ) === '1' ) {
24 toggleNode.checked = true;
25 hidden = true;
26 }
27 toggleNode.setAttribute( 'aria-label', hidden ?
28 mw.message( 'table-of-contents-show-button-aria-label' ).plain() :
29 mw.message( 'table-of-contents-hide-button-aria-label' ).plain()
30 );
31 }
32
33 mw.hook( 'wikipage.content' ).add( ( $content ) => {
34 const tocs = $content[ 0 ] ? $content[ 0 ].querySelectorAll( '.toc' ) : [];
35 let i = tocs.length;
36 while ( i-- ) {
37 initToc( tocs[ i ] );
38 }
39 } );
40 }() );