MediaWiki:Gadget-hide-empty-fields.js: Różnice pomiędzy wersjami
Usunięta treść Dodana treść
.not() -> !.is() |
m $ |
||
(Nie pokazano 1 pośredniej wersji utworzonej przez tego samego użytkownika) | |||
Linia 42: | Linia 42: | ||
$dd.text() === '' && |
$dd.text() === '' && |
||
// element pod polem, odpowiednio: znaczenia, tłumaczenia, warianty, źródła |
// element pod polem, odpowiednio: znaczenia, tłumaczenia, warianty, źródła |
||
!$dl.next().is( 'p, ul, table, .mw-references-wrap' ) |
!$dl.next().is( 'p, ul, table, .mw-references-wrap' ) && |
||
// wyjątek dla tabelek typu `{| ... |}` w polu odmiany |
|||
// [[Specjalna:Niezmienny link/7541865#barszczowy]] |
|||
!$dl.next().is( 'dl:has(table.fldt-odmiana)' ) |
|||
) { |
) { |
||
$dl.addClass( 'empty-dl' ); |
$dl.addClass( 'empty-dl' ); |
Wersja z 14:08, 25 sty 2021
/*
* Skrypt ukrywający puste pola w artykułach. Przeróbka kodu do rozwijania
* skrótów autorstwa [[User:Sp5uhe]].
* Autorzy przeróbek: [[User:Olaf]], [[User:Peter Bowman]].
*/
var hef = mw.libs.hideEmptyFields = {
state: null,
hasEmptyFields: null,
$caEmptyFields: $( [] )
},
L10n = {
'qqx': [ 'hide-empty-fields-hide', 'hide-empty-fields-show', 'hide-empty-fields-no-empty', 'hide-empty-fields-tooltip' ],
'en': [ 'Hide empty fields', 'Show empty fields', 'No empty fields', 'Show/hide empty fields' ],
'pl': [ 'Ukryj puste pola', 'Pokaż puste pola', 'Brak pustych pól', 'Pokaż/ukryj puste pola' ]
},
config = mw.config.get( [
'wgNamespaceNumber',
'wgAction',
'wgTitle',
'wgUserLanguage'
] ),
state = {
HIDE: 'hide',
SHOW: 'show'
},
storageKey = 'ext.gadget.hide-empty-fields.state';
mw.libs.hideEmptyFields.browseContent = function ( $content ) {
$content.find( '.field' ).each( function ( i, el ) {
var $dt = $( el ).parent( 'dt' ),
$dd = $dt.next( 'dd' ),
$dl = $dt.parent( 'dl' );
// [[Dyskusja szablonu:pole#Dwukropek]]
if ( $dd.text() === '' ) {
$dd = $dd.next( 'dd' );
}
if (
// puste pole
$dd.text() === '' &&
// element pod polem, odpowiednio: znaczenia, tłumaczenia, warianty, źródła
!$dl.next().is( 'p, ul, table, .mw-references-wrap' ) &&
// wyjątek dla tabelek typu `{| ... |}` w polu odmiany
// [[Specjalna:Niezmienny link/7541865#barszczowy]]
!$dl.next().is( 'dl:has(table.fldt-odmiana)' )
) {
$dl.addClass( 'empty-dl' );
mw.libs.hideEmptyFields.hasEmptyFields = true;
}
} );
};
mw.libs.hideEmptyFields.toggleState = function () {
$( document.body ).toggleClass( 'gadget-hide-empty-fields-hidden' );
if ( mw.libs.hideEmptyFields.state === state.SHOW ) {
mw.libs.hideEmptyFields.state = state.HIDE;
} else {
mw.libs.hideEmptyFields.state = state.SHOW;
}
mw.storage.set( storageKey, mw.libs.hideEmptyFields.state );
};
mw.libs.hideEmptyFields.updatePortletLink = function () {
var newText = '';
if ( mw.libs.hideEmptyFields.hasEmptyFields ) {
if ( mw.libs.hideEmptyFields.state === state.SHOW ) {
newText = mw.msg( 'hide-empty-fields-hide' );
} else {
newText = mw.msg( 'hide-empty-fields-show' );
}
} else {
newText = mw.msg( 'hide-empty-fields-no-empty' );
}
mw.libs.hideEmptyFields.$caEmptyFields.find( 'a' ).text( newText );
};
if (
config.wgNamespaceNumber === 0 &&
config.wgAction === 'view' &&
config.wgTitle.indexOf( 'Słownik ' ) !== 0
) {
$.each( L10n[ config.wgUserLanguage ] || L10n.en, function ( i, message ) {
mw.messages.set( L10n.qqx[ i ], message );
} );
mw.libs.hideEmptyFields.state = state.SHOW;
mw.libs.hideEmptyFields.hasEmptyFields = false;
$( function () {
mw.libs.hideEmptyFields.$caEmptyFields = $( mw.util.addPortletLink(
'p-cactions',
'#',
mw.msg( 'hide-empty-fields-no-empty' ),
'ca-empty-fields',
mw.msg( 'hide-empty-fields-tooltip' ),
'1',
'#ca-history'
) )
.on( 'click', function ( e ) {
mw.libs.hideEmptyFields.toggleState();
mw.libs.hideEmptyFields.updatePortletLink();
return false;
} );
if ( mw.storage.get( storageKey ) !== state.SHOW ) {
mw.libs.hideEmptyFields.toggleState();
}
// mw.hook('wikipage.content') uruchamia sie czasem *przed* document.ready
mw.libs.hideEmptyFields.updatePortletLink();
} );
mw.hook( 'wikipage.content' ).add( function ( $content ) {
mw.libs.hideEmptyFields.hasEmptyFields = false;
mw.libs.hideEmptyFields.browseContent( $content );
mw.libs.hideEmptyFields.updatePortletLink();
// zapobiega wskokowi w niewlasciwe miejsce wskutek ukrycia pustych sekcji po zaladowaniu strony
//if ( location.hash ) location.hash = location.hash;
} );
}