2 * Scripts common to all skins
6 * Collapsible tables and divs.
8 * Users can create tables and nested divs which collapse either on-click or on-load,
9 * to save space on a page, or to conceal information at first sight. Eg:
11 * <table class="wikitable collapsible collapsed"><tr>
12 * <th>A table header which will always be visible</th>
14 * <td>A table cell which will be hidden on page-load</td>
17 * <div class="collapsible collapsed">
18 * Content which will always be visible
19 * <span class="collapsible-expander">Click me!</span>
21 * This content will be hidden until the span above is clicked
25 * If the user does not create a toggle-button manually, one will be created,
26 * in the top-right header cell for tables, and at the beginning of the outer
27 * div's content for a collapsible div.
30 $('.collapsible').each( function(){
32 if( $('.collapsible-expander', $x).size() ){
33 $('.collapsible-expander', $x)
34 .click(function(e, rmClass){
36 rmClass = !(rmClass == false);
39 .trigger('mw-toggle-collapse', [rmClass]);
43 var $expander = $j('<div class="collapsible-expander">')
44 .text( '[' + mediaWiki.msg( 'hide' ) + ']' )
45 .click(function(e, rmClass){
46 rmClass = !(rmClass == false);
50 .trigger('mw-toggle-collapse', [rmClass])
53 ($(this).is('.collapsible.collapsed .collapsible-expander')
54 ? mediaWiki.msg( 'show' )
55 : mediaWiki.msg( 'hide' )) +
60 if( $x.is('div.collapsible')){
61 $x.prepend($expander);
63 $('tr:first th:last',$x).append($expander);
70 * This is a bit nasty because it also toggles any nested
71 * collapsible objects. But it would be a nightmare to only
72 * select the outer collapser without adding ids everywhere.
74 $('table.collapsible').live( 'mw-toggle-collapse', function(e, rmClass){
76 var time = rmClass ? 500 : 0;
78 // We'd like to use slideToggle() like for divs, but the jQuery
79 // slide animation for table rows is just *pig ugly*...
80 .toggle("fade", { direction: "vertical" }, time);
82 $('table.collapsible',$(this)).andSelf().toggleClass('collapsed');
87 $('div.collapsible').live( 'mw-toggle-collapse', function(e, rmClass){
89 var time = rmClass ? 500 : 0;
90 $(this).children(':not(.collapsible-expander)')
93 $('div.collapsible',$(this)).andSelf().toggleClass('collapsed');
99 * Here we want to collapse .collapsible-expander buttons whose closest
100 * div.collapsible parent wants to be collapsed on first view
102 $('.collapsible-expander').filter(function(){
103 return $(this).closest('.collapsible').is('.collapsible.collapsed')
104 }).trigger( 'click', [false] );