javascript - tinymce - Is it possible to call a custom plugin function from outside the toolbar? - Stack Overflow

OK. i know may be this question has been asked before :HereBut my question is that how can i call a plu

OK. i know may be this question has been asked before :

Here

But my question is that how can i call a plugin function from outside button not from toolbar button.

I have added a custom plugins:

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

Check this on Fiddle

and i am calling this customfunction from other function which is called when i click on Custom Button. Like this:

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

}

Button:

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

But it is not working for me?

Am i doing right thing by calling custom plugin function with that way?

Am i missing anything?

OK. i know may be this question has been asked before :

Here

But my question is that how can i call a plugin function from outside button not from toolbar button.

I have added a custom plugins:

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

Check this on Fiddle

and i am calling this customfunction from other function which is called when i click on Custom Button. Like this:

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

}

Button:

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

But it is not working for me?

Am i doing right thing by calling custom plugin function with that way?

Am i missing anything?

Share Improve this question edited May 23, 2017 at 12:17 CommunityBot 11 silver badge asked May 25, 2014 at 9:57 Shail ParasShail Paras 1,1632 gold badges14 silver badges35 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

One possibility would be to add a button with a unique ID to the toolbar and call the click event of the button. The plugin would look like this:

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();
                }
            });
    }
);

Then initialise the tinymce editor like this:

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"
});

Finally call the button click event:

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

Don't use the add_filter. The plete code form your tinymce fiddle:

<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>

your function is stored in

tinymce.PluginManager.items[0]

inspecting the dom you can see that function. try to alert it

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745331551a4622901.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信