Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(autoinit): Review destroy method - FRONT-3596 #2389

Merged
merged 5 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,23 @@ export class Accordion {
);
});
}

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

/**
* Destroy component.
*/
static destroy() {
destroy() {
if (this.attachClickListener && this.toggles) {
this.toggles.forEach((toggle) => {
toggle.removeEventListener('click', this.handleClickOnToggle);
});
}
if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,24 @@ export class BreadcrumbCore {
);

this.check();

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

/**
* Destroy component.
*/
static destroy() {
destroy() {
if (this.attachClickListener && this.ellipsisButton) {
this.ellipsisButton.removeEventListener(
'click',
this.handleClickOnEllipsis
);
}
if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,21 @@ export class BreadcrumbHarmonised {
);

this.check();

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

static destroy() {
destroy() {
if (this.attachClickListener && this.ellipsisButton) {
this.ellipsisButton.removeEventListener(
'click',
this.handleClickOnEllipsis
);
}
if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}

handleClickOnEllipsis() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,21 @@ export class BreadcrumbStandardised {
);

this.check();

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

static destroy() {
destroy() {
if (this.attachClickListener && this.ellipsisButton) {
this.ellipsisButton.removeEventListener(
'click',
this.handleClickOnEllipsis
);
}
if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}

handleClickOnEllipsis() {
Expand Down
8 changes: 7 additions & 1 deletion src/implementations/vanilla/components/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,15 @@ export class Carousel {
if (this.attachResizeListener) {
window.addEventListener('resize', this.handleResize);
}

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

/**
* Destroy component.
*/
static destroy() {
destroy() {
if (this.cloneFirstSLide && this.cloneLastSLide) {
this.cloneFirstSLide.remove();
this.cloneLastSLide.remove();
Expand Down Expand Up @@ -209,6 +212,9 @@ export class Carousel {
if (this.attachResizeListener) {
window.removeEventListener('resize', this.handleResize);
}
if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,23 @@ export class CategoryFilter {
item.addEventListener('click', this.handleClickExpand)
);
}

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

/**
* Destroy component.
*/
static destroy() {
destroy() {
if (this.attachClickListener && this.items) {
this.items.forEach((item) => {
item.removeEventListener('click', this.handleClickExpand, false);
});
}
if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export class Datepicker {
},
});

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');

return picker;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,21 @@ export class Expandable {
if (this.attachClickListener && this.toggle) {
this.toggle.addEventListener('click', this.handleClickOnToggle);
}

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

/**
* Destroy component.
*/
static destroy() {
destroy() {
if (this.attachClickListener && this.toggle) {
this.toggle.removeEventListener('click', this.handleClickOnToggle);
}
if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,21 @@ export class FileUpload {
if (this.attachChangeListener && this.fileUploadInput) {
this.fileUploadInput.addEventListener('change', this.handleChange);
}

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

/**
* Destroy component.
*/
static destroy() {
destroy() {
if (this.attachChangeListener && this.fileUploadInput) {
this.fileUploadInput.removeEventListener('change', this.handleChange);
}
if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/implementations/vanilla/components/file/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,24 @@ export class FileDownload {
this.handleClickOnToggle
);
}

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

/**
* Destroy component.
*/
static destroy() {
destroy() {
if (this.attachClickListener && this.translationToggle) {
this.translationToggle.removeEventListener(
'click',
this.handleClickOnToggle
);
}
if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}

/**
Expand Down
9 changes: 8 additions & 1 deletion src/implementations/vanilla/components/gallery/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,15 @@ export class Gallery {
if (this.count) {
this.count.innerHTML = this.galleryItems.length;
}

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

/**
* Destroy component.
*/
static destroy() {
destroy() {
if (this.attachClickListener && this.closeButton) {
this.closeButton.removeEventListener(
'click',
Expand Down Expand Up @@ -286,6 +289,10 @@ export class Gallery {
if (this.attachResizeListener) {
window.removeEventListener('resize', this.handleResize);
}

if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ export class InpageNavigation {
);
toggleElement.addEventListener('click', this.handleClickOnToggler);
}

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

/**
Expand Down Expand Up @@ -353,7 +356,7 @@ export class InpageNavigation {
/**
* Destroy component instance.
*/
static destroy() {
destroy() {
if (this.attachClickListener && this.toggleElement) {
this.toggleElement.removeEventListener(
'click',
Expand All @@ -368,6 +371,10 @@ export class InpageNavigation {
this.destroyScrollSpy();
this.destroySticky();
this.destroyObserver();

if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/implementations/vanilla/components/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,15 @@ export class Menu {
setTimeout(() => {
this.element.classList.add('ecl-menu--transition');
}, 500);

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

/**
* Destroy component.
*/
static destroy() {
destroy() {
if (this.attachClickListener && this.open) {
this.open.removeEventListener('click', this.handleClickOnOpen);
}
Expand Down Expand Up @@ -240,6 +243,9 @@ export class Menu {
if (this.attachResizeListener) {
window.removeEventListener('resize', this.handleResize);
}
if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/implementations/vanilla/components/message/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,21 @@ export class Message {
if (this.attachClickListener && this.close) {
this.close.addEventListener('click', this.handleClickOnClose);
}

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

/**
* Destroy component.
*/
static destroy() {
destroy() {
if (this.attachClickListener && this.close) {
this.close.removeEventListener('click', this.handleClickOnClose);
}
if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,15 @@ export class NewsTicker {
if (this.attachResizeListener) {
window.addEventListener('resize', this.handleResize);
}

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

/**
* Destroy component.
*/
static destroy() {
destroy() {
if (this.attachClickListener && this.toggle) {
this.toggle.removeEventListener('click', this.handleClickOnToggle);
}
Expand All @@ -167,6 +170,9 @@ export class NewsTicker {
if (this.attachResizeListener) {
window.removeEventListener('resize', this.handleResize);
}
if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}

/**
Expand Down
9 changes: 8 additions & 1 deletion src/implementations/vanilla/components/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,15 @@ export class Select {

// Respect default selected options.
this.updateCurrentValue();

// Set ecl initialized attribute
this.element.setAttribute('data-ecl-auto-initialized', 'true');
}

/**
* Destroy component.
*/
static destroy() {
destroy() {
this.selectMultiple.removeEventListener('focusout', this.handleFocusout);
this.input.removeEventListener('keypress', this.handleToggle);
this.input.removeEventListener('click', this.handleToggle);
Expand All @@ -333,6 +336,10 @@ export class Select {
}

this.select.parentNode.classList.remove('ecl-select__container--hidden');

if (this.element) {
this.element.removeAttribute('data-ecl-auto-initialized');
}
}

updateCurrentValue() {
Expand Down
Loading