首页前端开发其他前端知识nicedit 轻量级编辑器 使用心得

nicedit 轻量级编辑器 使用心得

时间2024-02-10 09:50:03发布访客分类其他前端知识浏览1079
导读:收集整理的这篇文章主要介绍了nicedit 轻量级编辑器 使用心得,觉得挺不错的,现在分享给大家,也给大家做个参考。 NicEdIT的Javascript集成到任何网站在几秒钟内作出的任...
收集整理的这篇文章主要介绍了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 你可以根据你的功能需要,来定制一个下载。
本站下载地址

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: nicedit 轻量级编辑器 使用心得
本文地址: https://pptw.com/jishu/608201.html
FCKEditor 表单提交时运行的代码 得到XML文档大小的方法

游客 回复需填写必要信息