4 // Table of contents toggle
5 mw
.hook( 'wikipage.content' ).add( function ( $content
) {
6 var $toc
, $tocTitle
, $tocToggleLink
, $tocList
, hideToc
;
7 $toc
= $content
.find( '#toc' );
8 $tocTitle
= $content
.find( '#toctitle' );
9 $tocToggleLink
= $content
.find( '#togglelink' );
10 $tocList
= $toc
.find( 'ul' ).eq( 0 );
12 // Hide/show the table of contents element
13 function toggleToc( e
) {
15 if ( $tocList
.is( ':hidden' ) ) {
16 $tocList
.slideDown( 'fast' );
17 $tocToggleLink
.text( mw
.msg( 'hidetoc' ) );
18 $toc
.removeClass( 'tochidden' );
19 mw
.cookie
.set( 'hidetoc', null );
21 $tocList
.slideUp( 'fast' );
22 $tocToggleLink
.text( mw
.msg( 'showtoc' ) );
23 $toc
.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 ( $toc
.length
&& $tocTitle
.length
&& $tocList
.length
&& !$tocToggleLink
.length
) {
31 hideToc
= mw
.cookie
.get( 'hidetoc' ) === '1';
33 $tocToggleLink
= $( '<a href="#" id="togglelink"></a>' )
34 .text( mw
.msg( hideToc
? 'showtoc' : 'hidetoc' ) )
39 .wrap( '<span class="toctoggle"></span>' )
47 $toc
.addClass( 'tochidden' );
52 }( mediaWiki
, jQuery
) );