4 // Table of contents toggle
5 mw
.hook( 'wikipage.content' ).add( function ( $content
) {
8 * Hide/show the table of contents element
10 * @param {jQuery} $toggleLink A jQuery object of the toggle link.
12 function toggleToc( $toggleLink
) {
13 var $tocList
= $content
.find( '#toc ul:first' );
15 // This function shouldn't be called if there's no TOC,
16 // but just in case...
17 if ( $tocList
.length
) {
18 if ( $tocList
.is( ':hidden' ) ) {
19 $tocList
.slideDown( 'fast' );
20 $toggleLink
.text( mw
.msg( 'hidetoc' ) );
21 $content
.find( '#toc' ).removeClass( 'tochidden' );
22 $.cookie( 'mw_hidetoc', null, {
27 $tocList
.slideUp( 'fast' );
28 $toggleLink
.text( mw
.msg( 'showtoc' ) );
29 $content
.find( '#toc' ).addClass( 'tochidden' );
30 $.cookie( 'mw_hidetoc', '1', {
38 var $tocTitle
, $tocToggleLink
, hideTocCookie
;
39 $tocTitle
= $content
.find( '#toctitle' );
40 $tocToggleLink
= $content
.find( '#togglelink' );
41 // Only add it if there is a TOC and there is no toggle added already
42 if ( $content
.find( '#toc' ).length
&& $tocTitle
.length
&& !$tocToggleLink
.length
) {
43 hideTocCookie
= $.cookie( 'mw_hidetoc' );
44 $tocToggleLink
= $( '<a href="#" class="internal" id="togglelink"></a>' )
45 .text( mw
.msg( 'hidetoc' ) )
46 .click( function ( e
) {
48 toggleToc( $( this ) );
52 .wrap( '<span class="toctoggle"></span>' )
58 if ( hideTocCookie
=== '1' ) {
59 toggleToc( $tocToggleLink
);
64 }( mediaWiki
, jQuery
) );