MediaWiki:Common.js-backup
Erscheinungsbild
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
/* Das folgende JavaScript wird für alle Benutzer geladen. Das hat ChatGPT erstellt um das Popup-Fenster für Preview (Vorschau Seiteninhalt bei Hoover auf Link) anzupassen. */
// Wartet, bis das Popup-Feature geladen ist:
mw.loader.using('ext.popups', function () {
// Registriert einen Event-Handler für neu erzeugte Popups:
$(document).on('DOMNodeInserted', '.mwe-popups-container', function (e) {
// Entfernt oder überschreibt die inline-Styles:
$(e.target).css({
'max-height': 'none',
'overflow': 'visible'
});
});
});
(function () {
if (mw.config.get('wgNamespaceNumber') !== 14) return; // nur Kategorie-Seiten
var MODE_KEY = 'mwCatLabelMode'; // 'clean' oder 'default'
var url = new URL(location.href);
var param = url.searchParams.get('catview'); // optionaler URL-Override
var mode = param || localStorage.getItem(MODE_KEY) || 'clean';
// Nur echte Listeneinträge; Paginierung/„nächste Seite“ bleibt unberührt
var anchors = Array.from(document.querySelectorAll('#mw-pages li > a[href]'))
.filter(a => !a.classList.contains('new'));
// Original-Beschriftung sichern (für Rückschaltung)
anchors.forEach(a => { if (!a.dataset.origLabel) a.dataset.origLabel = a.textContent; });
function extractTitleFromURL(href) {
var u = new URL(href, location.origin);
var t = u.searchParams.get('title');
if (!t) t = u.pathname.replace(/^\/(wiki|w)\/?/, '');
t = decodeURIComponent(t).replace(/_/g, ' ');
var i = t.indexOf('#'); if (i !== -1) t = t.slice(0, i);
return t;
}
function lastSegmentWithoutNs(title) {
return title.replace(/^[^:]+:/, '').split('/').pop();
}
function applyClean() {
anchors.forEach(a => {
var u = new URL(a.href, location.origin);
if (u.search) return; // alles mit ?query (z. B. Paginierung) überspringen
var title = extractTitleFromURL(a.href);
a.textContent = lastSegmentWithoutNs(title);
});
}
function applyDefault() {
anchors.forEach(a => { if (a.dataset.origLabel) a.textContent = a.dataset.origLabel; });
}
if (mode === 'clean') applyClean(); else applyDefault();
if (param) localStorage.setItem(MODE_KEY, mode);
// Kleines UI neben der Überschrift
var h2 = document.querySelector('#mw-pages h2');
if (h2) {
var wrap = document.createElement('span');
wrap.style.fontSize = '0.9em';
wrap.style.marginLeft = '0.5em';
var linkClean = document.createElement('a');
var linkDefault = document.createElement('a');
linkClean.href = linkDefault.href = '#';
function render() {
linkClean.textContent = (mode === 'clean' ? 'Kurz (aktiv)' : 'Kurz');
linkDefault.textContent = (mode === 'default' ? 'Standard (aktiv)' : 'Standard');
}
linkClean.addEventListener('click', function (e) {
e.preventDefault(); mode = 'clean'; localStorage.setItem(MODE_KEY, mode); applyClean(); render();
});
linkDefault.addEventListener('click', function (e) {
e.preventDefault(); mode = 'default'; localStorage.setItem(MODE_KEY, mode); applyDefault(); render();
});
wrap.appendChild(document.createTextNode('Darstellung: '));
wrap.appendChild(linkClean);
wrap.appendChild(document.createTextNode(' | '));
wrap.appendChild(linkDefault);
h2.appendChild(wrap);
render();
}
})();
/*Überschriften auf Kategorie Datum Seiten nur zeigen, wenn auch eine Tabelle existiert*/
mw.hook('wikipage.content').add(function ($c) {
$c.find('.aew-datum .aew-block').each(function () {
// Wenn innerhalb des Blocks keine SMW-Tabelle gerendert wurde → Block entfernen
if ($(this).find('table.wikitable').length === 0) {
$(this).remove();
}
});
});
/**
* Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
* loaded for all users on every wiki page. If possible create a gadget that is
* enabled by default instead of adding it here (since gadgets are fully
* optimized ResourceLoader modules with possibility to add dependencies etc.)
*
* Since Common.js isn't a gadget, there is no place to declare its
* dependencies, so we have to lazy load them with mw.loader.using on demand and
* then execute the rest in the callback. In most cases these dependencies will
* be loaded (or loading) already and the callback will not be delayed. In case a
* dependency hasn't arrived yet it'll make sure those are loaded before this.
*/
/* global mw, $ */
/* jshint strict:false, browser:true */
mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
/* Begin of mw.loader.using callback */
/**
* Map addPortletLink to mw.util
* @deprecated: Use mw.util.addPortletLink instead.
*/
mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );
/**
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
* @rev 6
*/
var extraCSS = mw.util.getParamValue( 'withCSS' ),
extraJS = mw.util.getParamValue( 'withJS' );
if ( extraCSS ) {
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
}
}
if ( extraJS ) {
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
}
}
/**
* Collapsible tables; reimplemented with mw-collapsible
* Styling is also in place to avoid FOUC
*
* Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
* @version 3.0.0 (2018-05-20)
* @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
* @author [[User:R. Koot]]
* @author [[User:Krinkle]]
* @author [[User:TheDJ]]
* @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
* is supported in MediaWiki core. Shimmable since MediaWiki 1.32
*
* @param {jQuery} $content
*/
function makeCollapsibleMwCollapsible( $content ) {
var $tables = $content
.find( 'table.collapsible:not(.mw-collapsible)' )
.addClass( 'mw-collapsible' );
$.each( $tables, function ( index, table ) {
// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
if ( $( table ).hasClass( 'collapsed' ) ) {
$( table ).addClass( 'mw-collapsed' );
// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
}
} );
if ( $tables.length > 0 ) {
mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
$tables.makeCollapsible();
} );
}
}
mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );
/**
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
*
* Maintainers: TheDJ
*/
function mwCollapsibleSetup( $collapsibleContent ) {
var $element,
$toggle,
autoCollapseThreshold = 2;
$.each( $collapsibleContent, function ( index, element ) {
$element = $( element );
if ( $element.hasClass( 'collapsible' ) ) {
$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
}
if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
$element.data( 'mw-collapsible' ).collapse();
} else if ( $element.hasClass( 'innercollapse' ) ) {
if ( $element.parents( '.outercollapse' ).length > 0 ) {
$element.data( 'mw-collapsible' ).collapse();
}
}
// because of colored backgrounds, style the link in the text color
// to ensure accessible contrast
$toggle = $element.find( '.mw-collapsible-toggle' );
if ( $toggle.length ) {
// Make the toggle inherit text color (Updated for T333357 2023-04-29)
if ( $toggle.parent()[ 0 ].style.color ) {
$toggle.css( 'color', 'inherit' );
$toggle.find( '.mw-collapsible-text' ).css( 'color', 'inherit' );
}
}
} );
}
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );
/* End of mw.loader.using callback */
} );
/* DO NOT ADD CODE BELOW THIS LINE */