2012-05-12 23 views
2

您好我正在使用NicEditor,我希望字體大小以不同的方式工作。 RightNow公司的編輯器使用:NicEditor字體大小從<font size ='1'>標記到<span style ='font-size:8px'>

<font size='1...7'>the selected text here</font>

我wan't它成爲一個span標籤即

<span style='font-size:30px'>the selected text here</span>

這裏是下拉代碼:

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中的標記在textarea旁邊。

任何建議都非常歡迎。

謝謝

回答

4

知道這是一個老問題,但應該誰都需要這裏的答案是。

注意這是非常基本的,可以改進,例如它會創建嵌套的。

不管怎樣,添加此JS代碼你初始化你nicEditor之前,創建一個自定義插件:

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"); 
相關問題