CKEditor
是一个非常优秀的 Web 服文本编辑器,提供了非常多的功能和丰富的文档
Constantly leading innovation in the field of rich text editing. Take full control of your content creation process with such unique features as Paste from Word, Advanced Content Filter, widgets, custom HTML formatting and many more.
CKEditor 还有一个很大的优势是它有一个非常强大的插件商店,里面基本都是免费的,推荐 3 个基础,但是很实用的插件:
修改表格的大小
Table Resize
:
http://ckeditor.com/addon/tableresize
预览编辑结果
Preview
:
http://ckeditor.com/addon/preview
文本的颜色
Color Button
:
http://ckeditor.com/addon/colorbutton
公式编辑器:
http://ckeditor.com/addon/ckeditorwiris
很酷的皮肤 Moon Dark:
http://ckeditor.com/addon/moono-dark
修改配置 config.js
1 2 3 4 5 6
// 使用上面的几个插件 config.extraPlugins = 'tableresize,preview,colorbutton'; // Simplify the dialog windows. config.removeDialogTabs = 'image:advanced;image:Link;link:advanced;link:target'; config.removePlugins = 'elementspath';
CKEditor 上传文件
http://ckeditor.com
,点击
Download
,然后下载,标准版就可以了,大多数时候 LGPL 的免费授权协议即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
<!DOCTYPE html > <html > <head > <meta charset ="utf-8" > <title > CKEditor 的使用</title > <script src ="/lib/ckeditor/ckeditor.js" > </script > </head > <body > <textarea id ="editor1" > </textarea > <button onclick ="setContent()" > Set Content</button > <button onclick ="getContent()" > Get Content</button > <script > CKEDITOR.replace('editor1' ); function setContent () { CKEDITOR.instances.editor1.setData('<b>This is for test</b>' ); } function getContent () { var content = CKEDITOR.instances.editor1.getData(); alert(content); } </script > </body > </html >
http://www.layui.com/doc/modules/layer.html
success() 是层弹出后的回调方法。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
createCkeditor('editor' ); function showEditorDialog () { layer.open({ type : 1 , title : '魔法编辑器' , closeBtn : false , content : $('#editor-box' ), area : ['700px' ], shadeClose : false , btn : ['保存' , '取消' ], btn1 : function () { var content = CKEDITOR.instances.editor.getData(); alert(content); layer.closeAll(); }, btn2 : function (e ) { }, success : function () { createCkeditor('editor' ); } }); } function createCkeditor (name ) { var editor = CKEDITOR.instances[name]; if (editor) { editor.destroy(true ); } CKEDITOR.replace(name, { language : 'zh-cn' , allowedContent : true , removePlugins : 'elementspath' , resize_enabled : false , height : '300px' }); }
filebrowserFlashUploadUrl
The location of the script that handles file uploads in the Flash dialog window. …
filebrowserImageUploadUrl
The location of the script that handles file uploads in the Image dialog window. …
filebrowserUploadUrl
The location of the script that handles file uploads. If set, the
Upload
tab will appear in the
Link
,
Image
, and
Flash
dialog windows.
到此为止,CKEditor 的介绍应该能满足百分之八十的需求了,如果想更深度的使用 CKEditor,就需要仔细的阅读帮助文档了
http://docs.cksource.com/Main_Page
。
也许有人要问我,你为啥这么崇洋媚外,不使用百度的 UEditor 或则 UMEditor?不更简单吗?帮助文档还是中文的呢!确实尝试过,但是它们的图片和文件上传弹出对话框在弹出层中显示不全(打开看看 Dom 结构就明白为啥了)和在弹出对话框中全屏编辑时有问题而放弃。