Improved Page lik handling

This commit is contained in:
2026-02-02 22:36:38 +01:00
parent 47a8bfa50a
commit 1b6df4a9e4
8 changed files with 245 additions and 130 deletions

View File

@@ -77,10 +77,6 @@
return false;
}
function fetchInfo() {
return requestPageLink('info', {});
}
function ensurePageLink() {
return requestPageLink('ensure', { sectok: getSectok() });
}
@@ -111,33 +107,24 @@
} catch (e2) {}
}
function attachStatus() {
var status = document.querySelector('.luxtools-pagelink-status[data-luxtools-pagelink="1"]');
if (!status) return;
function attachCopyTargets() {
var targets = document.querySelectorAll('[data-luxtools-pagelink-copy="1"]');
if (!targets || !targets.length) return;
var pageTitle = document.querySelector('#dokuwiki__content h1')
|| document.querySelector('.pageId')
|| document.querySelector('h1');
if (pageTitle && pageTitle.appendChild) {
status.classList.add('is-inline');
pageTitle.appendChild(status);
}
var copy = String(status.getAttribute('data-copy') || '') === '1';
if (copy) {
status.setAttribute('role', 'button');
status.setAttribute('tabindex', '0');
status.addEventListener('click', function (e) {
targets.forEach(function (el) {
if (!el || !el.getAttribute) return;
el.setAttribute('role', 'button');
el.setAttribute('tabindex', '0');
el.addEventListener('click', function (e) {
e.preventDefault();
copyToClipboard(String(status.getAttribute('data-uuid') || '').trim());
copyToClipboard(String(el.getAttribute('data-uuid') || '').trim());
});
status.addEventListener('keydown', function (e) {
el.addEventListener('keydown', function (e) {
if (!e || (e.key !== 'Enter' && e.key !== ' ')) return;
e.preventDefault();
copyToClipboard(String(status.getAttribute('data-uuid') || '').trim());
copyToClipboard(String(el.getAttribute('data-uuid') || '').trim());
});
}
});
}
window.addBtnActionLuxtoolsPageLink = function ($btn, props, edid) {
@@ -178,5 +165,5 @@
return 'luxtools-pagelink';
};
document.addEventListener('DOMContentLoaded', attachStatus, false);
document.addEventListener('DOMContentLoaded', attachCopyTargets, false);
})();