【问题标题】:NicEditor font size mody from <font size='1'> tag to <span style='font-size: 8px'>NicEditor 字体大小从 <font size='1'> 标签修改为 <span style='font-size: 8px'>
【发布时间】:2012-05-20 15:11:31
【问题描述】:

您好,我正在使用 NicEditor,我希望字体大小以不同的方式工作。现在编辑器使用:

&lt;font size='1...7'&gt;the selected text here&lt;/font&gt;

我不想让它成为一个跨度标签,即

&lt;span style='font-size:30px'&gt;the selected text here&lt;/span&gt;

这是下拉菜单的代码:

var nicEditorFontSizeSelect = nicEditorSelect.extend({
    sel : {1 : '1&nbsp;(8pt)', 2 : '2&nbsp;(10pt)', 3 : '3&nbsp;(12pt)', 4 : '4&nbsp;(14pt)', 5 : '5&nbsp;(18pt)', 6 : '6&nbsp;(24pt)', 7 : '7&nbsp;(36pt)', 8 : '8&nbsp;(48pt)', 9 : '9&nbsp;(72pt)', 10 : '10&nbsp;90pt)', 11 : '11&nbsp;(100pt)'},
    init : function() {
        this.setDisplay('Font&nbsp;Size...');
        for(itm in this.sel) {
            this.add(itm,'<font size="'+itm+'">'+this.sel[itm]+'</font>');
        }       
    }
});

但我找不到要修改的代码,以便它将font 替换为文本区域内的span 标记。

非常欢迎任何建议。

谢谢

【问题讨论】:

    标签: javascript textbox text-editor nicedit rich-text-editor


    【解决方案1】:

    知道这是一个老问题,但如果其他人需要这里的答案。

    请注意,这是非常基本的,可以进行改进,例如它会创建嵌套的 's。

    不管怎样,在你初始化你的nicEditor之前添加这个JS代码,创建一个自定义插件:

    var nicSelectOptionsCustomFormat = {
        buttons : {
            'fontCustomSize' : {name : __('Font size'), type : 'nicEditorCustomFormatSelect'}
        }
    };
    var nicEditorCustomFormatSelect = nicEditorSelect.extend({
        sel : {'11px' : '11px', '13px' : '13px', '15px' : '15px', '19px' : '19px', '22px' : '22px'},
    
        init : function() {
            this.setDisplay('Font size');
            for(itm in this.sel) {
                this.add(itm,'<span style="size:'+itm+'">'+this.sel[itm]+'</span>');
            }
        }
    
        ,update : function(elm) {
            var newNode = document.createElement('span');
            newNode.style.fontSize = elm;
            var rng = this.ne.selectedInstance.getRng().surroundContents(newNode);
            this.close();
        }
    });
    nicEditors.registerPlugin(nicPlugin,nicSelectOptionsCustomFormat);
    

    然后在创建编辑器时使用fontCustomSize,例如:

    var config = {
        buttonList: ["bold", "italic", "underline","fontCustomSize"]
    };
    var e = new nicEditor(config);
    e.panelInstance("page-description");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-25
      • 2023-03-30
      • 2013-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多