«MediaWiki:Common.js» и «MediaWiki:Mainpage-citeauthor/pl»: разница между страницами

Материал из Янтарной ноосферы, свободной интернет-энциклопедии
(Различия между страницами)
м (1 версия импортирована: попробуем)
 
м (1 версия импортирована: попробуем)
 
Строка 1: Строка 1:
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
Karl Szlogel
// Collapsiblе: [[ВП:СБ]]
 
function collapsibleTables( $content ) {
var $btn,
$a,
tblIdx = 0,
colTables = [],
$Tables = $content.find( 'table' );
 
    $Tables.each( function( i, table ) {
        if ( $(table).hasClass( 'collapsible' ) ) {
var $table = $( this ),
$row = $table.find( 'tr' ).first(),
$cell = $row.find( 'th' ).first();
if ( !$cell.length ) {
return;
}
$table.attr( 'id', 'collapsibleTable' + tblIdx );
$btn = $( '<span>' ).addClass('collapseButton');
$a = $( '<a>' )
.attr( 'id', 'collapseButton' + tblIdx )
.attr( 'href', 'javascript:collapseTable(' + tblIdx + ');' )
.css( 'color', // изменяем цвет ссылки, только если цвет текста в навбоксе нестандартный
($cell.css( 'color' ) == $('.mw-body').css('color'))
? 'auto'
: $cell.css( 'color' ) )
.text( collapseCaption );
$btn
.append( '[' )
.append( $a )
.append( ']' );
if ( $cell.contents().length ) {
$btn.insertBefore( $cell.contents().first() );
} else {
$btn.appendTo( $cell );
}
colTables[tblIdx++] = $table;
        }
} );
for ( var i = 0; i < tblIdx; i++ ) {
if ( colTables[i].hasClass( 'collapsed' ) ||
( tblIdx > NavigationBarShowDefault &&
colTables[i].hasClass( 'autocollapse' )
)
) {
collapseTable( i );
}
}
}
 
mw.hook( 'wikipage.content' ).add( collapsibleTables );
 
function collapseTable ( idx ) {
var $table = $( '#collapsibleTable' + idx ),
$rows = $table.children().children( 'tr' ),
$btn = $( '#collapseButton' + idx );
if ( !$table.length || !$rows.length || !$btn.length ) {
return false;
}
 
var isShown = ( $btn.text() === collapseCaption ),
cssDisplay = isShown ? 'none' : $rows.first().css( 'display' );
 
$btn.text( isShown ? expandCaption : collapseCaption );
$rows.slice( 1 ).each( function() {
$( this ).css( 'display', cssDisplay );
} );
}
 
function collapsibleDivs( $content ) {
var navIdx = 0,
colNavs = [],
i,
$Divs = $content.find( 'div' );
$Divs.each( function( i, div ) {
        if ( $(div).hasClass( 'NavFrame' ) ) {
var $navFrame = $( this );
$navFrame.attr( 'id', 'NavFrame' + navIdx );
var $a = $( '<a>' )
.addClass( 'NavToggle' )
.attr( 'id', 'NavToggle' + navIdx )
.attr( 'href', 'javascript:collapseDiv(' + navIdx + ');' )
.text( NavigationBarHide );
$navFrame.children( '.NavHead' ).append( $a );
colNavs[navIdx++] = $navFrame;
        }
} );
for ( i = 0; i < navIdx; i++ ) {
if ( colNavs[i].hasClass( 'collapsed' ) ||
( navIdx > NavigationBarShowDefault &&
!colNavs[i].hasClass( 'expanded' )
)
) {
collapseDiv( i );
}
}
}
 
mw.hook( 'wikipage.content' ).add( collapsibleDivs );
 
function collapseDiv ( idx ) {
var $div = $( '#NavFrame' + idx ),
$btn = $( '#NavToggle' + idx );
if ( !$div.length || !$btn.length ) {
return false;
}
var isShown = ( $btn.text() === NavigationBarHide );
$btn.text( isShown ? NavigationBarShow : NavigationBarHide );
$div.children( '.NavContent,.NavPic' ).each( function() {
$( this ).css( 'display', isShown ? 'none' : 'block' );
} );
}

Текущая версия от 18:04, 10 февраля 2023

Karl Szlogel