Hide total in columns
This commit is contained in:
59
Asset/js/relocate.js
Normal file
59
Asset/js/relocate.js
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* FinanceBuddy -- place the "Hide/Show column total" entry inside the native column menu.
|
||||
*
|
||||
* Kanboard only exposes the template:board:column:dropdown hook AFTER the column menu <ul>, and its
|
||||
* dropdown JS clones just that <ul> when the menu opens. So the hook item cannot reach the menu on
|
||||
* its own. column_dropdown.php renders the item hidden next to the menu; this script moves each such
|
||||
* item into that column's real <ul> so it appears alongside "Hide this column", etc.
|
||||
*
|
||||
* BoardDragAndDrop.refresh() does $("#board-container").replaceWith(data) on every drag-and-drop and
|
||||
* poll refresh, so the observer is bound to the STABLE parent of #board-container (which survives the
|
||||
* swap), not to #board-container itself -- otherwise it would be left watching a detached node and
|
||||
* the entry would vanish until a full page reload.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function relocate() {
|
||||
var items = document.querySelectorAll(".financebuddy-menu-item");
|
||||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var li = items[i];
|
||||
|
||||
// Already moved into a menu list: just make sure it is visible.
|
||||
if (li.closest("ul")) {
|
||||
li.style.display = "";
|
||||
continue;
|
||||
}
|
||||
|
||||
// The hook renders the item as a child of the column's dropdown wrapper; its first <ul>
|
||||
// is the native menu.
|
||||
var menu = li.parentNode ? li.parentNode.querySelector("ul") : null;
|
||||
|
||||
if (menu) {
|
||||
menu.appendChild(li);
|
||||
li.style.display = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
var container = document.getElementById("board-container");
|
||||
|
||||
if (!container) {
|
||||
return;
|
||||
}
|
||||
|
||||
relocate();
|
||||
|
||||
if (window.MutationObserver && container.parentNode) {
|
||||
new MutationObserver(relocate).observe(container.parentNode, { childList: true, subtree: true });
|
||||
}
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user