MediaWiki:Common.js
From Aeroraft
Jump to navigationJump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
/* Das folgende JavaScript wird für alle Benutzer geladen.*/
/* Menüeintrag in der Sidebar Create New Document*/
$(document).ready(function() {
// Finde die ul-Liste innerhalb des Create New Page Menüs
var createMenu = $("#p-Create_New_Page .pBody > ul");
// Füge die Untermenüpunkte für die Erstellung neuer Seiten hinzu
createMenu.append(
'<li><a href="/index.php?title=Special:FormEdit/New_Main_Process">New Main Process</a></li>' +
'<li><a href="/index.php?title=Special:FormEdit/New_Document">New Document</a></li>' +
'<li><a href="/index.php?title=Special:FormEdit/New_Work_Instruction">New Work Instruction</a></li>' +
'<li><a href="/index.php?title=Special:FormEdit/New_Info_Page">New Info Page</a></li>'
);
});
// Einschränkungen für Properties
$(document).ready(function () {
// Document Type - Nur Administratoren dürfen es ändern
if (mw.config.get('wgUserGroups').indexOf('sysop') === -1) {
$('input[name="Has document type"], select[name="Has document type"]').prop('disabled', true);
}
// Scope of Validity - Nur Administratoren dürfen es ändern
if (mw.config.get('wgUserGroups').indexOf('sysop') === -1) {
$('input[name="Has scope of validity"], select[name="Has scope of validity"]').prop('disabled', true);
}
// Dynamische Dropdowns für PageTitle-Generierung
$('#process-selector').change(function () {
const selectedProcess = $(this).val();
$.ajax({
url: mw.util.wikiScript('api'),
data: {
action: 'ask',
query: `[[Has main process::${selectedProcess}]]|?Has subproperty`,
format: 'json'
},
success: function (data) {
const subProcesses = data.query.results;
$('#subprocess-selector').empty();
$.each(subProcesses, function (key, value) {
// Verwendung des Template Literals mit korrektem Syntax
$('#subprocess-selector').append(`<option value="${key}">${value.printouts['Has subproperty'][0]}</option>`);
});
}
});
});
});
// Fügt die Statusanzeige basierend auf dem Semantic Property hinzu
$(document).ready(function () {
$('.semantic-status').each(function () {
var status = $(this).text();
if (status === 'Draft') {
$(this).addClass('page-status-draft');
} else if (status === 'Rejected') {
$(this).addClass('page-status-rejected');
} else if (status === 'Approved') {
$(this).addClass('page-status-approved');
}
});
});
//Menüanpassung für Freigegebene Seiten und Entwürfe:
$(document).ready(function(){
var approvalStatus = mw.config.get('wgSemanticData')['Has approval status'];
if (approvalStatus === 'Draft') {
// Füge spezielle Markierung für Entwürfe hinzu
$('#p-personal').append('<li>Entwurf</li>');
} else if (approvalStatus === 'Approved') {
// Füge spezielle Markierung für genehmigte Seiten hinzu
$('#p-personal').append('<li>Genehmigt</li>');
}
});
//Skalierung der Koordinaten
(function() {
const imageMap = document.querySelector('img[usemap="#image-map"]');
const areas = document.querySelectorAll('map[name="image-map"] area');
function adjustCoords() {
const imgWidth = imageMap.offsetWidth;
const imgHeight = imageMap.offsetHeight;
areas.forEach(area => {
const coords = area.getAttribute('coords').split(',');
const newCoords = coords.map((coord, index) => {
return (index % 2 === 0)
? Math.round(coord * (imgWidth / 1000)) // x-Coordinate scaling
: Math.round(coord * (imgHeight / 500)); // y-Coordinate scaling
});
area.setAttribute('coords', newCoords.join(','));
});
}
window.addEventListener('resize', adjustCoords);
window.addEventListener('load', adjustCoords);
})();
// Auto-fill "Created On" field with the current date
$(document).ready(function () {
// Check if the form contains a field for "Created On"
const createdOnField = $('[name="Has created on"]');
if (createdOnField.length) {
// Get the current date in YYYY-MM-DD format
const currentDate = new Date().toISOString().split('T')[0];
// Set the value of the field
createdOnField.val(currentDate);
}
});
// Script zur Erfassung des Benutzernamens Kopfdaten für Dokumentenbearbeitung
mw.hook('formEdit').add(function () {
// Prüfe, ob die Seite ein Formular verwendet
if (mw.config.get('wgNamespaceNumber') >= 0) {
const currentUser = mw.config.get('wgUserName'); // Aktueller Benutzername ermitteln
const editorField = $('input[name="Has editor"]'); // Eingabefeld für "Has editor"
if (editorField.length) {
// Setze den Wert des Feldes "Has editor"
editorField.val('User:' + currentUser);
}
}
});