9 // Table of contents toggle
10 mw
.hook( 'wikipage.content' ).add( function ( $content
) {
11 var $toc
, $tocTitle
, $tocToggleLink
, hideToc
;
12 $toc
= $content
.find( '#toc' );
13 $tocTitle
= $content
.find( '#toctitle' );
14 $tocToggleLink
= $content
.find( '#togglelink' );
17 * Hide/show the table of contents element
19 * @param {jQuery} $toggleLink A jQuery object of the toggle link.
21 function toggleToc( $toggleLink
) {
22 var $tocList
= $toc
.find( 'ul:first' );
24 // This function shouldn't be called if there's no TOC,
25 // but just in case...
26 if ( $tocList
.length
) {
27 if ( $tocList
.is( ':hidden' ) ) {
28 $tocList
.slideDown( 'fast' );
29 $toggleLink
.text( mw
.msg( 'hidetoc' ) );
30 $toc
.removeClass( 'tochidden' );
31 $.cookie( 'mw_hidetoc', null, {
36 $tocList
.slideUp( 'fast' );
37 $toggleLink
.text( mw
.msg( 'showtoc' ) );
38 $toc
.addClass( 'tochidden' );
39 $.cookie( 'mw_hidetoc', '1', {
46 // Only add it if there is a TOC and there is no toggle added already
47 if ( $toc
.length
&& $tocTitle
.length
&& !$tocToggleLink
.length
) {
48 hideToc
= $.cookie( 'mw_hidetoc' ) === '1';
49 $tocToggleLink
= $( '<a href="#" class="internal" id="togglelink"></a>' )
50 .text( hideToc
? mw
.msg( 'showtoc' ) : mw
.msg( 'hidetoc' ) )
51 .click( function ( e
) {
53 toggleToc( $( this ) );
57 .wrap( '<span class="toctoggle"></span>' )
64 $toc
.find( 'ul:first' ).hide();
65 $toc
.addClass( 'tochidden' );
70 }( mediaWiki
, jQuery
) );