/* * OrganonTweaks -- clicking a task title opens the edit modal instead of the read-only card view, * reusing Kanboard's own modal opener (KB.modal.open). * - Board: the title is a link, and a hidden marker rendered next to it (only when the user may * edit) carries the server-generated edit URL. * - Card view: the title (#task-summary > h2) opens the same modal via #task-view's data-edit-url, * but only when the user may edit -- detected by the presence of the sidebar "Edit" action. * * A capture-phase delegated click runs before Kanboard's own handlers, survives the board's AJAX * re-renders, and stops both the link navigation and the card's own click. */ (function () { "use strict"; function openEdit(url) { if (url && window.KB && KB.modal) { KB.modal.open(url, "large", false); } } // The sidebar "Edit the task" action (fa-edit) only renders when the current user may edit. function canEdit() { return !!document.querySelector(".sidebar a i.fa-edit"); } document.addEventListener("click", function (e) { if (!e.target || !e.target.closest) { return; } // Board card title -> open the edit modal via the per-card marker URL. var link = e.target.closest(".task-board-title a"); if (link) { var card = link.closest(".task-board"); var marker = card ? card.querySelector(".organon-edit-url") : null; if (marker) { e.preventDefault(); e.stopPropagation(); openEdit(marker.getAttribute("data-url")); } return; } // Card-view title -> open the same edit modal (#task-view carries the edit URL). var title = e.target.closest("#task-summary > h2"); if (title && canEdit()) { var taskView = document.querySelector("#task-view"); if (taskView && taskView.getAttribute("data-edit-url")) { openEdit(taskView.getAttribute("data-edit-url")); } } }, true); // Make the card-view title look clickable (the board title is already a link). function markTitle() { var title = document.querySelector("#task-summary > h2"); if (title && canEdit()) { title.style.cursor = "pointer"; } } if (document.readyState !== "loading") { markTitle(); } else { document.addEventListener("DOMContentLoaded", markTitle); } })();