在tinyMCE插件中按下按钮 [英] Catch pressing button in plugin for tinyMCE

查看:183
本文介绍了在tinyMCE插件中按下按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想捕捉某些按钮被按下的事件. 在 TinyMCE捕获单击按钮事件中,建议了一种简单的解决方法,但对于对我来说,它不起作用.能否请你帮忙.这是我在editor_plugin_src.js和editor_plugin.js文件中的tinymce/plugins/test文件夹中的代码:

I want to catch the event of some button was pressed. In TinyMCE capture click button event was suggested simple solution of how to do it, but for me it does not work. Could you please help. Here is my code in tinymce/plugins/test folder in editor_plugin_src.js and editor_plugin.js files:

(function(){
tinymce.create("tinymce.plugins.testPlugin",{
    init:function(ed,url){
        ed.addCommand('my_bold', this.my_bold, this); //calls the function my_bold
        ed.onInit.add(function(editor) {
            if (editor.controlManager.get('bold')){
                editor.controlManager.get('bold').settings.cmd='my_bold_action'; 
            };

        });
    },
    my_bold: function() {           
        // exectution of regular command
        this.editor.execCommand('Bold');

        // now do whatever you like here
        alert('pressed');
    },
    createControl:function(b,a){
        return null
    },
    getInfo:function(){
        return{
            longname:"test plugin",
            author:"test author",
            authorurl:"http://tinymce.moxiecode.com",
            infourl:"http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/example",
            version:"1.0"
        }
    }
});
tinymce.PluginManager.add("test",tinymce.plugins.TestPlugin)     })();

我在这里激活插件测试:

Here I activate plugin test:

    $(this).tinymce({
        ...
        autoresize_bottom_margin : 15,
        mode : 'exact',
        elements : clickedId,           
        theme : 'advanced',
        plugins : 'autoresize,test',
        force_br_newlines : true,

更新:

(function(){
tinymce.PluginManager.requireLangPack("test");
tinymce.create("tinymce.plugins.test",{
    init:function(ed,url){
        ed.addCommand('my_bold', this.my_bold, this);//calls the function my_bold
        ed.onInit.add(function(editor) {
            if (editor.controlManager.get('bold')){
                editor.controlManager.get('bold').settings.cmd='my_bold'; 
            }
        });
    },
    my_bold: function() {           
        // exectution of regular command
        this.editor.execCommand('Bold');

        // now do whatever you like here
        alert('pressed');
    },
    createControl:function(ed,url){
        return null
    },
    getInfo:function(){
        return{
           longname:"test plugin",
           author:"test author",
           authorurl:"http://tinymce.moxiecode.com",
           infourl:"http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/example",
           version:"1.0"
        }
    }
});
tinymce.PluginManager.add("test",tinymce.plugins.test)    })();

现在我有这个.

推荐答案

您是否已将粗体按钮添加到按钮配置中? 像这样:

Have you added the bold button to your button config? Something like:

theme_advanced_buttons1: "bold,italic,underline";

更新:

editor.controlManager.get('bold').settings.cmd='my_bold_action';

是错误的,您需要:

editor.controlManager.get('bold').settings.cmd='my_bold';

这里.

这篇关于在tinyMCE插件中按下按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆