2012-02-18 68 views
2

使用CKeditor我想提供一種簡單的方法來從組合框或類似內容插入少量的html代碼。這是可能的W/O插件還是有一個現有的插件?ckeditor插件的代碼snipplets?

例如:

Toolbar:[ ][ ] [comboBox] 
       |article image   | => (inserts <img src="aimage/{{id}}"/> 
       |full-width-2col-table | => (inserts <table width="100%"><tr>.. 

({{ID}}將通過AJAX代替但這是另一個故事...)

問候,

回答

1

我工作的一個類似的問題,只是幾天前,所以我剝去了我製作的一個插件。

在CK插件目錄中創建一個名爲「myinsert」的文件夾。創建一個名爲plugin.js及以下內容粘貼到它:

CKEDITOR.plugins.add('myinsert', 
{ 
init: function(editor) 
{ 
    editor.addCommand('insertMycode', 
     { 
      exec : function(editor) 
      {  
       var timestamp = new Date(); 
       editor.insertHtml('Some Code Here.'); 
      } 
     }); 


    editor.ui.addButton('Mycode', 
    { 
     label: 'Insert Timestamp', 
     command: 'insertMycode', 
     icon: this.path + 'tag.gif' 
    }); 
} 
}); 

您必須包括在該目錄中的圖標,否則按鈕將無法正確顯示。

接下來,在你的腳本調用你的編輯器,把這個:extraPlugins : 'myinsert', 例如:

<script type="text/javascript"> 
CKEDITOR.replace('editor1', { 
    extraPlugins : 'myinsert', 
    toolbar : 'EditPost', 
    uiColor : '#BBB', 
}); 
</script> 

然後,只需添加函數名稱到工具欄設置,可以是任何地方。

{ name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About', 'Mycode' ] } 

如果您重命名函數或文件夾,請確保它們必須是相同的名稱。另外,你放在工具欄上的名字必須與editor.ui.addButton()

+0

中的名字相符。十分感謝! – Teson 2012-02-21 07:43:40