spohlenz / tinymce-rails

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

Manual tinyMCEInit() firing option #229

Closed sintro closed 6 years ago

sintro commented 6 years ago

There are option for manual initializing of tinymce, which is usefull almost always if you use turbolinks. But this option - is to fully reimplement all the tinymce initialize script, which is beautiful feature of this gem (to define tinymce configs in one place at tinymce.yml). But what about some option to view's tinymce method to disable automatic tinyMCEInit() call? So the method will define tinyMCEInit() method in body with all global configs, and the programmer will be able to call it from where he wants by calling of this method (probably it should be defined for window scope).

sintro commented 6 years ago

This way a lot of code from here https://github.com/spohlenz/tinymce-rails/issues/213 will be DRYed out.

spohlenz commented 6 years ago

I've reworked the JavaScript initialization code in the latest version which should provide some more flexibility. In particular, these changes allow multiple configurations to be easily used within the one page.

The main changes are in:

In order to disable the default TinyMCE initialization, you can manually add all of the configurations with:

<%= javascript_tag tinymce_configurations_javascript %>

and then initialize with:

TinyMCERails.initialize('default', { selector: "#myeditor", custom: "options" });
sintro commented 6 years ago

Nice! Still sad https://github.com/spohlenz/tinymce-rails/blob/master/lib/tinymce/rails/helper.rb#L38 this method (tinymce_configurations_javascript) does not allow to input options for overriding (like tinymce_configuration). So one need to bother with options passing from data attributes to javascript initializer (TinyMCERails.initialize) for options which depends on the particular rendered page.

spohlenz commented 6 years ago

I've added an options parameter to the tinymce_configurations_javascript helper in the 4.7.3 release.