我工作的一個類似的問題,只是幾天前,所以我剝去了我製作的一個插件。
在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()
中的名字相符。十分感謝! – Teson 2012-02-21 07:43:40