chore(course-teaser): implemented destroy in course teaser
This commit is contained in:
parent
c5760bb2eb
commit
6d66b822ac
@ -1,4 +1,5 @@
|
|||||||
import { Utility } from '../../core/utility';
|
import { Utility } from '../../core/utility';
|
||||||
|
import { EventManager, EventWrapper, EVENT_TYPE } from '../../lib/event-manager/event-manager';
|
||||||
import './course-teaser.sass';
|
import './course-teaser.sass';
|
||||||
|
|
||||||
const COURSE_TEASER_INITIALIZED_CLASS = 'course-teaser--initialized';
|
const COURSE_TEASER_INITIALIZED_CLASS = 'course-teaser--initialized';
|
||||||
@ -12,16 +13,30 @@ const COURSE_TEASER_CHEVRON_CLASS = 'course-teaser__chevron';
|
|||||||
export class CourseTeaser {
|
export class CourseTeaser {
|
||||||
|
|
||||||
_element;
|
_element;
|
||||||
|
_eventManager
|
||||||
|
|
||||||
constructor(element) {
|
constructor(element) {
|
||||||
if (!element) {
|
if (!element) {
|
||||||
throw new Error('CourseTeaser utility cannot be setup without an element!');
|
throw new Error('CourseTeaser utility cannot be setup without an element!');
|
||||||
}
|
}
|
||||||
|
this._eventManager = new EventManager();
|
||||||
if (element.classList.contains(COURSE_TEASER_INITIALIZED_CLASS)) {
|
if (element.classList.contains(COURSE_TEASER_INITIALIZED_CLASS)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this._element = element;
|
this._element = element;
|
||||||
element.addEventListener('click', e => this._onToggleExpand(e));
|
const clickHandler = e => this._onToggleExpand(e);
|
||||||
|
const clickEvent = new EventWrapper(EVENT_TYPE.CLICK, clickHandler.bind(this), element);
|
||||||
|
this._eventManager.registerNewListener(clickEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
this._eventManager.removeAllEventListenersFromUtil();
|
||||||
|
if(this._element.classList.contains(COURSE_TEASER_EXPANDED_CLASS)) {
|
||||||
|
this._element.classList.remove(COURSE_TEASER_EXPANDED_CLASS);
|
||||||
|
}
|
||||||
|
if (this._element.classList.contains(COURSE_TEASER_INITIALIZED_CLASS)) {
|
||||||
|
this._element.classList.remove(COURSE_TEASER_INITIALIZED_CLASS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onToggleExpand(event) {
|
_onToggleExpand(event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user