2734
правки
Изменения
Нет описания правки
/**
* Collapsible tableselements
*
* Based on http://wwwAdd the "collapsible" class to an element and the child element with class "collapsible-content" * (or everything but the header row if a table) will be hidden when the element is collapsed.mediawiki * * * Add the class "collapsed" to the element to make it start out collapsed.org/wiki/Manual:Collapsible_tables#Common * * Add either "collapsetoggle-left" or "collapsetoggle-inline" to the element to choose the collapse * toggle alignment (defaults to right).js_script_ * * Add an ID in the format of "collapsible-<x>" to the element to make any element with the class * "collapsetoggle-custom" and a matching class in the format of "collapsible-<x>-toggle" control * the collapsing instead of the standard button.28before_1 * If the custom toggle contains an element with the "jslink" class, only that will be clickable.18.29
*/
( function() {
var $tables collapsibles = $contentwikipageContent.find( 'table.collapsible' ); if ( !$tables || !$tablescollapsibles.length ) { return false;
}
var buttonText $toggleTemplate = $( ' <span class="collapsible-button">' ).addClass( 'collapsetoggle' ).append( '[', $( '<span class="jslink">' + mcw).i18n.hideText + addClass( 'jslink' ), '</span>]</span> '; ); $tablescollapsibles.each( function() { var $table collapsible = $( this ), $header, $collapseButton, firstWidth, secondWidth; // This table is already collapsible if ( $tablecollapsible.data( 'made-collapsible' ) ) {
return true;
}
}
}
// For Create and insert the toggle button to float properly, it has to be /before/ the cell textif there is no custom one if ( !$toggle || !$toggle.length ) { var $toggleContainer; if ( $collapsible.is( 'table' ) ) { var $rows = $children.filter( 'thead' ).children(); if ( !$rows.length ) { $rows = $children.filter( 'tbody' ).first().children(); if ( !$rows.length ) { $rows = $children.filter( 'tr' ); } } $toggleContainer = $rows.first().children().last(); } else { $toggleContainer = $children.first(); if ( $toggleContainer.hasClass( 'collapsible-content' ) ) { $toggleContainer = $collapsible; } } $toggle = $toggleTemplate.clone(); if ( $collapsible.hasClass( 'collapsetoggle-inline' ) || $collapsible.hasClass( 'collapse-button-none' ) ) { $headertoggleContainer.append( buttonText $toggle ); } else { $headertoggleContainer.prepend( buttonText $toggle ); }
}
}
// Set the text back to hide if it's not collapsed to begin with
if ( !$tablecollapsible.hasClass( 'collapsed' ) ) { $collapseButton.find( '> .jslink' )toggleLink.text( mcw.i18n.hideText );
}
$tabletoggleLink.dataon( 'collapsibleclick keydown', true function( e ){ // Only trigger on enter press if ( e.keyCode && e.keyCode !== 13 ) { return; } ); // This is bound directly because sortable tables donDon't play nicetoggle when clicking buttons or links inside the toggle var $target = $( e.target ); if ( $tablestarget.findis( 'button' ) || $target.is( 'a' ) ) { return; } $collapsible-button .jslinktoggleClass( 'collapsed' ); if ( $collapsible.clickhasClass( function( e 'collapsed' ) ) { var $table = $toggleLink.text( this showText ); } else { $toggleLink.closesttext( 'hideText ); } // Stop tablesorting activating when clicking the link e.collapsible' stopPropagation(); } );
} );
}() );