Sha256: a84394290346d1d34b8ee00d610c59f1cc4ce1478bb57ed8eb1075c4472a2b51

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

window.onload = function() {
  initQuillEditors();
}

$(document).on('has_many_add:after', function() {
  initQuillEditors();
});

var initQuillEditors = function() {
  var editors = document.querySelectorAll('.quill-editor');
  var default_options = {
    modules: {
      toolbar: [
        ['bold', 'italic', 'underline'],
        ['link', 'blockquote', 'code-block'],
        [{ 'script': 'sub'}, { 'script': 'super' }],
        [{ 'align': [] }, { list: 'ordered' }, { list: 'bullet' }],
        [{ 'color': [] }, { 'background': [] }],
        ['clean'],
      ]
    },
    placeholder: '',
    theme: 'snow'
  };

  for(var i = 0; i < editors.length; i++) {
    var content = editors[i].querySelector('.quill-editor-content');
    var isActive = editors[i].classList.contains('quill-editor--active');
    if(content && !isActive) {
      var options = editors[i].getAttribute('data-options') ? JSON.parse(editors[i].getAttribute('data-options')) : default_options;
      editors[i]['_quill-editor'] = new Quill(content, options);
      editors[i].classList += ' quill-editor--active';
    }
  }

  var formtastic = document.querySelector('form.formtastic');
  if(formtastic) {
    formtastic.onsubmit = function() {
      for(var i = 0; i < editors.length; i++) {
        var input = editors[i].querySelector('input[type="hidden"]');
        input.value = editors[i]['_quill-editor'].root.innerHTML;
      }
    };
  }
};

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activeadmin_quill_editor-0.2.0 app/assets/javascripts/activeadmin/quill_editor_input.js