spohlenz / tinymce-rails

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

Configuring init_instance_callback does not work with string or arrow function #291

Closed ronald closed 1 year ago

ronald commented 1 year ago

Thanks for providing this plugin :smile:

I've question / bug report.

my config looks like this:

default:
  init_instance_callback: "tinymce_after_init"

tinymce-rails generates this:

TinyMCERails.configuration.default = {
  selector: "textarea.tinymce",
  cache_suffix: "?v=6.2.0",
  init_instance_callback: "tinymce_after_init"
};
TinyMCERails.initialize('default', {

});

The callback does not work as it is passed as string to TinyMCE.

Is there any other way to pass the callback?

Thx

spohlenz commented 1 year ago

Try setting init_instance_callback to a string beginning with "function(". The configuration should detect this and output it as a function rather than a string.

e.g.

default:
  init_instance_callback: "function() { tinymce_after_init(); }"
ronald commented 1 year ago
default:
  init_instance_callback: "function(editor) { tinymce_after_init(editor); }"

This works. Thank you.

Is this documented somewhere or should i update README via PR?

I already tried this before

default:
  init_instance_callback: "(editor) => tinymce_after_init(editor)"

but Arrow function expression does not seem to be supported.

Does it make sense to support that as well?

spohlenz commented 1 year ago

Support for arrow functions has been added in 6363612.