Difference between revisions of "MediaWiki:Common.js"

From Awesome Baozam
Jump to: navigation, search
Line 1: Line 1:
 
( function ( mw, $ ) {
 
( function ( mw, $ ) {
 
     'use strict';
 
     'use strict';
alert(mw.msg( 'showtoc' ));
 
 
     // Table of contents toggle
 
     // Table of contents toggle
 
     mw.hook( 'wikipage.content' ).add( function ( $content ) {
 
     mw.hook( 'wikipage.content' ).add( function ( $content ) {
Line 7: Line 6:
 
             var d = $('<div>').html( $(this).html() ).slideUp( 'fast' );
 
             var d = $('<div>').html( $(this).html() ).slideUp( 'fast' );
 
             $(this).html("").append( '<h2 class=toctitle>Details <span class="toctoggle">[ <a href=#>' + mw.msg( 'showtoc' ) + '</a> ]</span></h4>' ).append( d );                 
 
             $(this).html("").append( '<h2 class=toctitle>Details <span class="toctoggle">[ <a href=#>' + mw.msg( 'showtoc' ) + '</a> ]</span></h4>' ).append( d );                 
             $(this).find( 'h4 a' );
+
             $(this).find( '.toctitle a' ).click( function(e) {
 +
                e.preventDefault();
 +
                $(this).toggleClass('off').text( $(this).hasClass('off') ? mw.msg( 'showtoc' ) : mw.msg( 'hidetoc' ) );
 +
 
 +
            } );
 
         } );
 
         } );
 
     } );
 
     } );
  
 
}( mediaWiki, jQuery ) );
 
}( mediaWiki, jQuery ) );

Revision as of 12:34, 6 July 2016

( function ( mw, $ ) {
    'use strict';
    // Table of contents toggle
    mw.hook( 'wikipage.content' ).add( function ( $content ) {
        $content.find('.details' ).each( function() {
            var d = $('<div>').html( $(this).html() ).slideUp( 'fast' );
            $(this).html("").append( '<h2 class=toctitle>Details <span class="toctoggle">[ <a href=#>' + mw.msg( 'showtoc' ) + '</a> ]</span></h4>' ).append( d );                
            $(this).find( '.toctitle a' ).click( function(e) {
                e.preventDefault();
                $(this).toggleClass('off').text( $(this).hasClass('off') ? mw.msg( 'showtoc' ) : mw.msg( 'hidetoc' ) );
 
            } );
        } );
    } );
 
}( mediaWiki, jQuery ) );