$(document).ready(function() {
  // setup html editor
  var imgUploadHtml = $('#html-editor-image-upload-tab').html();

  if (imgUploadHtml) {
    var options = {
        "html": true,
      customTemplates: {
        image: function(locale) {
          return imgUploadHtml;
        }
      }
    };
    $('textarea.html-editor').wysihtml5(options);
  } else {
    $("textarea.html-editor").each(function(){$(this).wysihtml5();});
  }
});

$(document).ready(function() {
  // setup html editor
  var imgUploadHtml = $('#html-editor-image-upload-tab').html();
  var handler;

  if (imgUploadHtml) {
    var options = {
        "html": true,
      customTemplates: {
        image: function(locale) {
          return imgUploadHtml;
        }
      }
    };
    handler = function() { $(this).wysihtml5(options); };
  } else {
    handler = function() { $(this).wysihtml5(); };
  }
  $('textarea.html-editor').each(handler);
  $(document).on('DOMNodeInserted', function(e) {
      $('textarea.html-editor', e.target).each(handler);
  })
});

Make the HTML Editor component monitor every node insertion for HTML WYSIWYG widgets. This is so that we can insert new editors at runtime and they will automatically be enabled.
Make the HTML Editor component monitor every node insertion for HTML WYSIWYG widgets. This is so that we can insert new editors at runtime and they will automatically be enabled.
