Sha256: 7951b14e3ae1d8a19988a751bc909da2cdf2d558ae9ac65574eeb98f333a037b

Contents?: true

Size: 842 Bytes

Versions: 1

Compression:

Stored size: 842 Bytes

Contents

//= require simplemde.min

document.addEventListener('DOMContentLoaded', setup);
document.addEventListener('turbolinks:load', setup);

function setup() {
  initSimpleMDE(document);
  initObserver(document.querySelector('.field-unit--nested'));
}

function initSimpleMDE(element) {
  if (!element) return;

  element.querySelectorAll('[data-simplemde="false"]').forEach(function(el) {
    new SimpleMDE({ element: el });
    el.setAttribute('data-simplemde', true);
  });
}

function initObserver(element) {
  if (!element) return;

  const observer = new MutationObserver(function (mutations) {
    for (let mutation of mutations) {
      if (mutation.addedNodes.length) {
        mutation.addedNodes.forEach(function(node) {
          initSimpleMDE(node);
        });
      }
    }
  });

  observer.observe(element, { childList: true });
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
administrate-field-simple_markdown-0.3.0 app/assets/javascripts/administrate-field-simple_markdown/application.js