Search code examples
tinymce

Intercept event on changing font size


When changing fontsize with tinymce it adds a span with attribute style set to eg. 'font-size: 12pt'.

I would like to intercept that behaviour and do something totally different. I would need the chosen value but I don't want the text to change in the text field only in my visualisation on another part of the page.

Does anyone know if this is possible?


Solution

  • You can utilize the FormatApply event to track if any format was applied.

    Here is an example that will log every FormatApply event via the browser console:

        tinymce.init({
            selector: "textarea",
            setup: function(editor) {
                editor.on('FormatApply', function(element) {
                    console.log(element);
                });
            }
            
        });

    I've also created a fiddle: https://fiddle.tiny.cloud/t8iaab.