Skip to content

Commit

Permalink
feat(accordion): Removing outdated code in the js - FRONT-4465 (#3438)
Browse files Browse the repository at this point in the history
  • Loading branch information
planctus authored Jun 18, 2024
1 parent 81c9782 commit d53db9c
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions src/implementations/vanilla/components/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class Accordion {
this.target = null;

// Bind `this` for use in callbacks
this.handleClickOutside = this.handleClickOutside.bind(this);
this.handleClickOnToggle = this.handleClickOnToggle.bind(this);
}

Expand All @@ -75,15 +74,13 @@ export class Accordion {
}
ECL.components = ECL.components || new Map();

document.addEventListener('click', this.handleClickOutside);

this.toggles = queryAll(this.toggleSelector, this.element);

// Bind click event on toggles
if (this.attachClickListener && this.toggles) {
this.toggles.forEach((toggle) => {
toggle.addEventListener('click', (event) =>
this.handleClickOnToggle(event, toggle),
toggle.addEventListener('click', () =>
this.handleClickOnToggle(toggle),
);
});
}
Expand Down Expand Up @@ -128,7 +125,6 @@ export class Accordion {
* Destroy component.
*/
destroy() {
document.removeEventListener('click', this.handleClickOutside);
if (this.attachClickListener && this.toggles) {
this.toggles.forEach((toggle) => {
toggle.replaceWith(toggle.cloneNode(true));
Expand All @@ -140,23 +136,12 @@ export class Accordion {
}
}

/**
* @param {e} Event
*/
handleClickOutside(e) {
if (e.target && this.toggles && !this.element.contains(e.target)) {
this.toggles.forEach((item) =>
item.classList.remove('ecl-accordion__toggle--active'),
);
}
}

/**
* @param {HTMLElement} toggle Target element to toggle.
*
* @fires Accordion#onToggle
*/
handleClickOnToggle(event, toggle) {
handleClickOnToggle(toggle) {
let isOpening = false;
// Get target element
const target = queryOne(
Expand Down Expand Up @@ -204,14 +189,6 @@ export class Accordion {
useNode.setAttribute('xlink:href', newXlinkHref);
}
}

this.toggles.forEach((item) =>
item.classList.remove('ecl-accordion__toggle--active'),
);
// This is the way we distinguish the click from a press on Enter
if (event.detail > 0) {
toggle.classList.add('ecl-accordion__toggle--active');
}
}
}

Expand Down

1 comment on commit d53db9c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.