Merge "user: Allow "CAS update failed" exceptions to be normalised"
[lhc/web/wiklou.git] / resources / src / mediawiki.toc / toc.js
1 ( function () {
2 'use strict';
3
4 // Table of contents toggle
5 mw.hook( 'wikipage.content' ).add( function ( $content ) {
6 $content.find( '.toc' ).addBack( '.toc' ).each( function () {
7 var hideToc,
8 $this = $( this ),
9 $tocToggleCheckbox = $this.children( '.toctogglecheckbox' ),
10 $tocTitle = $this.find( '.toctitle' ),
11 $tocToggleLink = $this.find( '.togglelink' ),
12 $tocList = $this.find( 'ul' ).eq( 0 );
13
14 // Hide/show the table of contents element
15 function toggleToc() {
16 if ( $tocList.is( ':hidden' ) ) {
17 $tocList.slideDown( 'fast' );
18 $tocToggleLink.text( mw.msg( 'hidetoc' ) );
19 $this.removeClass( 'tochidden' );
20 mw.cookie.set( 'hidetoc', null );
21 } else {
22 $tocList.slideUp( 'fast' );
23 $tocToggleLink.text( mw.msg( 'showtoc' ) );
24 $this.addClass( 'tochidden' );
25 mw.cookie.set( 'hidetoc', '1' );
26 }
27 }
28
29 // Only add it if there is a complete TOC and it doesn't
30 // have a toggle added already
31 if ( !$tocToggleCheckbox.length && $tocTitle.length && $tocList.length && !$tocToggleLink.length ) {
32 hideToc = mw.cookie.get( 'hidetoc' ) === '1';
33
34 $tocToggleLink = $( '<a role="button" tabindex="0" class="togglelink"></a>' )
35 .text( mw.msg( hideToc ? 'showtoc' : 'hidetoc' ) )
36 .on( 'click keypress', function ( e ) {
37 if (
38 e.type === 'click' ||
39 e.type === 'keypress' && e.which === 13
40 ) {
41 toggleToc();
42 }
43 } );
44
45 $tocTitle.append(
46 $tocToggleLink
47 .wrap( '<span class="toctoggle"></span>' )
48 .parent()
49 .prepend( '&nbsp;[' )
50 .append( ']&nbsp;' )
51 );
52
53 if ( hideToc ) {
54 $tocList.hide();
55 $this.addClass( 'tochidden' );
56 }
57 }
58 } );
59 } );
60
61 }() );