Warning.png

Поддержка Wiki прекращена, она доступна в режиме архива. Информация в ней устарела и может быть неактуальной.

Изменения

Перейти к: навигация, поиск

MediaWiki:Common.js

1649 байтов убрано, 14:32, 13 августа 2016
Отмена правки 1593, сделанной участником MailGik (обс.)
/**
* Collapsible elementstables
*
* Add 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 collapsedBased on http://www. * * * Add the class "collapsed" to the element to make it start out collapsedmediawiki. * * Add either "collapsetoggle-left" or "collapsetoggle-inline" to the element to choose the collapse * toggle alignment (defaults to right)org/wiki/Manual:Collapsible_tables#Common. * * 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 buttonjs_script_. * If the custom toggle contains an element with the "jslink" class, only that will be clickable28before_1.18.29
*/
( function() {
var $collapsibles tables = $wikipageContentcontent.find( 'table.collapsible' ); if ( !$collapsiblestables || !$tables.length ) { returnfalse;
}
var $toggleTemplate buttonText = $( '<spanclass="collapsible-button">[<span class="jslink">' )+ mcw.addClass( 'collapsetoggle' )i18n.append( '[', $( hideText + '</span>' ).addClass( 'jslink' ), ']</span> '; ); $collapsiblestables.each( function() { var $collapsible table = $( this ), $header, $collapseButton, firstWidth, secondWidth; // This table is already collapsible if ( $collapsibletable.data( 'made-collapsible' ) ) {
return true;
}
var // Use the collapse-button if specified otherwise the first header cell of the first row $children header = $collapsibletable.childrenfind('tr:first .collapse-button' ); var showText = if ( !$collapsibleheader.data( 'expandtext' length ) || i18n.showText;{ var hideText $header = $collapsibletable.datafind( 'collapsetexttr:first > th:first' ) || i18n.hideText; }
// If there No header or the table body is no content area, add itempty if ( !$collapsibleheader.is( 'table' ) && length || !$childrentable.filterfind( '.collapsible-contenttr:not(tr:first)' ).length html() { if ( $collapsible.istrim( 'tr' ) .length ) { $children.addClass( 'collapsible-content' ); } else { $collapsible.wrapInner( '<div class="collapsible-content">' )return true; }
}
var $toggle;// For the button to float properly, it has to be /before/ the cell text var id = if ( $collapsibletable.attrhasClass( 'idcollapse-button-none' ); if ( id && id.match( /^collapsible-./ ) ) { $toggle = $( $wikipageContent[0]header.getElementsByClassNameappend( id + '-toggle' ) buttonText ); } else { .filter( '.collapsetoggle-custom' ) $header.cssprepend( 'visibility', 'visible' buttonText );
}
// Create Find max button size, and insert the toggle button if there is no custom oneset its min-width to it if ( !$toggle || !collapseButton = $toggletable.find( '.length collapsible-button' ) { var $toggleContainer; if ( firstWidth = $collapsiblecollapseButton.iswidth( 'table' ) ) {; var $rows = $childrencollapseButton.filterfind( 'thead> .jslink' ).childrentext(mcw.i18n.showText ); if ( !$rows.length ) { $rows secondWidth = $children.filter( 'tbody' ).first()collapseButton.childrenwidth(); if ( firstWidth !$rows.length = secondWidth ) { $rows = $children.filter if ( 'tr' firstWidth < secondWidth ); } }{ $toggleContainer = $rowscollapseButton.first().children().lastcss('min-width', secondWidth );
} else {
$toggleContainer = $childrencollapseButton.first(); if ( $toggleContainer.hasClasscss( 'collapsiblemin-contentwidth' ) ) { $toggleContainer = $collapsible; } } $toggle = $toggleTemplate.clone(); if ( $collapsible.hasClass( 'collapsetoggle-inline' ) || $collapsible.hasClass( 'collapse-button-none' ) ) { $toggleContainer.append( $toggle ); } else { $toggleContainer.prepend( $toggle , firstWidth );
}
}
// Set the text back to hide if it's not collapsed to begin with
if ( !$table.hasClass( 'collapsed' ) ) {
$collapseButton.find( '> .jslink' ).text( mcw.i18n.hideText );
}
var $toggleLink = table.data( 'collapsible', true ); } ); // This is bound directly because sortable tables don't play nice $toggletables.find( '.collapsible-button .jslink' ); if .click( function( !$toggleLink.length e ) { var $toggleLink table = $toggle; } $toggleLink( this ).attrclosest( 'tabindextable.collapsible', 0 ).text( hideText );
// Find max toggle size, and set its min-width to itStop table sorting activating when clicking the link var hideWidth = $togglee.widthstopPropagation(); $toggleLink.text( showText ); var showWidth = $toggle.width(); if ( hideWidth !== showWidth ) { $toggle.css( 'min-width', hideWidth > showWidth ? hideWidth : showWidth ); }
// Set the text back to hide if it( $table.hasClass( 's not collapsed to begin with' ) ) { if ( ! $collapsibletable.hasClassremoveClass( 'collapsed' ) .addClass( 'expanded' ); $( this ).text( mcw.i18n.hideText ) ; } else { $toggleLinktable.removeClass( 'expanded' ).addClass( 'collapsed' ); $( this ).text( hideText mcw.i18n.showText );
}
$toggleLink.on( 'click keydown', function( e ) {
// Only trigger on enter press
if ( e.keyCode && e.keyCode !== 13 ) {
return;
}
// Don't toggle when clicking buttons or links inside the toggle
var $target = $( e.target );
if ( $target.is( 'button' ) || $target.is( 'a' ) ) {
return;
}
$collapsible.toggleClass( 'collapsed' );
if ( $collapsible.hasClass( 'collapsed' ) ) {
$toggleLink.text( showText );
} else {
$toggleLink.text( hideText );
}
// Stop table sorting activating when clicking the link
e.stopPropagation();
} );
$collapsible.data( 'made-collapsible', true );
} );
}() );

Навигация