2017-08-17 22:00:37 +05:30
|
|
|
import Hook from './hook';
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
class HookButton extends Hook {
|
|
|
|
constructor(trigger, list, plugins, config) {
|
|
|
|
super(trigger, list, plugins, config);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
this.type = 'button';
|
|
|
|
this.event = 'click';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
this.eventWrapper = {};
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
this.addEvents();
|
|
|
|
this.addPlugins();
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
addPlugins() {
|
2021-03-08 18:12:59 +05:30
|
|
|
this.plugins.forEach((plugin) => plugin.init(this));
|
2017-09-10 17:25:29 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
clicked(e) {
|
2021-04-29 21:17:54 +05:30
|
|
|
e.preventDefault();
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
const buttonEvent = new CustomEvent('click.dl', {
|
2017-08-17 22:00:37 +05:30
|
|
|
detail: {
|
|
|
|
hook: this,
|
|
|
|
},
|
|
|
|
bubbles: true,
|
2017-09-10 17:25:29 +05:30
|
|
|
cancelable: true,
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
e.target.dispatchEvent(buttonEvent);
|
|
|
|
|
|
|
|
this.list.toggle();
|
2017-09-10 17:25:29 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
addEvents() {
|
2017-08-17 22:00:37 +05:30
|
|
|
this.eventWrapper.clicked = this.clicked.bind(this);
|
|
|
|
this.trigger.addEventListener('click', this.eventWrapper.clicked);
|
2017-09-10 17:25:29 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
removeEvents() {
|
2017-08-17 22:00:37 +05:30
|
|
|
this.trigger.removeEventListener('click', this.eventWrapper.clicked);
|
2017-09-10 17:25:29 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
restoreInitialState() {
|
2017-08-17 22:00:37 +05:30
|
|
|
this.list.list.innerHTML = this.list.initialState;
|
2017-09-10 17:25:29 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
removePlugins() {
|
2021-03-08 18:12:59 +05:30
|
|
|
this.plugins.forEach((plugin) => plugin.destroy());
|
2017-09-10 17:25:29 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
destroy() {
|
2017-08-17 22:00:37 +05:30
|
|
|
this.restoreInitialState();
|
|
|
|
|
|
|
|
this.removeEvents();
|
|
|
|
this.removePlugins();
|
2017-09-10 17:25:29 +05:30
|
|
|
}
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
export default HookButton;
|