Tinymce - Is it possible to call a custom plugin function from outside the toolbar?

OK I know, maybe this question was asked before:

Here

But my question is that how can I call the plugin function from an external button, not using the toolbar.

I added custom plugins:

tinymce.PluginManager.add('example', function(e) {
        function customfunction(){
                    e.focus(true);
                    alert('Hello TinyMce');
            }
        }
);

Check it out on Fiddle

and I call it customfunctionfrom another function, which is called when I click Custom Button. Like this:

function clickme()
{
   tinymce.get('textareaid').plugins.example.customfunction();

}

Button

<button onclick="clickme()" >Custom Button</button>

But this does not work for me?

What am I doing right custom plugin functionin this way?

Am I missing something?

+4
source share
2 answers

ID . :

tinymce.PluginManager.add('example', function(e) {

        function customfunction() {
                    e.focus(true);
                    alert('Hello TinyMce');
            }


        e.addButton('testButton', {
            id: "testButton",
            text: 'Example',
            icon: false,
            onclick: function() {
                    // calls the custom function
                    customfunction();
                }
            });
    }
);

tinymce :

tinymce.init({
    selector: "textarea",
    plugins: "example",
    // show the button
    toolbar: "testButton undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});

:

function clickme()
{
   document.getElementById("testButton").click();
}

add_filter. tinymce:

<script type="text/javascript">
tinymce.PluginManager.add('example', function(e) {
        function customfunction() {
                    e.focus(true);
                    alert('Hello TinyMce');
            }


    e.addButton('testButton', {
        id: "testButton",
        text: 'Example',
        icon: false,
        onclick: function() {
                customfunction();
            }
        });
}
);

tinymce.init({
    selector: "textarea",
    plugins: "example",
    toolbar: "testButton undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
//add_filter('mce_external_plugins', 'example');
function clickme()
{
   document.getElementById("testButton").click();
}

</script>

<form method="post" action="">
    <textarea name="content" id="textareaid"></textarea>
</form>

<button onclick="clickme();" >abc</button>
+3

tinymce.PluginManager.items[0]

dom, .

0

Source: https://habr.com/ru/post/1541933/


All Articles