From bc00ef27e444fb15b8f90347d479c2577dc1a101 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Mon, 29 Jul 2024 10:58:45 +0200 Subject: [PATCH] ActionList: Simplify code --- asset/js/widget/ActionList.js | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/asset/js/widget/ActionList.js b/asset/js/widget/ActionList.js index 4772b4aa..fd29d06a 100644 --- a/asset/js/widget/ActionList.js +++ b/asset/js/widget/ActionList.js @@ -137,9 +137,7 @@ define(["../notjQuery"], function ($) { toActiveItems.push(item); } - if (activeItems.length === 1 - && toActiveItems.length === 0 - ) { + if (activeItems.length === 1 && toActiveItems.length === 0) { $(this.list).trigger('all-deselected'); this.clearSelection(toDeactivateItems); @@ -451,10 +449,10 @@ define(["../notjQuery"], function ($) { */ setActive(toActiveItem) { if (toActiveItem instanceof HTMLElement) { - toActiveItem.classList.add('active'); - } else { - toActiveItem.forEach(item => item.classList.add('active')); + toActiveItem = [toActiveItem] } + + toActiveItem.forEach(item => item.classList.add('active')); } /** @@ -464,15 +462,7 @@ define(["../notjQuery"], function ($) { */ getActiveItems() { - let items; - - if (this.list.tagName.toLowerCase() === 'table') { - items = this.list.querySelectorAll(`:scope > tbody > ${LIST_ITEM_IDENTIFIER}.active`); - } else { - items = this.list.querySelectorAll(`:scope > ${LIST_ITEM_IDENTIFIER}.active`); - } - - return Array.from(items); + return Array.from(this.list.querySelectorAll(`${LIST_ITEM_IDENTIFIER}.active`)); } /** @@ -482,15 +472,7 @@ define(["../notjQuery"], function ($) { */ getAllItems() { - let items; - - if (this.list.tagName.toLowerCase() === 'table') { - items = this.list.querySelectorAll(`:scope > tbody > ${LIST_ITEM_IDENTIFIER}`); - } else { - items = this.list.querySelectorAll(`:scope > ${LIST_ITEM_IDENTIFIER}`); - } - - return Array.from(items); + return Array.from(this.list.querySelectorAll(LIST_ITEM_IDENTIFIER)); } /**