From c91734312c3d06edc19b20af18db5c2de69d4ee2 Mon Sep 17 00:00:00 2001 From: Adam Daley Date: Tue, 10 Mar 2026 07:28:28 +0000 Subject: [PATCH] Fixes for 3 code quality findings (#3305) * Apply suggested fix to src/themes/admin_default/assets/js/utils.js from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> * Apply suggested fix to src/themes/admin_default/assets/js/utils.js from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> * Apply suggested fix to src/themes/admin_default/assets/js/utils.js from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- src/themes/admin_default/assets/js/utils.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/themes/admin_default/assets/js/utils.js b/src/themes/admin_default/assets/js/utils.js index cef59047d..324ffb5e3 100644 --- a/src/themes/admin_default/assets/js/utils.js +++ b/src/themes/admin_default/assets/js/utils.js @@ -68,10 +68,12 @@ export function safeQuerySelectorAll(selector, scope = document) { */ export function debounce(func, wait) { let timeout; - return function executedFunction(...args) { + return function executedFunction() { + const context = this; + const args = arguments; const later = () => { clearTimeout(timeout); - func(...args); + func.apply(context, args); }; clearTimeout(timeout); timeout = setTimeout(later, wait); @@ -88,14 +90,15 @@ export function throttle(func, limit) { let lastFunc; let lastRan; return function(...args) { + const context = this; if (!lastRan) { - func(...args); + func.apply(context, args); lastRan = Date.now(); } else { clearTimeout(lastFunc); lastFunc = setTimeout(() => { if ((Date.now() - lastRan) >= limit) { - func(...args); + func.apply(context, args); lastRan = Date.now(); } }, limit - (Date.now() - lastRan)); @@ -145,7 +148,8 @@ export function scrollToElement(target, options = {}) { * @returns {string} Formatted string */ export function formatBytes(bytes, decimals = 2) { - if (!Number.isFinite(bytes) || bytes <= 0) return '0 Bytes'; + if (!Number.isFinite(bytes) || bytes < 0) return '0 Bytes'; + if (bytes === 0) return '0 Bytes'; const k = 1024; const dm = decimals < 0 ? 0 : decimals;