Krinkle has uploaded a new change for review. https://gerrit.wikimedia.org/r/131902
Change subject: mediawiki.toc: Clean up left overs ...................................................................... mediawiki.toc: Clean up left overs Follows-up d7a40c8 which creates the mediawiki.toc module and moved the tocToggle method from mediawiki.util. The tocToggle callback used to be a public method and therefore had two things about that that are obsolete: * Taking the toggle as parameter. This is a private method now, and we already have a reference to the toggle. * Asserting that the #toc has an <ul>. There is no need to defer this check this far in, nor to repeat it on each click. The old code checked it earlier was well, but we used to repeat the check here as the method was public. Now that it is a private helper method we can simply return early before setting it all up in the first place. Also: * Removed jsduck-like construction. This file is being indexed, as part of src/mediawiki/, but turning this into a class seems odd. It doesn't really have any structure to it. It's just UI glue. Turned it into an ignored file (no doc blocks). Change-Id: I21d4f735032b96f00291502e06d9d35a74648143 --- M resources/src/mediawiki/mediawiki.toc.js 1 file changed, 28 insertions(+), 38 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/02/131902/1 diff --git a/resources/src/mediawiki/mediawiki.toc.js b/resources/src/mediawiki/mediawiki.toc.js index dfdedb6..e8dd473 100644 --- a/resources/src/mediawiki/mediawiki.toc.js +++ b/resources/src/mediawiki/mediawiki.toc.js @@ -1,57 +1,47 @@ -/** - * @private - * @singleton - * @class mw.toc - */ ( function ( mw, $ ) { 'use strict'; // Table of contents toggle mw.hook( 'wikipage.content' ).add( function ( $content ) { - var $toc, $tocTitle, $tocToggleLink, hideToc; + var $toc, $tocTitle, $tocToggleLink, $tocList, hideToc; $toc = $content.find( '#toc' ); $tocTitle = $content.find( '#toctitle' ); $tocToggleLink = $content.find( '#togglelink' ); + $tocList = $toc.find( 'ul' ).eq( 0 ); - /** - * Hide/show the table of contents element - * - * @param {jQuery} $toggleLink A jQuery object of the toggle link. - */ - function toggleToc( $toggleLink ) { - var $tocList = $toc.find( 'ul:first' ); - - // This function shouldn't be called if there's no TOC, - // but just in case... - if ( $tocList.length ) { - if ( $tocList.is( ':hidden' ) ) { - $tocList.slideDown( 'fast' ); - $toggleLink.text( mw.msg( 'hidetoc' ) ); - $toc.removeClass( 'tochidden' ); - $.cookie( 'mw_hidetoc', null, { - expires: 30, - path: '/' - } ); - } else { - $tocList.slideUp( 'fast' ); - $toggleLink.text( mw.msg( 'showtoc' ) ); - $toc.addClass( 'tochidden' ); - $.cookie( 'mw_hidetoc', '1', { - expires: 30, - path: '/' - } ); - } + // Hide/show the table of contents element + function toggleToc() { + if ( $tocList.is( ':hidden' ) ) { + $tocList.slideDown( 'fast' ); + $tocToggleLink.text( mw.msg( 'hidetoc' ) ); + $toc.removeClass( 'tochidden' ); + $.cookie( 'mw_hidetoc', null, { + expires: 30, + path: '/' + } ); + } else { + $tocList.slideUp( 'fast' ); + $tocToggleLink.text( mw.msg( 'showtoc' ) ); + $toc.addClass( 'tochidden' ); + $.cookie( 'mw_hidetoc', '1', { + expires: 30, + path: '/' + } ); } } - // Only add it if there is a TOC and there is no toggle added already - if ( $toc.length && $tocTitle.length && !$tocToggleLink.length ) { + + // Only add it if there is a complete TOC and it doesn't + // have a toggle added already + if ( $toc.length && $tocTitle.length && $tocList.length && !$tocToggleLink.length ) { hideToc = $.cookie( 'mw_hidetoc' ) === '1'; + $tocToggleLink = $( '<a href="#" class="internal" id="togglelink"></a>' ) .text( hideToc ? mw.msg( 'showtoc' ) : mw.msg( 'hidetoc' ) ) .click( function ( e ) { e.preventDefault(); - toggleToc( $( this ) ); + toggleToc(); } ); + $tocTitle.append( $tocToggleLink .wrap( '<span class="toctoggle"></span>' ) @@ -61,7 +51,7 @@ ); if ( hideToc ) { - $toc.find( 'ul:first' ).hide(); + $tocList.hide(); $toc.addClass( 'tochidden' ); } } -- To view, visit https://gerrit.wikimedia.org/r/131902 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I21d4f735032b96f00291502e06d9d35a74648143 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Krinkle <krinklem...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits