diff --git a/Asset/js/title-click-edit.js b/Asset/js/title-click-edit.js index 2ac8e5c..c3f3286 100644 --- a/Asset/js/title-click-edit.js +++ b/Asset/js/title-click-edit.js @@ -1,11 +1,13 @@ /* * 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 part: 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. + * 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 is used so it (a) runs before Kanboard's own bubble-phase handlers, - * (b) survives the board's AJAX re-renders without re-binding, and (c) stops both the link navigation - * and the card's own click. + * 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"; @@ -16,6 +18,11 @@ } } + // 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; @@ -31,6 +38,30 @@ 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); + } })();