Warning.png

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

Изменения

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

MediaWiki:Common.js

1649 байтов добавлено, 18:39, 18 августа 2016
Нет описания правки
/**
* 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;
}
// Use the collapse-button if specified otherwise the first header cell of the first rowvar $children = $collapsible.children(); var showText = $header collapsible.data( 'expandtext' ) || i18n.showText; var hideText = $tablecollapsible.finddata( 'tr:first .collapse-buttoncollapsetext' )|| i18n.hideText; // If there is no content area, add it if ( !$headercollapsible.is( 'table' ) && !$children.filter( '.collapsible-content' ).length ) { if ( $collapsible.is( 'tr' ) ) { $header = children.addClass( 'collapsible-content' ); } else { $tablecollapsible.findwrapInner( 'tr:first <div class="collapsible-content"> th:first' ); }
}
// No header or the table body is emptyvar $toggle; var id = $collapsible.attr( 'id' ); if ( !id && id.match( /^collapsible-./ ) ) { $header.length || !toggle = $( $tablewikipageContent[0].findgetElementsByClassName( id + '-toggle'tr:not(tr:first)' ) .htmlfilter('.collapsetoggle-custom' ).trimcss('visibility', 'visible' ).length ) { 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 ); }
}
// Find max button size, and set its min-width to it var $collapseButton toggleLink = $tabletoggle.find( '.collapsible-buttonjslink' ); firstWidth = if ( !$collapseButtontoggleLink.width(length ){ $toggleLink = $toggle; } $collapseButtontoggleLink.findattr( '> .jslinktabindex' , 0 ).text( mcw.i18n.showText ); secondWidth = $collapseButton.width(hideText );
if // Find max toggle size, and set its min-width to it var hideWidth = $toggle.width( firstWidth != secondWidth ) {; if $toggleLink.text( firstWidth < secondWidth showText ) {; var showWidth = $collapseButtontoggle.csswidth( 'min-width', secondWidth ); } else if ( hideWidth !== showWidth ) { $collapseButtontoggle.css( 'min-width', firstWidth hideWidth > showWidth ? hideWidth : showWidth ); }
}
// 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(); } );
// Stop table sorting activating when clicking the link e.stopPropagation(); if ( $table.hasClass( 'collapsed' ) ) { $table.removeClass( 'collapsed' )collapsible.addClassdata( 'expandedmade-collapsible' , true ); $( this ).text( mcw.i18n.hideText ); } else { $table.removeClass( 'expanded' ).addClass( 'collapsed' ); $( this ).text( mcw.i18n.showText ); }
} );
}() );

Навигация