Skip to content

Commit

Permalink
ActionList: Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Jul 30, 2024
1 parent 44dfdb3 commit 0754767
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions asset/js/widget/ActionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -459,10 +457,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'));
}

/**
Expand All @@ -472,15 +470,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`));
}

/**
Expand All @@ -490,15 +480,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));
}

/**
Expand Down

0 comments on commit 0754767

Please sign in to comment.