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 if ( $tocList
.is( ':hidden' ) ) {
17 $tocList
.slideDown( 'fast' );
18 $tocToggleLink
.text( mw
.msg( 'hidetoc' ) );
19 $this.removeClass( 'tochidden' );
20 mw
.cookie
.set( 'hidetoc', null );
22 $tocList
.slideUp( 'fast' );
23 $tocToggleLink
.text( mw
.msg( 'showtoc' ) );
24 $this.addClass( 'tochidden' );
25 mw
.cookie
.set( 'hidetoc', '1' );
29 // Only add it if there is a complete TOC and it doesn't
30 // have a toggle added already
31 if ( !$tocToggleCheckbox
.length
&& $tocTitle
.length
&& $tocList
.length
&& !$tocToggleLink
.length
) {
32 hideToc
= mw
.cookie
.get( 'hidetoc' ) === '1';
34 $tocToggleLink
= $( '<a>' )
39 .addClass( 'togglelink' )
40 .text( mw
.msg( hideToc
? 'showtoc' : 'hidetoc' ) )
41 .on( 'click keypress', function ( e
) {
44 e
.type
=== 'keypress' && e
.which
=== 13
52 .wrap( '<span class="toctoggle"></span>' )
60 $this.addClass( 'tochidden' );