MediaWiki:Common.js: Unterschied zwischen den Versionen
Aus smw-dev03
(Die Seite wurde neu angelegt: „→Das folgende JavaScript wird für alle Benutzer geladen.: document.addEventListener("DOMContentLoaded", function() { const form = document.querySelector("form[action*='Special:FormEdit']"); const input = form.querySelector("input[type='text']"); const warning = document.getElementById("gutachten-warning"); form.addEventListener("submit", function(e) { e.preventDefault(); const pageName = input.value.trim(); if (!pageName) retur…“) |
Keine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
$(document).ready(function() { | |||
// Only run on Special:Mit_Formular_bearbeiten | |||
if (mw.config.get('wgCanonicalSpecialPageName') === 'FormEdit') { | |||
const urlParts = window.location.pathname.split('/'); | |||
const formName = urlParts[urlParts.length - 2]; | |||
const pageName = decodeURIComponent(urlParts[urlParts.length - 1]); | |||
// show warning | // Only run for the GutachtenAuspragungForm | ||
if (formName === 'GutachtenAuspragungForm') { | |||
const apiUrl = mw.util.wikiScript('api') + '?action=query&titles=' + encodeURIComponent(pageName) + '&format=json'; | |||
$.getJSON(apiUrl, function(data) { | |||
const pages = data.query.pages; | |||
const exists = !pages.hasOwnProperty('-1'); | |||
} | |||
} | if (!exists) { | ||
// If page doesn't exist, show warning and redirect user to creation link instead | |||
alert('Dieses Gutachten existiert nicht. Bitte verwenden Sie den Button „Neues Gutachten erstellen“, um ein Gutachten anzulegen.'); | |||
window.location.href = mw.util.getUrl('Spezial:Mit_Formular_bearbeiten', {form: 'GutachtenAuspragungForm'}); | |||
} | |||
// else: existing page, no action needed | |||
}); | |||
} | |||
} | |||
}); | }); | ||
Version vom 5. Mai 2025, 12:52 Uhr
$(document).ready(function() {
// Only run on Special:Mit_Formular_bearbeiten
if (mw.config.get('wgCanonicalSpecialPageName') === 'FormEdit') {
const urlParts = window.location.pathname.split('/');
const formName = urlParts[urlParts.length - 2];
const pageName = decodeURIComponent(urlParts[urlParts.length - 1]);
// Only run for the GutachtenAuspragungForm
if (formName === 'GutachtenAuspragungForm') {
const apiUrl = mw.util.wikiScript('api') + '?action=query&titles=' + encodeURIComponent(pageName) + '&format=json';
$.getJSON(apiUrl, function(data) {
const pages = data.query.pages;
const exists = !pages.hasOwnProperty('-1');
if (!exists) {
// If page doesn't exist, show warning and redirect user to creation link instead
alert('Dieses Gutachten existiert nicht. Bitte verwenden Sie den Button „Neues Gutachten erstellen“, um ein Gutachten anzulegen.');
window.location.href = mw.util.getUrl('Spezial:Mit_Formular_bearbeiten', {form: 'GutachtenAuspragungForm'});
}
// else: existing page, no action needed
});
}
}
});