Remove obsolete functions

This commit is contained in:
2026-06-16 10:25:24 +02:00
parent 404ce088f3
commit f8b09e18bd
6 changed files with 13 additions and 343 deletions
+9 -106
View File
@@ -2,113 +2,16 @@
var content = document.querySelector('.content');
if (!content) return;
var allHeadings = content.querySelectorAll('h1, h2, h3, h4, h5, h6');
if (!allHeadings.length) return;
var headings = content.querySelectorAll('h2, h3, h4');
if (!headings.length) return;
function copyAnchor(id, item, label, menu) {
var url = window.location.origin + window.location.pathname + '#' + id;
function flash() {
item.textContent = 'Copied!';
setTimeout(function () {
item.textContent = label;
menu.classList.remove('is-open');
}, 1200);
}
function fallback() {
var ta = document.createElement('textarea');
ta.value = url;
ta.setAttribute('readonly', '');
ta.style.position = 'fixed';
ta.style.opacity = '0';
document.body.appendChild(ta);
ta.select();
var ok = false;
try { ok = document.execCommand('copy'); } catch (e) { ok = false; }
document.body.removeChild(ta);
if (ok) flash();
else openModal({
title: 'Copy anchor link',
body: 'Could not copy automatically. URL:\n' + url,
confirm: { label: 'OK', onConfirm: function () { closeModal(); } }
});
}
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(url).then(flash, fallback);
} else {
fallback();
}
}
function addTask(sectionIndex, headingId) {
var input = document.createElement('input');
input.type = 'text';
input.className = 'input';
input.placeholder = 'Task description';
var ctrl = openModal({
title: 'Add task',
body: input,
confirm: {
label: 'ADD',
initiallyDisabled: true,
onConfirm: function () {
var text = input.value.trim();
if (!text) return;
var action = window.location.pathname + '?addtask=' + sectionIndex;
var target = window.location.pathname + '#' + headingId;
closeModal();
postReplace(action, 'text=' + encodeURIComponent(text), target);
}
}
});
input.addEventListener('input', function () {
ctrl.setConfirmDisabled(input.value.trim() === '');
});
}
allHeadings.forEach(function (h, i) {
headings.forEach(function (h) {
if (!h.id) return;
var tag = h.tagName.toLowerCase();
if (tag !== 'h2' && tag !== 'h3' && tag !== 'h4') return;
var sectionIndex = i + 1;
var wrap = document.createElement('span');
wrap.className = 'dropdown heading-anchor';
var trigger = document.createElement('button');
trigger.type = 'button';
trigger.className = 'dropdown-toggle';
trigger.setAttribute('aria-haspopup', 'menu');
trigger.setAttribute('aria-label', 'Section actions');
trigger.textContent = '#';
var menu = document.createElement('div');
menu.className = 'dropdown-menu';
var copyLabel = 'Copy anchor link';
var copyBtn = document.createElement('button');
copyBtn.type = 'button';
copyBtn.className = 'btn btn-tool btn-block';
copyBtn.dataset.action = 'copy-anchor';
copyBtn.textContent = copyLabel;
copyBtn.addEventListener('click', function (e) {
e.stopPropagation();
copyAnchor(h.id, copyBtn, copyLabel, menu);
});
var addBtn = document.createElement('button');
addBtn.type = 'button';
addBtn.className = 'btn btn-tool btn-block';
addBtn.dataset.action = 'add-task';
addBtn.textContent = 'Add task';
addBtn.addEventListener('click', function () { addTask(sectionIndex, h.id); });
menu.appendChild(copyBtn);
menu.appendChild(addBtn);
wrap.appendChild(trigger);
wrap.appendChild(menu);
h.insertBefore(wrap, h.firstChild);
wireDropdown(trigger);
var a = document.createElement('a');
a.href = '#' + h.id;
a.className = 'heading-anchor';
a.setAttribute('aria-label', 'Link to this section');
a.textContent = '#';
h.insertBefore(a, h.firstChild);
});
}());
-1
View File
@@ -57,7 +57,6 @@
{{if not .IsRoot}}
<button class="btn btn-block" onclick="movePage()" title="Move page (M)">MOVE PAGE</button>
{{end}}
<button class="btn btn-block" data-action="clean-tasks" onclick="cleanUpTasks()" title="Clean up finished tasks" hidden>CLEAN UP TASKS</button>
{{if not .IsRoot}}
<button class="btn btn-block danger" onclick="deletePage()" title="Delete page">DELETE PAGE</button>
{{end}}
-21
View File
@@ -21,25 +21,4 @@
});
});
});
var hasChecked = !!document.querySelector('input.task-checkbox:checked');
if (hasChecked) {
var btn = document.querySelector('[data-action="clean-tasks"]');
if (btn) btn.hidden = false;
}
})();
function cleanUpTasks() {
openModal({
title: 'Clean up tasks',
body: 'Remove all completed tasks from this page?',
confirm: {
label: 'CLEAN UP',
danger: true,
onConfirm: function () {
closeModal();
postReplace(window.location.pathname + '?cleantasks=1', null, window.location.pathname);
}
}
});
}