Sha256: 82ca9723fca2301732af37859cfe08041526c33b220a3b5824898fe4cb8ccd77

Contents?: true

Size: 1.25 KB

Versions: 6

Compression:

Stored size: 1.25 KB

Contents

//= require thredded/core/thredded
//= require thredded/dependencies/autosize
//= require thredded/core/on_page_load
//= require thredded/components/mention_autocompletion
//= require thredded/components/preview_area

(() => {
  const Thredded = window.Thredded;
  const ThreddedMentionAutocompletion = window.ThreddedMentionAutocompletion;
  const ThreddedPreviewArea = window.ThreddedPreviewArea;
  const autosize = window.autosize;

  const COMPONENT_SELECTOR = '[data-thredded-post-form]';
  const CONTENT_TEXTAREA_SELECTOR = 'textarea[name$="[content]"]';

  const initPostForm = (form) => {
    const textarea = form.querySelector(CONTENT_TEXTAREA_SELECTOR);
    autosize(textarea);
    new ThreddedPreviewArea(form, textarea);
    ThreddedMentionAutocompletion.init(form, textarea);
  };

  const destroyPostForm = (form) => {
    autosize.destroy(form.querySelector(CONTENT_TEXTAREA_SELECTOR));
  };

  Thredded.onPageLoad(() => {
    Array.prototype.forEach.call(document.querySelectorAll(COMPONENT_SELECTOR), (node) => {
      initPostForm(node);
    });
  });

  document.addEventListener('turbolinks:before-cache', () => {
    Array.prototype.forEach.call(document.querySelectorAll(COMPONENT_SELECTOR), (node) => {
      destroyPostForm(node);
    });
  });
})();

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
thredded-1.1.0 app/assets/javascripts/thredded/components/post_form.es6
thredded-1.0.1 app/assets/javascripts/thredded/components/post_form.es6
thredded-1.0.0 app/assets/javascripts/thredded/components/post_form.es6
thredded-0.16.16 app/assets/javascripts/thredded/components/post_form.es6
thredded-0.16.15 app/assets/javascripts/thredded/components/post_form.es6
thredded-0.16.14 app/assets/javascripts/thredded/components/post_form.es6