ckeditor插件開發(fā)簡單實例
CKeditor就是FCKeditor,在發(fā)布一個新版本的時候,把自己的名字都改了,不要"F"。
需求:我需要在編輯文本的時候,選擇一段文字,點擊自定義的按鈕,就能夠在這段文字后面增加一個圖標,圖標超鏈接去一個地址,以選中的文字作為參數(shù)。
做法:
1、在CKeditor的plugins文件夾下,創(chuàng)建新文件夾"addmap",這個名字可以自定義,這個名字是我項目中用的名字
2、在addmap文件夾下,放一張gif圖片"map.gif",用來作圖標用的。
3、在addmap文件夾下,新建"plugin.js",編輯這個js文件,我們這里的代碼是:
(function() {
//Section 1 : 按下自定義按鈕時執(zhí)行的代碼
var a = {
exec: function(editor) {
var data="";
var mySelection = editor.getSelection();
if (CKEDITOR.env.ie) {
mySelection.unlock(true);
data = mySelection.getNative().createRange().text;
} else {
data = mySelection.getNative();
}
if(data!=null&&data!=''){
editor.insertHtml(data+'<a href="/map_index.html?ad='+data+'"><img border="0" height="24" src="/images/map_icon.gif" width="24" /></a>');
}
}
},
b = 'addmap';
CKEDITOR.plugins.add(b, {
init: function(editor) {
editor.addCommand(b, a);
editor.ui.addButton('addmap', {
label: 'add map link',
icon: this.path + 'map.gif',
command: b
});
}
});
})();
4、回到CKeditor的根目錄,編輯config.js
CKEDITOR.editorConfig = function( config )
{
// Define changes to default configuration here. For example:
config.language = 'zh-cn';
//config.uiColor = '#AADC6E';
//字體.
config.font_names = '宋體;楷體_GB2312;新宋體;黑體;隸書;幼圓;微軟雅黑;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana;';
//工具按鈕
config.toolbar=
[
['Source','-','Preview'],
['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print','Link','Unlink','Anchor'],
['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
['addmap']
];
config.extraPlugins = 'addmap';
5、測試
相關文章
常用網(wǎng)頁編輯器漏洞手冊(全面版)fckeditor,ewebeditor
常用網(wǎng)頁編輯器漏洞手冊(全面版)fckeditor,ewebeditor,使用這類編輯器的朋友一定要注意下。2011-04-04輕松實現(xiàn) CKfinder進駐CKEditor3.0
看完YaSin寫得“將CKfinder 整合進 CKEditor3.0 ”之后,我總覺得問題有點復雜,尤其是修改壓縮了的js文件。2010-01-01ckeditor syntaxhighlighter代碼高亮插件配置分享
現(xiàn)在大家可以不必像我這樣為了實現(xiàn)代碼高亮的功能,去修改ckeditor編輯器,大家可以去使用百度編輯器(Ueditor)他有代碼高亮的功能,還蠻好用的,我的個人網(wǎng)站就是的百度編輯器的。歡迎大家去我的博客看看2014-12-12