MediaWiki:Common.js: Unterschied zwischen den Versionen
Erscheinungsbild
Gerard (Diskussion | Beiträge) KKeine Bearbeitungszusammenfassung |
Gerard (Diskussion | Beiträge) KKeine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
/* ============================================================ | /* ============================================================ | ||
COMMON.JS – Master-Version für mehrere Wikis | |||
Neutral, modular, mit Pfaden für BlueX (/Wiki_BlueX/images/) | |||
============================================================ */ | |||
/* ============================================================ | |||
1) Edit-Icons für "Bearbeiten" & "Quelltext bearbeiten" | |||
============================================================ */ | |||
mw.hook('wikipage.content').add(function ($content) { | |||
$content.find('.mw-editsection a').each(function () { | |||
const $a = $(this); | |||
const text = $a.text().trim(); | |||
// Basis-Styling für Icon-Links | |||
$a.css({ | |||
'font-size': '0', | |||
'display': 'inline-block', | |||
'width': '22px', | |||
'height': '22px', | |||
'background-size': 'contain', | |||
'background-repeat': 'no-repeat', | |||
'background-position': 'center', | |||
'vertical-align': 'middle', | |||
'margin-left': '4px' | |||
}); | |||
// Icon-Zuweisung (BlueX-Pfade) | |||
if (text === 'Bearbeiten') { | |||
$a.css('background-image', 'url("/Wiki_BlueX/images/e/e6/EditIcon.png")'); | |||
} | |||
if (text === 'Quelltext bearbeiten') { | |||
$a.css('background-image', 'url("/Wiki_BlueX/images/f/f6/QEditIcon.png")'); | |||
} | |||
}); | |||
// Klammern entfernen | |||
$content.find('.mw-editsection').css('font-size', '0'); | |||
}); | |||
/* ============================================================ | |||
2) Sidebar-Werkzeuge → eingebaute Toolbox kopieren | |||
============================================================ */ | |||
mw.loader.using('jquery').then(function () { | |||
const sidebarTools = $('#p-toolbox .vector-menu-content-list'); | |||
const builtinTools = $('#p-tb-list'); | |||
if (sidebarTools.length && builtinTools.length) { | |||
builtinTools.empty(); | |||
sidebarTools.children().clone().appendTo(builtinTools); | |||
} | |||
}); | |||
/* ============================================================ | |||
3) Vector-2022 – Collapse-Zustand speichern | |||
============================================================ */ | ============================================================ */ | ||
mw.hook('wikipage.content').add(function () { | mw.hook('wikipage.content').add(function () { | ||
if (mw.config.get('skin') !== 'vector-2022') return; | if (mw.config.get('skin') !== 'vector-2022') return; | ||
$('.vector-menu-heading').each(function () { | $('.vector-menu-heading').each(function () { | ||
const heading = $(this); | const heading = $(this); | ||
const content = heading.next('.vector-menu-content'); | const content = heading.next('.vector-menu-content'); | ||
const menu = heading.closest('.vector-menu'); | const menu = heading.closest('.vector-menu'); | ||
const id = menu.attr('id'); | const id = menu.attr('id'); | ||
if (!id) return; | if (!id) return; | ||
const saved = localStorage.getItem('v22-collapse-' + id); | const saved = localStorage.getItem('v22-collapse-' + id); | ||
| Zeile 28: | Zeile 84: | ||
} | } | ||
heading.off('click.v22').on('click.v22', function () { | heading.off('click.v22').on('click.v22', function () { | ||
heading.toggleClass('collapsed'); | heading.toggleClass('collapsed'); | ||
content.slideToggle(120); | content.slideToggle(120); | ||
localStorage.setItem( | localStorage.setItem( | ||
'v22-collapse-' + id, | 'v22-collapse-' + id, | ||
| Zeile 42: | Zeile 95: | ||
}); | }); | ||
}); | }); | ||
/* ============================================================ | /* ============================================================ | ||
4) Vector-2022 – Leere Menüs automatisch ausblenden | |||
============================================================ */ | ============================================================ */ | ||
| Zeile 57: | Zeile 112: | ||
const content = menu.find('.vector-menu-content'); | const content = menu.find('.vector-menu-content'); | ||
const headingEmpty = $.trim(heading.text()) === ""; | const headingEmpty = $.trim(heading.text()) === ""; | ||
const contentEmpty = content.find('li').length === 0; | const contentEmpty = content.find('li').length === 0; | ||
if (headingEmpty && contentEmpty) { | if (headingEmpty && contentEmpty) { | ||
menu.hide(); | menu.hide(); | ||
} | } | ||
}); | }); | ||
}); | |||
/* ============================================================ | |||
5) Admin-Werkzeuge in rechte Werkzeugleiste einfügen | |||
============================================================ */ | |||
$(document).ready(function () { | |||
const adminGroups = ['sysop', 'bureaucrat', 'interface-admin']; | |||
const userGroups = mw.config.get('wgUserGroups'); | |||
if (!userGroups.some(g => adminGroups.includes(g))) return; | |||
const $container = $('#p-tb .vector-menu-content-list'); | |||
if (!$container.length) return; | |||
// Überschrift | |||
$container.append('<li class="vector-menu-heading">Admin-Werkzeuge</li>'); | |||
// Beispiel-Link (neutral) | |||
$container.append( | |||
$('<li>').append( | |||
$('<a>') | |||
.attr('href', mw.util.getUrl('Spezial:Spezialseiten')) | |||
.text('Spezialseiten') | |||
) | |||
); | |||
}); | }); | ||
Version vom 31. Mai 2026, 07:23 Uhr
/* ============================================================
COMMON.JS – Master-Version für mehrere Wikis
Neutral, modular, mit Pfaden für BlueX (/Wiki_BlueX/images/)
============================================================ */
/* ============================================================
1) Edit-Icons für "Bearbeiten" & "Quelltext bearbeiten"
============================================================ */
mw.hook('wikipage.content').add(function ($content) {
$content.find('.mw-editsection a').each(function () {
const $a = $(this);
const text = $a.text().trim();
// Basis-Styling für Icon-Links
$a.css({
'font-size': '0',
'display': 'inline-block',
'width': '22px',
'height': '22px',
'background-size': 'contain',
'background-repeat': 'no-repeat',
'background-position': 'center',
'vertical-align': 'middle',
'margin-left': '4px'
});
// Icon-Zuweisung (BlueX-Pfade)
if (text === 'Bearbeiten') {
$a.css('background-image', 'url("/Wiki_BlueX/images/e/e6/EditIcon.png")');
}
if (text === 'Quelltext bearbeiten') {
$a.css('background-image', 'url("/Wiki_BlueX/images/f/f6/QEditIcon.png")');
}
});
// Klammern entfernen
$content.find('.mw-editsection').css('font-size', '0');
});
/* ============================================================
2) Sidebar-Werkzeuge → eingebaute Toolbox kopieren
============================================================ */
mw.loader.using('jquery').then(function () {
const sidebarTools = $('#p-toolbox .vector-menu-content-list');
const builtinTools = $('#p-tb-list');
if (sidebarTools.length && builtinTools.length) {
builtinTools.empty();
sidebarTools.children().clone().appendTo(builtinTools);
}
});
/* ============================================================
3) Vector-2022 – Collapse-Zustand speichern
============================================================ */
mw.hook('wikipage.content').add(function () {
if (mw.config.get('skin') !== 'vector-2022') return;
$('.vector-menu-heading').each(function () {
const heading = $(this);
const content = heading.next('.vector-menu-content');
const menu = heading.closest('.vector-menu');
const id = menu.attr('id');
if (!id) return;
const saved = localStorage.getItem('v22-collapse-' + id);
if (saved === 'collapsed') {
content.hide();
heading.addClass('collapsed');
}
heading.off('click.v22').on('click.v22', function () {
heading.toggleClass('collapsed');
content.slideToggle(120);
localStorage.setItem(
'v22-collapse-' + id,
heading.hasClass('collapsed') ? 'collapsed' : 'open'
);
});
});
});
/* ============================================================
4) Vector-2022 – Leere Menüs automatisch ausblenden
============================================================ */
mw.hook('wikipage.content').add(function () {
if (mw.config.get('skin') !== 'vector-2022') return;
$('.vector-menu').each(function () {
const menu = $(this);
const heading = menu.find('.vector-menu-heading');
const content = menu.find('.vector-menu-content');
const headingEmpty = $.trim(heading.text()) === "";
const contentEmpty = content.find('li').length === 0;
if (headingEmpty && contentEmpty) {
menu.hide();
}
});
});
/* ============================================================
5) Admin-Werkzeuge in rechte Werkzeugleiste einfügen
============================================================ */
$(document).ready(function () {
const adminGroups = ['sysop', 'bureaucrat', 'interface-admin'];
const userGroups = mw.config.get('wgUserGroups');
if (!userGroups.some(g => adminGroups.includes(g))) return;
const $container = $('#p-tb .vector-menu-content-list');
if (!$container.length) return;
// Überschrift
$container.append('<li class="vector-menu-heading">Admin-Werkzeuge</li>');
// Beispiel-Link (neutral)
$container.append(
$('<li>').append(
$('<a>')
.attr('href', mw.util.getUrl('Spezial:Spezialseiten'))
.text('Spezialseiten')
)
);
});