MediaWiki:Common.js
Z LawRus
Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.
- Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
- Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
- Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
- Opera: Naciśnij klawisze Ctrl+F5.
/* ─── LawRus — Common.js ────────────────────────────────────────────────────
1. Przenoszenie sekcji uczestników pod właściwe sekcje Umów w formularzu.
2. Walidacja formularza WpisKroniki przed zapisem (status ≥ 4).
───────────────────────────────────────────────────────────────────────────── */
/* Potwierdza że plik jest parsowany przez przeglądarkę */
console.log( '[LawRus] Common.js: plik załadowany (poza document.ready)' );
function lawrusReorderParticipants() {
var $h3kraj = $( 'span.mw-headline[id="Uczestnicy_umowy_krajowej"]' ).closest( 'h3' );
var $h3miedz = $( 'span.mw-headline' ).filter( function () {
return ( $( this ).attr( 'id' ) || '' ).indexOf( 'Uczestnicy_umowy_mi' ) === 0;
} ).closest( 'h3' );
console.log( '[LawRus] reorder: h3kraj=', $h3kraj.length, 'h3miedz=', $h3miedz.length );
if ( !$h3kraj.length || !$h3miedz.length ) return;
// Przenosi tylko h3 + jego multipleTemplateWrapper — bez dotykania sąsiednich elementów
var $wrapKraj = $h3kraj.nextAll( 'div.multipleTemplateWrapper' ).first();
var $wrapMiedz = $h3miedz.nextAll( 'div.multipleTemplateWrapper' ).first();
console.log( '[LawRus] reorder: wrapKraj=', $wrapKraj.length, 'wrapMiedz=', $wrapMiedz.length );
var $h2miedz = $( 'span.mw-headline' ).filter( function () {
return ( $( this ).attr( 'id' ) || '' ).indexOf( 'Umowa_mi' ) === 0;
} ).closest( 'h2' );
var $h2tekst = $( 'span.mw-headline' ).filter( function () {
return ( $( this ).attr( 'id' ) || '' ).indexOf( 'Tekst_' ) === 0;
} ).closest( 'h2' );
console.log( '[LawRus] reorder: h2miedz=', $h2miedz.length, 'h2tekst=', $h2tekst.length );
if ( $h2miedz.length && $wrapKraj.length ) {
$h3kraj.detach();
$wrapKraj.detach();
$h2miedz.before( $h3kraj );
$h2miedz.before( $wrapKraj );
}
if ( $h2tekst.length && $wrapMiedz.length ) {
$h3miedz.detach();
$wrapMiedz.detach();
$h2tekst.before( $h3miedz );
$h2tekst.before( $wrapMiedz );
}
// Przesuń blok przycisków (Zapisz/Podgląd/Anuluj) na koniec ich kontenera
var $save = $( '#pfForm .oo-ui-buttonInputWidget' ).first();
if ( $save.length ) {
var $block = $save;
while (
$block.parent().length &&
!$block.parent().is( '#pfForm' ) &&
!$block.parent().hasClass( 'mw-parser-output' )
) {
$block = $block.parent();
}
console.log( '[LawRus] btnBlock:', $block[0].tagName, $block[0].className );
$block.parent().append( $block );
}
console.log( '[LawRus] reorder: GOTOWE' );
}
$( function () {
console.log( '[LawRus] Common.js: document.ready, ns=' + mw.config.get( 'wgNamespaceNumber' ) );
if ( mw.config.get( 'wgUserName' ) ) {
$( 'body' ).addClass( 'lawrus-zalogowany' );
}
if ( $( 'span.mw-headline[id="Uczestnicy_umowy_krajowej"]' ).length ) {
lawrusReorderParticipants();
}
/* ── Walidacja przed zapisem (tylko formularz WpisKroniki) ── */
var $form = $( '#pfForm' );
if ( !$form.length ) return;
var REQUIRED_AT_4 = [
{ id: 'input_datacja_rok_lacinski', label: 'Rok AD' },
{ id: 'input_jezyk_oryginalu', label: 'Język oryginału' },
{ id: 'input_kraj', label: 'Kraj' },
{ id: 'input_tekst_zrodlowy', label: 'Tekst źródłowy' },
{ id: 'input_bibliografia', label: 'Bibliografia' },
{ id: 'input_streszczenie_pl', label: 'Streszczenie PL' },
{ id: 'input_streszczenie_en', label: 'Streszczenie EN' },
{ id: 'input_tlumaczenie_pl', label: 'Tłumaczenie PL' },
{ id: 'input_tlumaczenie_en', label: 'Tłumaczenie EN' }
];
var HIGH_STATUS = [ '4-do-publikacji', '5-opublikowane' ];
$form.on( 'submit', function ( e ) {
var status = $( '#input_status_wpisu' ).val() || '';
if ( HIGH_STATUS.indexOf( status ) === -1 ) return;
var missing = REQUIRED_AT_4.filter( function ( f ) {
return ( $( '#' + f.id ).val() || '' ).trim() === '';
} );
if ( $( '[id^=”input_typ_wpisu_”]:checked' ).length === 0 ) {
missing.push( { id: null, label: 'Typ wpisu' } );
}
if ( missing.length === 0 ) return;
e.preventDefault();
var names = missing.map( function ( f ) { return f.label; } ).join( ', ' );
mw.loader.using( 'mediawiki.notification' ).then( function () {
mw.notify(
'Przy statusie „' + status + '” wymagane są: ' + names + '. Uzupełnij przed zapisem.',
{ type: 'error', autoHide: false, tag: 'lawrus-validation' }
);
} );
missing.forEach( function ( f ) {
if ( f.id ) { $( '#' + f.id ).css( 'border-color', '#d33' ); }
} );
missing.forEach( function ( f ) {
if ( f.id ) {
$( '#' + f.id ).one( 'input', function () {
$( this ).css( 'border-color', '' );
} );
}
} );
} );
} );
