当前位置: 首页 > 图文教程 > 网络编程 > 网页编辑器 > nicedit 轻量级编辑器 使用心得

网页编辑器
让 FCKeditor 支持多用户Web环境(以PHP为例)
Ewebeditor 文件上传问题
PHP网页 Ewebeditor 编辑器嵌入方法
FckEditor 上传图片后图片变小了!问题解决
fckeditor asp版本的文件重命名
FckEditor 中文配置手册
FCKEditor网页编辑器 几点使用心得
FCK 编辑器焦点问题
添加FCKeditor插件需要注意的地方
javascript 获取FCKeditor内容
eWebEditor 上传文件提示格式不正确的解决方法
xhEditor的异步载入实现代码
FCKeditor 编辑器插入代码功能实现步骤
配置fckeditor 实现图片的上传
FCKeditor提供了一个完整的JavaScript API
fckediter javascript事件函数代码
ASP FCKeditor在线编辑器使用方法
ASP下使用FCKeditor在线编辑器的方法
ASP.NET中FCKEDITOR在线编辑器的用法
php下FCKeditor2.6.5网页编辑器的使用方法

网页编辑器 中的 nicedit 轻量级编辑器 使用心得


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 136 ::
收藏到网摘: n/a

NicEdit是一个轻量级,跨平台,内置内容编辑器,允许在浏览器中轻松地编辑网站上的内容。 NicEdit的Javascript集成到任何网站在几秒钟内作出的任何元素/区块编辑或转换标准textareas来丰富文本编辑。
How to use
http://nicedit.com/demos.php 给出了几个demo,包括最傻瓜式的把textarea转换成niceditor,简单配置编辑区和命令按钮,以及不同风格的编辑界面。
Deployment
NicEdit 可能是引用文件最少的在线编辑器,原因是不能更少了,一个js,一个图标文件。这两者的目录结构修改配置。
new nicEditor({iconsPath : '../nicEditorIcons.gif'})
Source Code
NicEdit 的源码是面向对象的,这使的本来就少至1300多行的代码更容易阅读,当然还有修改。
以一个添加图片的按钮为例:
/* 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 */
之间是添加图片按钮在按钮条上的配置,之后代码控制是添加图片按钮点击后浮出相应的面板,用来接收输入以在编辑器里插入图片。最后一句代码是把该按钮注册到按钮条上。
事实上,你也可以完全不使用nicedit的按钮条,而自己调用命令,即这行代码,
ne.nicCommand("insertImage",tmp);
这里的ne对象是nicedit的编辑区,它可以通过这种方式获得
myNicEditor = new nicEditor();
myNicEditor.addInstance('editordiv');
ed = myNicEditor.nicInstances[0];
需要注意的是,你要是这么简单的调用的话,和可能是没有任何效果的。你还需要在nicedit编辑区onblur前,比如你是在用户点击一个div的时候来插入图片,这时你需要在这个div onmousedown的时候执行
ed.saveRng();
来保存键盘在编辑器上的焦点,并在从用户那里得到了想要的输入以后,比如div的onclick,或是select的onchange以后,执行
ed.restoreRng();
以恢复焦点,只有这样,才能正确的位置插入图片。
download
nicedit提供了插件机制,非常容易拓展,在http://nicedit.com/download.php 你可以根据你的功能需要,来定制一个下载。
本站下载地址