2017-09-10 17:25:29 +05:30
|
|
|
export default class VisibilitySelect {
|
|
|
|
constructor(container) {
|
|
|
|
if (!container) throw new Error('VisibilitySelect requires a container element as argument 1');
|
|
|
|
this.container = container;
|
|
|
|
this.helpBlock = this.container.querySelector('.help-block');
|
|
|
|
this.select = this.container.querySelector('select');
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
init() {
|
|
|
|
if (this.select) {
|
|
|
|
this.updateHelpText();
|
|
|
|
this.select.addEventListener('change', this.updateHelpText.bind(this));
|
|
|
|
} else {
|
|
|
|
this.helpBlock.textContent = this.container.querySelector('.js-locked').dataset.helpBlock;
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
updateHelpText() {
|
|
|
|
this.helpBlock.textContent = this.select.querySelector('option:checked').dataset.description;
|
|
|
|
}
|
|
|
|
}
|