如何更改编辑器中的格式菜单选项



默认情况下,在格式菜单下(当按钮被点击时),有这些选项:

Normal Text
Quote
Code 
Header 1
Header ...
Header 5

我希望只有这些选项:

Normal Text
Quote
Code

有办法吗?

奥利瓦斯的回答是错误的。

您可以通过以下操作轻松实现此目标:

$('#redactor').redactor({
    formattingTags: ['p', 'blockquote', 'pre']
});

演示:http://jsfiddle.net/EkM4A/

遗憾的是,实现这一点的唯一方法是在初始化之前装饰您的编辑器实例并覆盖编辑器中的默认工具栏设置。

您可以在这里看到一个工作POC: http://jsfiddle.net/Zmetser/7m3f9/

和下面的代码:

$(function() {
    // Decorate redactor Object before init
    $.Redactor.fn = (function () {
        var toolbarInitOriginal = this.toolbarInit;
        // Create a new toolbarInit method which suits our needs
        this.toolbarInit = function (lang) {
            // Grab the default toolbar...
            var toolbar = toolbarInitOriginal(lang);
            // ...and overwrite the formatting dropdown menu
            toolbar.formatting.dropdown = {
                p: {
                    title: lang.paragraph,
                    func: 'formatBlocks'
                },
                blockquote: {
                    title: lang.quote,
                    func: 'formatQuote',
                    className: 'redactor_format_blockquote'
                },
                pre: {
                    title: lang.code,
                    func: 'formatBlocks',
                    className: 'redactor_format_pre'
                },
            };
            return toolbar;
        };
        return this;
    }.call($.Redactor.fn));
    // Init redactor
    $('#redactor').redactor({
        buttons: ['link', 'formatting', 'html']
    });
});

最新更新