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 29, 2024
1 parent b68eea4 commit bc00ef2
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 @@ -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'));
}

/**
Expand All @@ -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`));
}

/**
Expand All @@ -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));
}

/**
Expand Down

0 comments on commit bc00ef2

Please sign in to comment.