spohlenz / tinymce-rails

Integration of TinyMCE with the Rails asset pipeline
Other
812 stars 256 forks source link

Allow to call helper methods with the module as a receiver. #185

Closed heaven closed 8 years ago

heaven commented 8 years ago

This is sometimes useful. For example my use case was while integrating with rails_admin. Had to define rails_admin/custom/ui.js.erb:

$(document).ready(function() {
  function load_tinymce() {
    <%= TinyMCE::Rails::Helper.tinymce_javascript(:rails_admin) %>
  }

  load_tinymce();
  $(document).on('pjax:complete', load_tinymce);
});
spohlenz commented 8 years ago

Great idea, thank you.

heaven commented 8 years ago

Btw, for those who look how to add tinymce to rails admin, here's an example of my tinymce.js.erb:

$(document).ready(function() {
  function load_tinymce() {
    <%= TinyMCE::Rails::Helper.tinymce_javascript(:default, :content_css => asset_path("tinymce/contents.css")) %>
  }

  function unload_tinymce(evt) {
    var $container = $(evt.target);

    $container.find("textarea.tinymce").each(function(i, element) {
      var editor = tinyMCE.editors.find(function(editor) { return editor.targetElm === element });

      editor && editor.destroy();
    });
  }

  $("body").on("pjax:start", unload_tinymce)
  $(document).on('pjax:complete nested:fieldAdded', load_tinymce);
  load_tinymce();
});
Faq commented 2 years ago

@heaven this code for you still working? For me with rails 6.0 and tinymce-rails 4.6.4, the "tinymce/contents.css" was not loaded. Had to define it in tinymce.yml file like: content_css: 'tinymce/contents.css'