2017-06-30 17:42:12 -04:00
|
|
|
export default class VisibilitySelect {
|
2017-07-05 13:20:41 -04:00
|
|
|
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');
|
|
|
|
}
|
2016-11-22 12:16:30 -05:00
|
|
|
|
2017-07-05 13:20:41 -04:00
|
|
|
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;
|
2016-11-21 21:09:56 -05:00
|
|
|
}
|
2017-07-05 13:20:41 -04:00
|
|
|
}
|
2016-11-21 21:09:56 -05:00
|
|
|
|
2017-07-05 13:20:41 -04:00
|
|
|
updateHelpText() {
|
|
|
|
this.helpBlock.textContent = this.select.querySelector('option:checked').dataset.description;
|
2016-11-21 21:09:56 -05:00
|
|
|
}
|
2017-07-05 13:20:41 -04:00
|
|
|
}
|