BigW Consortium Gitlab

visibility_select.js 841 Bytes
Newer Older
1
(() => {
Luke "Jared" Bennett committed
2
  const gl = window.gl || (window.gl = {});
3 4

  class VisibilitySelect {
Luke "Jared" Bennett committed
5 6 7 8 9 10 11 12
    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');
    }

    init() {
13
      if (this.select) {
Luke "Jared" Bennett committed
14 15
        this.updateHelpText();
        this.select.addEventListener('change', this.updateHelpText.bind(this));
16
      } else {
Luke "Jared" Bennett committed
17
        this.helpBlock.textContent = this.container.querySelector('.js-locked').dataset.helpBlock;
18 19 20
      }
    }

Luke "Jared" Bennett committed
21 22
    updateHelpText() {
      this.helpBlock.textContent = this.select.querySelector('option:checked').dataset.description;
23 24 25
    }
  }

Luke "Jared" Bennett committed
26
  gl.VisibilitySelect = VisibilitySelect;
27
})();