#TinyMCE (v12) - Extend the init/setup

1 messages · Page 1 of 1 (latest)

static juniper
#

Is it possible to extend the TinyMce setup/initialisation? I need to make a change to enhance the behaviour of a couple of features, e.g. apply a specific class to elements when Justify-Left or Justify-Right are selected from the formatting toolbar.

tinymce.init({
    setup: function(editor) {
        editor.on('ExecCommand', function(e) {
            var selectedNode = editor.selection.getNode(); // Get the currently selected node
            if (e.command === 'JustifyLeft' || e.command === 'JustifyRight') {
                // Remove any previously added alignment classes
                editor.dom.removeClass(selectedNode, 'custom-justify-left custom-justify-right');
                // Check command and add the appropriate class
                if (e.command === 'JustifyLeft') {
                    editor.dom.addClass(selectedNode, 'custom-justify-left');
                } else if (e.command === 'JustifyRight') {
                    editor.dom.addClass(selectedNode, 'custom-justify-right');
                }
            }
        });
    }
});

Is this achievable somehow?

stark cloak
#
"RichTextEditor": {
  "Plugins": [ "visualblocks" ],
  "Commands": [
    {
      "Alias": "visualblocks",
      "Name": "Visual Blocks",
      "Mode": "Insert"
    }
  ],
  "CustomConfig": {
    "statusbar": "true",
    "branding": "false",
    "resize": "true",
    "formats": "{\"underline\": {\"selector\": \"p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li\",\"classes\": \"text-decoration-underline\"},\"alignleft\": {\"selector\": \"p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img,audio,video\",\"classes\": \"text-start\"},\"alignright\": {\"selector\": \"p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img,audio,video\",\"classes\": \"text-end\"},\"aligncenter\": {\"selector\": \"p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img,audio,video\",\"classes\": \"text-center\"},\"alignjustify\": {\"selector\": \"p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img,audio,video\",\"classes\": \"text-justify\"}}" //https://www.tiny.cloud/docs/tinymce/6/filter-content/#built-in-formats
  }
}
static juniper
static juniper
# static juniper Is it possible to extend the TinyMce setup/initialisation? I need to make a chan...

For anyone else that might be interested there is a great blog post here demonstrating a method of making the settings easier to manage without all the manual escaping required for the appsettings. - Thanks @maiden kelp for the inspiration!

stark cloak