4 // Table of contents toggle
5 mw
.hook( 'wikipage.content' ).add( function ( $content
) {
6 $content
.find( '.toc' ).addBack( '.toc' ).each( function () {
9 $tocTitle
= $this.find( '.toctitle' ),
10 $tocToggleLink
= $this.find( '.togglelink' ),
11 $tocList
= $this.find( 'ul' ).eq( 0 );
13 // Hide/show the table of contents element
14 function toggleToc() {
15 if ( $tocList
.is( ':hidden' ) ) {
16 $tocList
.slideDown( 'fast' );
17 $tocToggleLink
.text( mw
.msg( 'hidetoc' ) );
18 $this.removeClass( 'tochidden' );
19 mw
.cookie
.set( 'hidetoc', null );
21 $tocList
.slideUp( 'fast' );
22 $tocToggleLink
.text( mw
.msg( 'showtoc' ) );
23 $this.addClass( 'tochidden' );
24 mw
.cookie
.set( 'hidetoc', '1' );
28 // Only add it if there is a complete TOC and it doesn't
29 // have a toggle added already
30 if ( $tocTitle
.length
&& $tocList
.length
&& !$tocToggleLink
.length
) {
31 hideToc
= mw
.cookie
.get( 'hidetoc' ) === '1';
33 $tocToggleLink
= $( '<a role="button" tabindex="0" class="togglelink"></a>' )
34 .text( mw
.msg( hideToc
? 'showtoc' : 'hidetoc' ) )
35 .on( 'click keypress', function ( e
) {
38 e
.type
=== 'keypress' && e
.which
=== 13
46 .wrap( '<span class="toctoggle"></span>' )
54 $this.addClass( 'tochidden' );
60 }( mediaWiki
, jQuery
) );