Hi @rossmorley ,
Apologies for the delay in my response - I’ve been away on annual leave.
I am delighted to announce that I am allowed to share my TinyMCE implementation
I have detailed everything you need to know below, to give you the power to configure this to your exact requirements.
In the near future, I will be:
- Adding documentation on this in the Community Docs detailing this setup.
- I am already preparing an enhanced TinyMCE presenter for the Community AppShare .
But for now, please see below for advise on building this editor in your Code Studio components.
1. Initialise TinyMCE
Firstly, you’ll need to ensure that your TinyMCE instance is being initialised within your code component. The below code snippet is an example where I am initialising the editor on mounted - Notice I am also setting a min-height as a config, something we’ll talk more about in this guide.
You’ll notice we firstly prepare and initialise the editor (tinymce_instance), before attaching it to an element (#editor_container) in our frontend.
mounted: function () {
let SELF = this;
// Prepare initialising the editor
let tinymce_instance = class extends mats.system_module_tinymce_utilization_formatted_text {
config() {
let config = super.config();
config.min_height = 200;
return config;
}
}
// Initialise the editor against a container
new tinymce_instance($('#editor_container'), params);
}
2. Setup your container
The next step is to ensure that the frontend has been configured correctly to load the editor instance. In my below example, notice that I am using the div id editor_container which matches the mapping in the above configuration.
Important: You must have a textarea element within your container, as this is what is replaced with TinyMCE.
<div id="editor_container">
<textarea>{{ your_variable }}</textarea>
</div>
3. Configuring parameters
Now that we have a working TinyMCE editor, we can now optionally setup the parameters of the editor. These parameters will control showing/hiding specific groups of options within the editor’s toolbar - This effectively mirrors the settings within a text formatted fragment within page builder.
In the below code snippet, I have listed all parameters that can be specified, and setting true/false to show/hide toolbar options.
mounted: function () {
let SELF = this;
let tinymce_instance = class extends mats.system_module_tinymce_utilization_formatted_text {
config() {
let config = super.config();
config.min_height = 200;
return config;
}
}
// Specifying the editor's parameters to pull from the core platform
let params = {
settings: {
show_text_formatting: true,
show_text_positioning: true,
show_links: true,
show_tables: true,
show_images: true,
show_editing_aids: true
}
}
new tinymce_instance($('#editor_container'), params);
}
4. Configuring plugins
You can also configure supported plugins for TinyMCE and utilise them within your editor - This can be really handy if you want to offer extended functionality natively within your editor, such as auto-resizing the editor or word counts.
Note: We only support HugeRTE supported plugins within this TinyMCE editor, you can find a full list of supported plugins within the official HugeRTE documentation here.
In the below example, you can see I have configured my plugins and have specified a list of 3 plugins I want to use: autoresize, link and wordcount.
mounted: function () {
let SELF = this;
let tinymce_instance = class extends mats.system_module_tinymce_utilization_formatted_text {
config() {
let config = super.config();
config.min_height = 200;
// This is where I specify my supported plugins
config.plugins = (config.plugins || '') + ' autoresize link wordcount';
return config;
}
}
let params = {
settings: {
show_text_formatting: true,
show_text_positioning: true,
show_links: true,
show_tables: true,
show_images: true,
show_editing_aids: true
}
}
new tinymce_instance($('#editor_container'), params);
}
5. Configuring toolbar
You can also configure additional items within your toolbar, which pairs really nicely with plugins. Using the example code below, you may offer wordcount as a supported plugin but will want to show an option for it in your editor’s toolbar - This is how you can achieve this.
Note: Some plugins are not supported in the toolbar as they functionally apply and are not interactive (eg. autoresize). Others may already be in the toolbar due to parameters (described later in this document)
In the below code snippet, I have specified to show wordcount in my toolbar. autoresize is a functional plugin and therefore doesn’t and won’t display on the toolbar. I’ve decided not to include the link plugin, as I already have a link option enabled in my toolbar through the use of the show_links parameter - So adding the link option in my toolbar would serve as a duplicate option in my editor.
Top Tip: If you want full control over what your toolbar offers, set all parameters to false and you can then control the toolbar through the config.
mounted: function () {
let SELF = this;
let tinymce_instance = class extends mats.system_module_tinymce_utilization_formatted_text {
config() {
let config = super.config();
config.min_height = 200;
config.plugins = (config.plugins || '') + ' autoresize link wordcount';
// This is where I configure additional items in my editor's toolbar
config.toolbar = (config.toolbar || '') + ' wordcount';
return config;
}
}
let params = {
settings: {
show_text_formatting: true,
show_text_positioning: true,
show_links: true,
show_tables: true,
show_images: true,
show_editing_aids: true
}
}
new tinymce_instance($('#editor_container'), params);
}
Voila! You should now have a working TinyMCE instance. If you have any questions, or trouble setting this up, please do not hesitate to reach out.
Hope this helps 