Extjs4整合CKEditor富文本编辑器
来源:互联网 发布:中央财政转移支付数据 编辑:程序博客网 时间:2024/06/14 02:42
项目中有个新闻管理模块,需要富文本编辑器,用的前端框架是Extjs mvc,网上搜了很多资料,尝试了很多方法,效果都不理想,最后自己参考ckeditor里面的示例达到了想要的效果,记录于此以便以后用到,也希望能够帮到需要的网友,有什么不恰当的地方望大家批评指正。
前端界面代码如下
/** * 新闻表单 */Ext.define('Redare.view.news.NewsFormView',{ extend:'Ext.form.Panel', alias:'widget.NewsFormView', border:false, layout:'anchor', //显示formpanel type=0 添加 type=1 修改 showFormPanel:function(title,type,typeId,newsId,url){ this.typeId = typeId; this.newsId = newsId; this.url = url; Ext.create('Ext.window.Window', { title: title, height: 500, width: 800, layout: 'fit', modal:true, items:this }).show(); this.addCkEditor(type); }, //添加富文本编辑器ckeditor addCkEditor:function(type){ var me = this; // CKEDITOR.appendTo('newsckeditor'); CKEDITOR.replace( 'newsckeditor',{ height: 280, width:760, //如果选择字体样式等的弹出窗口被当前window挡住,就设置这个为一个较大的值 baseFloatZIndex: 99999, //图片和flash都上传到这里 filebrowserUploadUrl: '/news/upload' }); CKEDITOR.instances["newsckeditor"].on("instanceReady", function () { if(type == 1){ //如果是修改新闻信息,则先加载数据 me.loadNewsInfo(); } }); }, loadNewsInfo:function(){ this.getLoader().load({ params:{ newsId:this.newsId } }); }, initComponent: function() { var me = this; var loader=ExtJsonDataLoader({ url:'/news/detail', autoLoad:false, maskTarget:me },function(data){ //alert(data.content); me.query('textfield[name=title]')[0].setValue(data.title); CKEDITOR.instances.newsckeditor.setData(data.content); me.query('hidden[name=filePath]')[0].setValue(data.contentPath); }); Ext.applyIf(me, { loader:loader, defaults:{ margin:'10 10 10 10', anchor:'100%' }, items: [ { xtype:'hidden', name:'filePath' }, { xtype: 'textfield', name: 'title', fieldLabel: '标题', allowBlank: false, labelAlign: 'right', anchor:'90%', labelWidth: 60 },{ xtype:'panel', autoScroll:true, height:350, widht:800, border:false, html:'<div id="newsckeditor" name="newsckeditor"></div>', items:[ /*{ xtype: 'ckeditor', allowBlank: false, //fieldLabel: '内容', //labelAlign: 'left', name: 'content', id:'newsckeditor', allowBlank: true, CKConfig: { height: 280, width:760, //如果选择字体样式等的弹出窗口被当前window挡住,就设置这个为一个较大的值 baseFloatZIndex: 99999, //图片和flash都上传到这里 filebrowserUploadUrl: '/news/upload' } }*/ ] } ], buttons: [ { text: '保存', name: 'newsSubmitBtn', formBind: true } ] }); me.callParent(arguments); }});
效果如图
@RequestMapping(value = "/upload",method = RequestMethod.POST)@ResponseBodypublic Object uploadFile( @RequestParam(value = "upload",required = true) MultipartFile file, @RequestParam(value = "CKEditorFuncNum",required = true) String CKEditorFuncNum, HttpServletResponse response, HttpSession session){ String fileName = System.currentTimeMillis()+file.getOriginalFilename(); String httpImgPath = contentHttpPath + "/images/" + getLoginUserInfo(session).getUserName() + "/"+fileName; String filePath = contentRootPath + "/images/" + getLoginUserInfo(session).getUserName() + "/"+fileName; File fileReal = new File(filePath); if (!fileReal.getParentFile().exists()){ fileReal.getParentFile().mkdirs(); } try{ file.transferTo(fileReal); OutputStream outputStream = response.getOutputStream(); String s = "<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction("+CKEditorFuncNum+", '"+httpImgPath+"');</script>"; byte[] bt = s.getBytes(); outputStream.write(bt); outputStream.close(); }catch (IOException ex){ logger.error("图片上传失败!",ex); } return null;}
在后台代码中,主要看outputStream.write(bt)的内容就可以了,其他都是文件上传。
0 0
- Extjs4整合CKEditor富文本编辑器
- 富文本编辑器CKEditor
- 富文本编辑器CKeditor
- CKEditor整合CKFinder.doc的使用 实现富文本编辑器的整合使用
- ExtJs整合ckeditor文本编辑器
- 很棒的富文本编辑器CKEditor
- Flask项目集成富文本编辑器CKeditor
- 富文本编辑器ckeditor的使用
- 富文本编辑器 CKeditor 配置使用
- ckeditor富文本编辑器的使用
- HTML 富文本编辑器插件 CKEditor
- 富文本编辑器 CKeditor 的使用
- 前端富文本编辑器ckeditor的使用
- 富文本编辑器CKEditor的使用
- CKeditor富文本编辑器的使用
- 富文本编辑器,CKEditor与 CKFinder 整合并实现文件上传功能
- CKEditor 整合CKFinder实现文件上传及富文本操作
- CKEditor(在线富文本编辑器)的安装与使用
- Android Fresco图片处理库用法API英文原文文档1(Facebook开源Android图片库)
- Bayesian face revisited : a joint formulation 论文学习
- MAC 地址格式
- C求一个数的二进制1的个数(精版)
- The using of parentNode ,previousSibling
- Extjs4整合CKEditor富文本编辑器
- 用云计算看鹏博士
- 控制器的创建
- 开通csdn博客了
- 经典排序算法(Java版)
- iOS 毛玻璃效果
- iOS开发--左滑返回手势失效
- Combinations -- leetcode
- [Rtsp]RTSP对实时摄像头视频流进行转换(FFmpeg+FFserver)