«Шаблон:Ref-lang/ru» и «MediaWiki:Common.js»: разница между страницами
(Различия между страницами)
м (3 версии импортировано: попробуем) |
(всяческая хрень с возможностью сворачивания) |
||
Строка 1: | Строка 1: | ||
{{ | /* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */ | ||
// 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' ); | |||
} ); | |||
} |
Версия от 01:14, 5 сентября 2016
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
// 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' );
} );
}