4 // Table of contents toggle
5 mw
.hook( 'wikipage.content' ).add( function ( $content
) {
6 $content
.find( '.toc' ).addBack( '.toc' ).each( function () {
9 // .toctitle is new so may not exist in HTML caches for a few weeks,
10 // so keep checking for #toctitle for now
11 $tocTitle
= $this.find( '.toctitle, #toctitle' ),
12 $tocToggleLink
= $this.find( '.togglelink' ),
13 $tocList
= $this.find( 'ul' ).eq( 0 );
15 // Hide/show the table of contents element
16 function toggleToc() {
17 if ( $tocList
.is( ':hidden' ) ) {
18 $tocList
.slideDown( 'fast' );
19 $tocToggleLink
.text( mw
.msg( 'hidetoc' ) );
20 $this.removeClass( 'tochidden' );
21 mw
.cookie
.set( 'hidetoc', null );
23 $tocList
.slideUp( 'fast' );
24 $tocToggleLink
.text( mw
.msg( 'showtoc' ) );
25 $this.addClass( 'tochidden' );
26 mw
.cookie
.set( 'hidetoc', '1' );
30 // Only add it if there is a complete TOC and it doesn't
31 // have a toggle added already
32 if ( $tocTitle
.length
&& $tocList
.length
&& !$tocToggleLink
.length
) {
33 hideToc
= mw
.cookie
.get( 'hidetoc' ) === '1';
35 $tocToggleLink
= $( '<a role="button" tabindex="0" class="togglelink"></a>' )
36 .text( mw
.msg( hideToc
? 'showtoc' : 'hidetoc' ) )
37 .on( 'click keypress', function ( e
) {
40 e
.type
=== 'keypress' && e
.which
=== 13
48 .wrap( '<span class="toctoggle"></span>' )
56 $this.addClass( 'tochidden' );
62 }( mediaWiki
, jQuery
) );