From: Fomafix Date: Tue, 6 May 2014 20:08:46 +0000 (+0000) Subject: mediawiki.toc: Hide toc without animation in initial collapsed state X-Git-Tag: 1.31.0-rc.0~15857 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=1d15388d2138ceba6761b6a02c69c4f55980cb01;p=lhc%2Fweb%2Fwiklou.git mediawiki.toc: Hide toc without animation in initial collapsed state Bug: 64927 Change-Id: I5b46390b3dc6e42031f636119673892507151f54 --- diff --git a/resources/src/mediawiki/mediawiki.toc.js b/resources/src/mediawiki/mediawiki.toc.js index 6eb855284e..dfdedb6673 100644 --- a/resources/src/mediawiki/mediawiki.toc.js +++ b/resources/src/mediawiki/mediawiki.toc.js @@ -8,6 +8,10 @@ // Table of contents toggle mw.hook( 'wikipage.content' ).add( function ( $content ) { + var $toc, $tocTitle, $tocToggleLink, hideToc; + $toc = $content.find( '#toc' ); + $tocTitle = $content.find( '#toctitle' ); + $tocToggleLink = $content.find( '#togglelink' ); /** * Hide/show the table of contents element @@ -15,7 +19,7 @@ * @param {jQuery} $toggleLink A jQuery object of the toggle link. */ function toggleToc( $toggleLink ) { - var $tocList = $content.find( '#toc ul:first' ); + var $tocList = $toc.find( 'ul:first' ); // This function shouldn't be called if there's no TOC, // but just in case... @@ -23,7 +27,7 @@ if ( $tocList.is( ':hidden' ) ) { $tocList.slideDown( 'fast' ); $toggleLink.text( mw.msg( 'hidetoc' ) ); - $content.find( '#toc' ).removeClass( 'tochidden' ); + $toc.removeClass( 'tochidden' ); $.cookie( 'mw_hidetoc', null, { expires: 30, path: '/' @@ -31,7 +35,7 @@ } else { $tocList.slideUp( 'fast' ); $toggleLink.text( mw.msg( 'showtoc' ) ); - $content.find( '#toc' ).addClass( 'tochidden' ); + $toc.addClass( 'tochidden' ); $.cookie( 'mw_hidetoc', '1', { expires: 30, path: '/' @@ -39,15 +43,11 @@ } } } - - var $tocTitle, $tocToggleLink, hideTocCookie; - $tocTitle = $content.find( '#toctitle' ); - $tocToggleLink = $content.find( '#togglelink' ); // Only add it if there is a TOC and there is no toggle added already - if ( $content.find( '#toc' ).length && $tocTitle.length && !$tocToggleLink.length ) { - hideTocCookie = $.cookie( 'mw_hidetoc' ); + if ( $toc.length && $tocTitle.length && !$tocToggleLink.length ) { + hideToc = $.cookie( 'mw_hidetoc' ) === '1'; $tocToggleLink = $( '' ) - .text( mw.msg( 'hidetoc' ) ) + .text( hideToc ? mw.msg( 'showtoc' ) : mw.msg( 'hidetoc' ) ) .click( function ( e ) { e.preventDefault(); toggleToc( $( this ) ); @@ -60,8 +60,9 @@ .append( '] ' ) ); - if ( hideTocCookie === '1' ) { - toggleToc( $tocToggleLink ); + if ( hideToc ) { + $toc.find( 'ul:first' ).hide(); + $toc.addClass( 'tochidden' ); } } } );