Javascript 向Redactor WYSIWYG添加自定义下拉/按钮

Javascript 向Redactor WYSIWYG添加自定义下拉/按钮,javascript,jquery,wysiwyg,redactor,Javascript,Jquery,Wysiwyg,Redactor,我有两个问题: 我试着用这样一个按钮: buttons: buttons, buttonsCustom: { sh: { title: 'Syntax Highlighter', callback: function(){ var html = "<pre class='brush:'></pre>"; this.execCommand('inserthtml', html); } } } 按钮:按钮, 按钮自定

我有两个问题:

  • 我试着用这样一个按钮:

    buttons: buttons,
    buttonsCustom: {
      sh: {
        title: 'Syntax Highlighter', 
        callback: function(){
          var html = "<pre class='brush:'></pre>";
          this.execCommand('inserthtml', html);
        }
      }
    }
    
    按钮:按钮,
    按钮自定义:{
    上海:{
    标题:“语法高亮显示”,
    回调:函数(){
    var html=“”;
    这个.execCommand('inserthtml',html);
    }
    }
    }
    
    我的按钮出现了,但当我点击它时,它说“this”没有“execCommand”功能。它是如何工作的?我怎么能说“这”是编辑? 你知道我的意思吗

  • 可以创建一个下拉列表吗

  • 我自己修好的:

    callback: function(obj){
      var html = "<pre class='brush:'></pre>";
      obj.execCommand('inserthtml', html);
    }
    
    回调:函数(obj){
    var html=“”;
    obj.execCommand('inserthtml',html);
    }
    
    我自己修好了:

    callback: function(obj){
      var html = "<pre class='brush:'></pre>";
      obj.execCommand('inserthtml', html);
    }
    
    回调:函数(obj){
    var html=“”;
    obj.execCommand('inserthtml',html);
    }
    
    我想添加一个像redactor中那样的自定义按钮。我拿走了你的密码,为了我的目的我修改了密码。这对我很有用你可以看看:

    $(document).ready(
        function()
        {
            $('.redactor').redactor({ 
                focus: true,
                buttonsAdd: ['|', 'token'], 
                buttonsCustom: {
                    token: {
                        title: 'Ajouter une variable', 
                        dropdown: {
                            header: {title: 'Entête',callback: function(obj){obj.insertHtml('%header%');}},
                            footer: {title: 'Signature',callback: function(obj){obj.insertHtml('%footer%');}},
                            last_name: {title: 'Nom',callback: function(obj){obj.insertHtml('%last_name%');}},
                            first_name: {title: 'Prénom',callback: function(obj){obj.insertHtml('%first_name%');}},
                            date: {title: 'Date',callback: function(obj){obj.insertHtml('%date%');}},
                            contract: {title: 'Contrat',callback: function(obj){obj.insertHtml('%contract%');}}
                        }
                    } 
                }
            }); 
        }
    );
    

    干杯

    我想添加一个像redactor中那样的自定义按钮。我拿走了你的密码,为了我的目的我修改了密码。这对我很有用你可以看看:

    $(document).ready(
        function()
        {
            $('.redactor').redactor({ 
                focus: true,
                buttonsAdd: ['|', 'token'], 
                buttonsCustom: {
                    token: {
                        title: 'Ajouter une variable', 
                        dropdown: {
                            header: {title: 'Entête',callback: function(obj){obj.insertHtml('%header%');}},
                            footer: {title: 'Signature',callback: function(obj){obj.insertHtml('%footer%');}},
                            last_name: {title: 'Nom',callback: function(obj){obj.insertHtml('%last_name%');}},
                            first_name: {title: 'Prénom',callback: function(obj){obj.insertHtml('%first_name%');}},
                            date: {title: 'Date',callback: function(obj){obj.insertHtml('%date%');}},
                            contract: {title: 'Contrat',callback: function(obj){obj.insertHtml('%contract%');}}
                        }
                    } 
                }
            }); 
        }
    );
    

    Cheers

    查看redactor源代码(最新版本8.2.6),我注意到您可以向插件API的
    addBtn
    函数传递第四个参数来描述下拉列表。因此,假设您想在插件中添加字体大小下拉菜单:

    RedactorPlugins.fontSize = {
    
        init: function(obj) {
    
            btnCallback = function(obj,event,key) {
                // button actions, if any
            }
    
            dropdown = {
                small: {
                    title: 'Small'
                    callback: function(obj,event,key) { //set the font size to small }
                }
                medium: {
                    title: 'Medium'
                    callback: function(obj,event,key) { //set the font size to medium }
                }
            }
    
            this.addBtn('fontSize','Change font size', btnCallback, dropdown);
        }
    
    }
    

    查看redactor源代码(最新版本8.2.6),我注意到您可以向插件API的
    addBtn
    函数传递第四个参数来描述下拉列表。因此,假设您想在插件中添加字体大小下拉菜单:

    RedactorPlugins.fontSize = {
    
        init: function(obj) {
    
            btnCallback = function(obj,event,key) {
                // button actions, if any
            }
    
            dropdown = {
                small: {
                    title: 'Small'
                    callback: function(obj,event,key) { //set the font size to small }
                }
                medium: {
                    title: 'Medium'
                    callback: function(obj,event,key) { //set the font size to medium }
                }
            }
    
            this.addBtn('fontSize','Change font size', btnCallback, dropdown);
        }
    
    }