最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Add a custom dropdownbutton to Redactor WYSIWYG - Stack Overflow

programmeradmin4浏览0评论

I have two questions:

  1. I'm trying to had a button like this :

    buttons: buttons,
    buttonsCustom: {
      sh: {
        title: 'Syntax Highlighter', 
        callback: function(){
          var html = "<pre class='brush:'></pre>";
          this.execCommand('inserthtml', html);
        }
      }
    }
    

    My button appears but when i click on it, it say that "this" hasn't an "execCommand" function. How does it work ? How can i say that "this" is Redactor ? You know what i mean ?

  2. Is it possible to create a dropdown list ?

I have two questions:

  1. I'm trying to had a button like this :

    buttons: buttons,
    buttonsCustom: {
      sh: {
        title: 'Syntax Highlighter', 
        callback: function(){
          var html = "<pre class='brush:'></pre>";
          this.execCommand('inserthtml', html);
        }
      }
    }
    

    My button appears but when i click on it, it say that "this" hasn't an "execCommand" function. How does it work ? How can i say that "this" is Redactor ? You know what i mean ?

  2. Is it possible to create a dropdown list ?

Share Improve this question edited Nov 23, 2012 at 16:53 user229044 240k41 gold badges344 silver badges346 bronze badges asked Nov 23, 2012 at 16:42 JulienITARDJulienITARD 1372 silver badges10 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

I wanted to add a custom button like in redactor. I took your code and i changed the code for my purpose. It works for me you can take a look :

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

I fixed it by myself:

callback: function(obj){
  var html = "<pre class='brush:'></pre>";
  obj.execCommand('inserthtml', html);
}

Looking at the redactor source (latest version 8.2.6) I noticed that you can pass a fourth parameter to the plugin API's addBtn function to describe a dropdown. So, say you want to add a Font Size dropdown menu from inside a plugin:

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

}
发布评论

评论列表(0)

  1. 暂无评论