4 // Table of contents toggle
5 mw
.hook( 'wikipage.content' ).add( function ( $content
) {
6 $content
.find( '.toc' ).addBack( '.toc' ).each( function () {
9 $tocToggleCheckbox
= $this.children( '.toctogglecheckbox' ),
10 $tocTitle
= $this.find( '.toctitle' ),
11 $tocToggleLink
= $this.find( '.togglelink' ),
12 $tocList
= $this.find( 'ul' ).eq( 0 );
14 // Hide/show the table of contents element
15 function toggleToc() {
16 // eslint-disable-next-line no-jquery/no-class-state
17 if ( $this.hasClass( 'tochidden' ) ) {
18 // FIXME: Use CSS transitions
19 // eslint-disable-next-line no-jquery/no-slide
20 $tocList
.slideDown( 'fast' );
21 $tocToggleLink
.text( mw
.msg( 'hidetoc' ) );
22 $this.removeClass( 'tochidden' );
23 mw
.cookie
.set( 'hidetoc', null );
25 // eslint-disable-next-line no-jquery/no-slide
26 $tocList
.slideUp( 'fast' );
27 $tocToggleLink
.text( mw
.msg( 'showtoc' ) );
28 $this.addClass( 'tochidden' );
29 mw
.cookie
.set( 'hidetoc', '1' );
33 // Only add it if there is a complete TOC and it doesn't
34 // have a toggle added already
35 if ( !$tocToggleCheckbox
.length
&& $tocTitle
.length
&& $tocList
.length
&& !$tocToggleLink
.length
) {
36 hideToc
= mw
.cookie
.get( 'hidetoc' ) === '1';
38 $tocToggleLink
= $( '<a>' )
43 .addClass( 'togglelink' )
44 .text( mw
.msg( hideToc
? 'showtoc' : 'hidetoc' ) )
45 .on( 'click keypress', function ( e
) {
48 e
.type
=== 'keypress' && e
.which
=== 13
56 .wrap( '<span class="toctoggle"></span>' )
64 $this.addClass( 'tochidden' );