From a714ad67e7d8320c26aa0aeedc8eb810c954bf42 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Fri, 24 Dec 2010 13:44:24 +0000 Subject: [PATCH] Make sure the TOC is there when toggleToc is called. Although the function calling it checks it too, it could be called by a third party, or the TOC could've dissapeared :O (Follow-up r78941) --- resources/mediawiki.util/mediawiki.util.js | 36 +++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/resources/mediawiki.util/mediawiki.util.js b/resources/mediawiki.util/mediawiki.util.js index 6b4534e9b3..5f61236d0d 100644 --- a/resources/mediawiki.util/mediawiki.util.js +++ b/resources/mediawiki.util/mediawiki.util.js @@ -147,22 +147,28 @@ */ 'toggleToc' : function( $toggleLink ) { var $tocList = $( '#toc ul:first' ); - - if ( $tocList.is( ':hidden' ) ) { - $tocList.slideDown( 'fast' ); - $toggleLink.text( mw.msg( 'hidetoc' ) ); - $.cookie( 'mw_hidetoc', null, { - expires: 30, - path: '/' - } ); - return true; + + // This function shouldn't be called if there's no TOC, + // but just in case... + if ( $tocList.size() ) { + if ( $tocList.is( ':hidden' ) ) { + $tocList.slideDown( 'fast' ); + $toggleLink.text( mw.msg( 'hidetoc' ) ); + $.cookie( 'mw_hidetoc', null, { + expires: 30, + path: '/' + } ); + return true; + } else { + $tocList.slideUp( 'fast' ); + $toggleLink.text( mw.msg( 'showtoc' ) ); + $.cookie( 'mw_hidetoc', '1', { + expires: 30, + path: '/' + } ); + return false; + } } else { - $tocList.slideUp( 'fast' ); - $toggleLink.text( mw.msg( 'showtoc' ) ); - $.cookie( 'mw_hidetoc', '1', { - expires: 30, - path: '/' - } ); return false; } }, -- 2.20.1