nicedit 轻量级编辑器 使用心得
时间:2023-03-03 23:49:08
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 你可以根据你的功能需要,来定制一个下载。
本站下载地址
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
慎用UL列表
![](https://img.aspxhome.com/file/UploadPic/20093/25/01-71s.gif)
ASP应用之教你使用模板
![](https://img.aspxhome.com/file/UploadPic/up/2008101513214365.gif)
GitHub 热门:Python 算法大全,Star 超过 2 万
![](https://img.aspxhome.com/file/2023/1/133501_0s.jpg)
Golang汇编之控制流深入分析讲解
Python中常用的8种字符串操作方法
![](https://img.aspxhome.com/file/2023/6/87886_0s.jpg)
MYSQL自定义函数判断是否正整数的实例代码
![](https://img.aspxhome.com/file/2023/6/124066_0s.png)
innerHTML,outerHTML,innerText,outerText用法
细化解析:MySQL 数据库中对XA事务的限制
ACCESS中Field对象的标题属性
ASP读取Exif信息无组件实现过程
SQL Server 数据库索引其索引的小技巧
200个Python 标准库总结
Python文件遍历os.walk()与os.listdir()使用及说明
![](https://img.aspxhome.com/file/2023/8/89058_0s.png)
Go语言线程安全之互斥锁与读写锁
Javascript验证方法大全
如何利用python给图片添加半透明水印
![](https://img.aspxhome.com/file/2023/3/105193_0s.png)
Python字节单位转换实例
利用Django框架中select_related和prefetch_related函数对数据库查询优化
![](https://img.aspxhome.com/file/2023/9/133699_0s.jpg)