nicedit 輕量級(jí)編輯器 使用心得
更新時(shí)間:2009年06月11日 22:01:26 作者:
NicEdit是一個(gè)輕量級(jí),跨平臺(tái),內(nèi)置內(nèi)容編輯器,允許在瀏覽器中輕松地編輯網(wǎng)站上的內(nèi)容。
NicEdit的Javascript集成到任何網(wǎng)站在幾秒鐘內(nèi)作出的任何元素/區(qū)塊編輯或轉(zhuǎn)換標(biāo)準(zhǔn)textareas來(lái)豐富文本編輯。
How to use
http://nicedit.com/demos.php 給出了幾個(gè)demo,包括最傻瓜式的把textarea轉(zhuǎn)換成niceditor,簡(jiǎn)單配置編輯區(qū)和命令按鈕,以及不同風(fēng)格的編輯界面。
Deployment
NicEdit 可能是引用文件最少的在線編輯器,原因是不能更少了,一個(gè)js,一個(gè)圖標(biāo)文件。這兩者的目錄結(jié)構(gòu)修改配置。
new nicEditor({iconsPath : '../nicEditorIcons.gif'})
Source Code
NicEdit 的源碼是面向?qū)ο蟮模@使的本來(lái)就少至1300多行的代碼更容易閱讀,當(dāng)然還有修改。
以一個(gè)添加圖片的按鈕為例:
/* START CONFIG */
var nicImageOptions = {
buttons : {
'image' : {name : 'Add Image', type : 'nicImageButton', tags : ['IMG']}
}
};
/* END CONFIG */
var nicImageButton = nicEditorAdvancedButton.extend({
addPane : function() {
this.im = this.ne.selectedInstance.selElm().parentTag('IMG');
this.addForm({
'' : {type : 'title', txt : 'Add/Edit Image'},
'src' : {type : 'text', txt : 'URL', 'value' : 'http://', style : {width: '150px'}},
'alt' : {type : 'text', txt : 'Alt Text', style : {width: '100px'}},
'align' : {type : 'select', txt : 'Align', options : {none : 'Default','left' : 'Left', 'right' : 'Right'}}
},this.im);
},
submit : function(e) {
var src = this.inputs['src'].value;
if(src == "" || src == "http://") {
alert("You must enter a Image URL to insert");
return false;
}
this.removePane();
if(!this.im) {
var tmp = 'javascript:nicImTemp();';
this.ne.nicCommand("insertImage",tmp);
this.im = this.findElm('IMG','src',tmp);
}
if(this.im) {
this.im.setAttributes({
src : this.inputs['src'].value,
alt : this.inputs['alt'].value,
align : this.inputs['align'].value
});
}
}
});
nicEditors.registerPlugin(nicPlugin,nicImageOptions);
/* START CONFIG *//* END CONFIG */
之間是添加圖片按鈕在按鈕條上的配置,之后代碼控制是添加圖片按鈕點(diǎn)擊后浮出相應(yīng)的面板,用來(lái)接收輸入以在編輯器里插入圖片。最后一句代碼是把該按鈕注冊(cè)到按鈕條上。
事實(shí)上,你也可以完全不使用nicedit的按鈕條,而自己調(diào)用命令,即這行代碼,
ne.nicCommand("insertImage",tmp);
這里的ne對(duì)象是nicedit的編輯區(qū),它可以通過(guò)這種方式獲得
myNicEditor = new nicEditor();
myNicEditor.addInstance('editordiv');
ed = myNicEditor.nicInstances[0];
需要注意的是,你要是這么簡(jiǎn)單的調(diào)用的話,和可能是沒(méi)有任何效果的。你還需要在nicedit編輯區(qū)onblur前,比如你是在用戶點(diǎn)擊一個(gè)div的時(shí)候來(lái)插入圖片,這時(shí)你需要在這個(gè)div onmousedown的時(shí)候執(zhí)行
ed.saveRng();
來(lái)保存鍵盤在編輯器上的焦點(diǎn),并在從用戶那里得到了想要的輸入以后,比如div的onclick,或是select的onchange以后,執(zhí)行
ed.restoreRng();
以恢復(fù)焦點(diǎn),只有這樣,才能正確的位置插入圖片。
download
nicedit提供了插件機(jī)制,非常容易拓展,在http://nicedit.com/download.php 你可以根據(jù)你的功能需要,來(lái)定制一個(gè)下載。
本站下載地址
How to use
http://nicedit.com/demos.php 給出了幾個(gè)demo,包括最傻瓜式的把textarea轉(zhuǎn)換成niceditor,簡(jiǎn)單配置編輯區(qū)和命令按鈕,以及不同風(fēng)格的編輯界面。
Deployment
NicEdit 可能是引用文件最少的在線編輯器,原因是不能更少了,一個(gè)js,一個(gè)圖標(biāo)文件。這兩者的目錄結(jié)構(gòu)修改配置。
new nicEditor({iconsPath : '../nicEditorIcons.gif'})
Source Code
NicEdit 的源碼是面向?qū)ο蟮模@使的本來(lái)就少至1300多行的代碼更容易閱讀,當(dāng)然還有修改。
以一個(gè)添加圖片的按鈕為例:
/* START CONFIG */
var nicImageOptions = {
buttons : {
'image' : {name : 'Add Image', type : 'nicImageButton', tags : ['IMG']}
}
};
/* END CONFIG */
var nicImageButton = nicEditorAdvancedButton.extend({
addPane : function() {
this.im = this.ne.selectedInstance.selElm().parentTag('IMG');
this.addForm({
'' : {type : 'title', txt : 'Add/Edit Image'},
'src' : {type : 'text', txt : 'URL', 'value' : 'http://', style : {width: '150px'}},
'alt' : {type : 'text', txt : 'Alt Text', style : {width: '100px'}},
'align' : {type : 'select', txt : 'Align', options : {none : 'Default','left' : 'Left', 'right' : 'Right'}}
},this.im);
},
submit : function(e) {
var src = this.inputs['src'].value;
if(src == "" || src == "http://") {
alert("You must enter a Image URL to insert");
return false;
}
this.removePane();
if(!this.im) {
var tmp = 'javascript:nicImTemp();';
this.ne.nicCommand("insertImage",tmp);
this.im = this.findElm('IMG','src',tmp);
}
if(this.im) {
this.im.setAttributes({
src : this.inputs['src'].value,
alt : this.inputs['alt'].value,
align : this.inputs['align'].value
});
}
}
});
nicEditors.registerPlugin(nicPlugin,nicImageOptions);
/* START CONFIG *//* END CONFIG */
之間是添加圖片按鈕在按鈕條上的配置,之后代碼控制是添加圖片按鈕點(diǎn)擊后浮出相應(yīng)的面板,用來(lái)接收輸入以在編輯器里插入圖片。最后一句代碼是把該按鈕注冊(cè)到按鈕條上。
事實(shí)上,你也可以完全不使用nicedit的按鈕條,而自己調(diào)用命令,即這行代碼,
ne.nicCommand("insertImage",tmp);
這里的ne對(duì)象是nicedit的編輯區(qū),它可以通過(guò)這種方式獲得
myNicEditor = new nicEditor();
myNicEditor.addInstance('editordiv');
ed = myNicEditor.nicInstances[0];
需要注意的是,你要是這么簡(jiǎn)單的調(diào)用的話,和可能是沒(méi)有任何效果的。你還需要在nicedit編輯區(qū)onblur前,比如你是在用戶點(diǎn)擊一個(gè)div的時(shí)候來(lái)插入圖片,這時(shí)你需要在這個(gè)div onmousedown的時(shí)候執(zhí)行
ed.saveRng();
來(lái)保存鍵盤在編輯器上的焦點(diǎn),并在從用戶那里得到了想要的輸入以后,比如div的onclick,或是select的onchange以后,執(zhí)行
ed.restoreRng();
以恢復(fù)焦點(diǎn),只有這樣,才能正確的位置插入圖片。
download
nicedit提供了插件機(jī)制,非常容易拓展,在http://nicedit.com/download.php 你可以根據(jù)你的功能需要,來(lái)定制一個(gè)下載。
本站下載地址
相關(guān)文章
Ueditor百度編輯器的Html模式自動(dòng)替換樣式的解決方法
百度的Ueditor編輯器出于安全性考慮,用戶在html模式下粘貼進(jìn)去的html文檔會(huì)自動(dòng)被去除樣式和轉(zhuǎn)義。雖然安全的,但是非常不方便。做一下修改把這個(gè)功能去掉,需要的朋友可以參考下2017-03-03CKEDITOR二次開(kāi)發(fā)之插件開(kāi)發(fā)方法
CKEditor固有的一些文件被組織到_source目錄里. 核心的功能,諸如DOM元素操作,事件處理,初始化腳本和一些環(huán)境設(shè)置被包含在_source\core文件夾內(nèi). 而其它的一些功能, 比如格式化,拷貝和粘貼, 圖片和鏈接, 都被實(shí)現(xiàn)為插件形式放在_source\plugins文件夾內(nèi)2017-03-03syntaxhighlighter 去掉右上角問(wèn)號(hào)圖標(biāo)的三種方法
syntaxhighlighter可以高亮著色顯示幾乎所有語(yǔ)言形式的源代碼,還可以顯示行號(hào),是一款深受網(wǎng)站建設(shè)人員喜愛(ài)的工具,并且它還是免費(fèi)的2013-11-11