Sha256: 26149d12dbb117e28cadde761f1a1dddd404e4da1e2129d7bc00433b4d03add9

Contents?: true

Size: 1.18 KB

Versions: 18

Compression:

Stored size: 1.18 KB

Contents

//= require thredded/core/on_page_load

(() => {
  const Thredded = window.Thredded;
  const COMPONENT_SELECTOR = '.thredded--post--content--spoiler';
  const OPEN_CLASS = 'thredded--post--content--spoiler--is-open';

  Thredded.spoilers = {
    init(root) {
      Array.prototype.forEach.call(root.querySelectorAll(COMPONENT_SELECTOR), (node) => {
        node.addEventListener('mousedown', (evt) => {
          evt.stopPropagation();
          this.toggle(evt.currentTarget);
        });
        node.addEventListener('keypress', (evt) => {
          if (event.key === ' ' || event.key === 'Enter') {
            evt.preventDefault();
            evt.stopPropagation();
            this.toggle(evt.currentTarget);
          }
        });
      });
    },

    toggle(node) {
      const isOpen = node.classList.contains(OPEN_CLASS);
      node.classList.toggle(OPEN_CLASS);
      node.setAttribute('aria-expanded', isOpen ? 'false' : 'true');
      node.firstElementChild.setAttribute('aria-hidden', isOpen ? 'false' : 'true');
      node.lastElementChild.setAttribute('aria-hidden', isOpen ? 'true' : 'false');
    }
  };

  Thredded.onPageLoad(() => {
    Thredded.spoilers.init(document);
  });
})();

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
thredded-0.16.13 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.16.12 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.16.11 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.16.10 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.16.9 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.16.8 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.16.7 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.16.6 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.16.5 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.16.4 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.16.3 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.16.1 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.16.0 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.15.5 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.15.4 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.15.3 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.15.2 app/assets/javascripts/thredded/components/spoilers.es6
thredded-0.15.1 app/assets/javascripts/thredded/components/spoilers.es6