mediawiki.searchSuggest: Only handle Vector's fulltext hack on Vector
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.toc.js
1 ( function ( mw, $ ) {
2 'use strict';
3
4 // Table of contents toggle
5 mw.hook( 'wikipage.content' ).add( function ( $content ) {
6
7 /**
8 * Hide/show the table of contents element
9 *
10 * @param {jQuery} $toggleLink A jQuery object of the toggle link.
11 */
12 function toggleToc( $toggleLink ) {
13 var $tocList = $content.find( '#toc ul:first' );
14
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, {
23 expires: 30,
24 path: '/'
25 } );
26 } else {
27 $tocList.slideUp( 'fast' );
28 $toggleLink.text( mw.msg( 'showtoc' ) );
29 $content.find( '#toc' ).addClass( 'tochidden' );
30 $.cookie( 'mw_hidetoc', '1', {
31 expires: 30,
32 path: '/'
33 } );
34 }
35 }
36 }
37
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 ) {
47 e.preventDefault();
48 toggleToc( $( this ) );
49 } );
50 $tocTitle.append(
51 $tocToggleLink
52 .wrap( '<span class="toctoggle"></span>' )
53 .parent()
54 .prepend( '&nbsp;[' )
55 .append( ']&nbsp;' )
56 );
57
58 if ( hideTocCookie === '1' ) {
59 toggleToc( $tocToggleLink );
60 }
61 }
62 } );
63
64 }( mediaWiki, jQuery ) );