Unify modals

This commit is contained in:
2026-04-22 18:26:31 +02:00
parent 7c0d856081
commit 093b5c2ef0
6 changed files with 337 additions and 49 deletions
+86 -20
View File
@@ -1,25 +1,91 @@
function newPage() {
var input = document.createElement('input');
input.type = 'text';
input.className = 'modal-input';
input.placeholder = 'New page name';
openModal({
title: 'New page',
body: input,
confirm: {
label: 'CREATE',
onConfirm: function () {
var name = input.value.trim();
if (!name) return;
window.location.href = window.location.pathname +
encodeURIComponent(name) + '/?edit';
}
}
});
}
function movePage() {
const current = window.location.pathname;
const target = prompt('Move this page to (absolute path):', current);
if (target === null) return;
const clean = target.trim();
if (!clean || !clean.startsWith('/')) {
alert('Move target must be an absolute path starting with /');
return;
}
const form = document.createElement('form');
form.method = 'POST';
form.action = current + '?move=' + encodeURIComponent(clean);
document.body.appendChild(form);
form.submit();
var input = document.createElement('input');
input.type = 'text';
input.className = 'modal-input';
input.value = decodeURIComponent(window.location.pathname);
openModal({
title: 'Move page',
body: input,
confirm: {
label: 'MOVE',
onConfirm: function () {
var target = input.value.trim();
if (!target || !target.startsWith('/')) return;
var form = document.createElement('form');
form.method = 'POST';
form.action = window.location.pathname + '?move=' +
encodeURIComponent(target);
document.body.appendChild(form);
form.submit();
}
}
});
}
function deletePage() {
const current = window.location.pathname;
if (!confirm('Delete ' + current + ' and everything inside it?')) return;
const form = document.createElement('form');
form.method = 'POST';
form.action = current + '?delete=1';
document.body.appendChild(form);
form.submit();
var decodedPath = decodeURIComponent(window.location.pathname);
openModal({
title: 'Delete page',
body: 'Delete ' + decodedPath + ' and everything inside it?',
confirm: {
label: 'DELETE',
danger: true,
enterConfirms: false,
onConfirm: function () {
var form = document.createElement('form');
form.method = 'POST';
form.action = window.location.pathname + '?delete=1';
document.body.appendChild(form);
form.submit();
}
},
cancel: { autofocus: true },
swapButtons: true
});
}
document.addEventListener('DOMContentLoaded', function () {
var trigger = document.querySelector('[data-action="actions-drop"]');
if (!trigger) return;
var menu = trigger.parentElement.querySelector('.dropdown-menu');
if (!menu) return;
trigger.addEventListener('click', function (e) {
e.stopPropagation();
menu.classList.toggle('is-open');
});
menu.addEventListener('click', function () {
menu.classList.remove('is-open');
});
document.addEventListener('click', function (e) {
if (!trigger.contains(e.target) && !menu.contains(e.target)) {
menu.classList.remove('is-open');
}
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape') menu.classList.remove('is-open');
});
});