FleetCart/Modules/Slider/Resources/assets/admin/js/Slide.js
2023-06-11 13:14:03 +01:00

42 lines
1.1 KiB
JavaScript

export default class {
constructor(data) {
this.slidePanelHtml = this.getSlidePanelHtml(data);
}
getSlidePanelHtml(data) {
data.slide.options = data.slide.options || this.getDefaultOptions();
let template = _.template($('#slide-template').html());
return $(template(data));
}
getDefaultOptions() {
return { caption_1: {}, caption_2: {}, direction: 'left', call_to_action: {} };
}
render() {
this.attachEventListeners();
this.showSelectedOptionBlock();
return this.slidePanelHtml;
}
attachEventListeners() {
this.slidePanelHtml.find('.delete-slide').on('click', () => {
this.slidePanelHtml.remove();
});
this.slidePanelHtml.find('.change-option-block').on('change', (e) => {
this.slidePanelHtml.find('.slide-options').hide();
this.slidePanelHtml.find(`.${e.currentTarget.value}`).show();
});
}
showSelectedOptionBlock() {
setTimeout(() => {
this.slidePanelHtml.find('.change-option-block').trigger('change');
});
}
}