MediaWiki:Gadget-small-sections.js
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.
// <pre>
// Author: [[pl:User:Beau]]
var sectionCripplingGadget = {
version: 9,
crippledSections: {},
/**
* Inicjacja gadżetu
*/
init: function() {
// Tylko przestrzeń główna i użytkowników
if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 && mw.config.get( 'wgNamespaceNumber' ) !== 2 ) {
return;
}
//if ( mw.user.options.get( 'gadget-small-references', 0 ) == 1 ) {
// this.crippledSections['Przypisy'] = 'section-references';
//}
if ( mw.user.options.get( 'gadget-small-notes', 0 ) == 1 ) {
this.crippledSections['Uwagi'] = 'section-notes';
}
if ( mw.user.options.get( 'gadget-small-bibliography', 0 ) == 1 ) {
this.crippledSections['Bibliografia'] = 'section-bibliography';
}
if ( mw.user.options.get( 'gadget-small-external-links', 0 ) == 1 ) {
this.crippledSections['Linki zewnętrzne'] = 'section-external-links';
}
if ( mw.user.options.get( 'gadget-small-see-also', 0 ) == 1 ) {
this.crippledSections['Zobacz też'] = 'section-see-also';
}
var contentText = null;
if ( mw.config.get( 'wgAction' ) === 'view' ) {
// Czytanie
contentText = document.getElementById( 'mw-content-text' );
if ( contentText.firstChild.classList.contains( 'mw-parser-output' ) ) {
contentText = contentText.firstChild;
}
} else if ( mw.config.get( 'wgAction' ) === 'submit' ) {
// Podgląd edycji
contentText = jQuery( '.mw-parser-output' )[0];
}
if ( !contentText ) {
return;
}
var stylize = null;
var currentNode = contentText.firstChild;
var numberHeadings = ( mw.user.options.get( 'numberheadings', 0 ) == 1 );
while ( currentNode ) {
if ( currentNode.tagName && currentNode.tagName.match( /^H[1-6]$/ ) ) {
stylize = null;
var text = jQuery( currentNode ).children( '.mw-headline' ).text().trim();
if ( numberHeadings ) {
// Usuń numerację
text = text.replace( /^\d+\s*/g, '' );
}
stylize = this.crippledSections[text];
} else if ( stylize ) {
var $currentNode = jQuery( currentNode );
if ( !$currentNode.hasClass( 'do-not-make-smaller' ) ) {
$currentNode.addClass( "section-small " + stylize );
}
}
currentNode = currentNode.nextSibling;
}
}
};
jQuery( document ).ready( function() {
sectionCripplingGadget.init()
} );
// </pre>