手机
当前位置:查字典教程网 >编程开发 >网页编辑器 >nicedit 轻量级编辑器 使用心得
nicedit 轻量级编辑器 使用心得
摘要:NicEdit的Javascript集成到任何网站在几秒钟内作出的任何元素/区块编辑或转换标准textareas来丰富文本编辑。Howtou...

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 你可以根据你的功能需要,来定制一个下载。

本站下载地址

【nicedit 轻量级编辑器 使用心得】相关文章:

PHP网页 Ewebeditor 编辑器嵌入方法

FCKeditor smarty 编辑器的应用PHP

fckeditor编辑器在php中的配置方法

kindSoft在线网页编辑器简单的配置参数介绍

百度编辑器二次开发常用手记整理小结

ThinkPHP中FCKeditor编辑器的使用方法

一个Javascript 编写的代码编辑器

dedecms5.5 最新版ckeditor编辑器整合教程

FCKeditor编辑器添加图片上传功能及图片路径问题解决方法

在asp.net中KindEditor编辑器的使用方法小结

精品推荐
分类导航