From 5795ec055fa96e3da7bd7bfc9e3c0dc356aa66c7 Mon Sep 17 00:00:00 2001 From: AuDevTist1C <114492072+AuDevTist1C@users.noreply.github.com> Date: Wed, 12 Aug 2026 06:44:58 +0200 Subject: [PATCH] refactor(file-browser): Streamline event delegation target resolution and simplify selection mode DOM queries Optimize event handling efficiency and DOM interaction performance within the file browser module by hoisting target resolution to the entry point of the click event listener and removing redundant ancestor tree traversals during item multi-selection. * **Event Target Delegation & Null-Safety (`src/pages/fileBrowser/fileBrowser.js`):** * Replaced direct `e.target` assignment with `e.target.closest(".tile, .nav")` to resolve the root interactive item or navigation element immediately upon event dispatch. * Added `isTileEl` evaluation via optional chaining (`$el?.classList.contains("tile")`) to explicitly distinguish file/folder item tiles from navigation elements. * Applied optional chaining checks to action attribute lookups (`$el?.getAttribute("action")` and `$el?.dataset.action`), preventing runtime errors when click events originate from non-interactive container padding outside targeted elements. * **Selection Mode & Target Traversal Refactoring (`src/pages/fileBrowser/fileBrowser.js`):** * Eliminated redundant secondary DOM ancestor queries (`$el.closest(".tile")`) inside the selection mode branch, reducing DOM tree lookup overhead. * Consolidated tile verification and unselectable dataset checks into a unified early guard clause (`if (!isTileEl || $el.dataset.notSelectable != null) return;`). * Rebound child element queries for checkbox toggling (`$el.querySelector(".input-checkbox")`) and URL extraction (`$el.querySelector("data-url").textContent`) directly to `$el`, removing temporary element references and simplifying scope management. (AI generated commit message) --- src/pages/fileBrowser/fileBrowser.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/fileBrowser/fileBrowser.js b/src/pages/fileBrowser/fileBrowser.js index ee56da6a1..05f66e3d0 100644 --- a/src/pages/fileBrowser/fileBrowser.js +++ b/src/pages/fileBrowser/fileBrowser.js @@ -916,15 +916,15 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) { /** * @type {HTMLElement} */ - const $el = e.target; + const $el = e.target.closest(".tile, .nav"); + const isTileEl = $el?.classList.contains("tile"); if (isSelectionMode) { - const $el2 = $el.closest(".tile"); - if ($el2?.dataset.notSelectable != null) return; - const checkbox = $el2?.querySelector(".input-checkbox"); + if (!isTileEl || $el.dataset.notSelectable != null) return; + const checkbox = $el.querySelector(".input-checkbox"); if (checkbox && !$el.closest(".selection-header")) { checkbox.checked = !checkbox.checked; - const url = $el2.querySelector("data-url").textContent; + const url = $el.querySelector("data-url").textContent; if (checkbox.checked) { selectedItems.add(url); } else { @@ -936,7 +936,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) { return; } - let action = $el.getAttribute("action") || $el.dataset.action; + let action = $el?.getAttribute("action") || $el?.dataset.action; if (!action) return; let url = $el.dataset.url;