ueditor1.4.3.1版本二次开发记录
2015-10-10 10:44
218 查看
最近项目需要拿ueditor做一些个性化功能,在此特意把修改的内容记录在这,一来方便自己知道改动过的地方,二来也是希望后来者如何需要做到类似的功能可以直接拿去用了。
![](http://images2015.cnblogs.com/blog/748216/201510/748216-20151010154734518-1359636262.png)
修改代码如下:
1.去除复制粘贴内容中的图片、段落所包含的样式及类名
在ueditor.config.js中找到“filterTxtRules”配置,并修改为以下代码filterTxtRules : function(){ function transP(node){ node.tagName = 'p'; node.attrs=''; //清空所有属性 node.setStyle(); } return { //直接删除及其字节点内容 '-' : 'script style object iframe embed input select', 'p': function(node){ node.attrs=''; //清空粘贴内容中p元素所带的属性 }, 'img':function(node){ node.attrs['class']='';//清除class属性,此处不能使用node.attrs.class='',在ie8下报错,因为class是关键字 node.attrs['style']='';//清除style属性 node.setStyle(); }, 'br':{'$':{}}, 'div':{'$':{}}, 'li':{'$':{}}, 'caption':transP, 'th':transP, 'tr':transP, 'h1':transP,'h2':transP,'h3':transP,'h4':transP,'h5':transP,'h6':transP, 'td':function(node){ //没有内容的td直接删掉 var txt = !!node.innerText(); if(txt){ node.parentNode.insertAfter(UE.uNode.createText(' '),node); } node.parentNode.removeChild(node,node.innerText()) } } }()
2.选中图片时段落居中等操作按钮灰色不可点
这个功能需要修改到ueditor源码,所以需要你下载的是完整源码版本,然后找到"_src/adapter/editorui.js"这个文件并定位到" //排版,图片排版,文字方向"这里,如截图![](http://images2015.cnblogs.com/blog/748216/201510/748216-20151010154734518-1359636262.png)
修改代码如下:
//排版,图片排版,文字方向 var typeset = { 'justify':['left', 'right', 'center', 'justify'], 'imagefloat':['none', 'left', 'center', 'right'], 'directionality':['ltr', 'rtl'] }; for (var p in typeset) { (function (cmd, val) { var uilist = []; for (var i = 0, ci; ci = val[i++];) { (function (cmd2) { editorui[cmd.replace('float', '') + cmd2] = function (editor) { var ui = new editorui.Button({ className:'edui-for-' + cmd.replace('float', '') + cmd2, title:editor.options.labelMap[cmd.replace('float', '') + cmd2] || editor.getLang("labelMap." + cmd.replace('float', '') + cmd2) || '', theme:editor.options.theme, onclick:function () { editor.execCommand(cmd, cmd2); } }); uilist.push(ui); editorui.buttons[cmd] = ui; editor.addListener('selectionchange', function (type, causeByUi, uiReady) { var range = this.selection.getRange(), startNode; startNode = range.getClosedNode(); if (startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG') { if(/image/g.test(ui.className)){ ui.setDisabled(editor.queryCommandState(cmd) == -1); ui.setChecked(editor.queryCommandValue(cmd) == cmd2 && !uiReady); }else{ ui.setDisabled(true); } }else{ ui.setDisabled(editor.queryCommandState(cmd) == -1); ui.setChecked(editor.queryCommandValue(cmd) == cmd2 && !uiReady); } }); return ui; }; })(ci) } })(p, typeset[p]) }
相关文章推荐
- UISlider大总结
- flash builder 4.7 破解
- UITabelView移动,编辑大总结
- UIImageView animation大总结
- UIScrollView大总结
- request属性 request.getAttribute()
- IOS 实现UI状态保持和恢复
- UIScreenEdgePanGestureRecognizer无法响应/失效
- UITableBarController大总结
- Android Can only use lower 16 bits for requestCode问题
- IOS开发UI基础之综合应用
- iOS UIViewController的edgesForExtendedLayout属性
- IOS UITableView多选删除功能
- QT5设计VTK UI窗口
- uitableview beginupdates 和endupdates 的使用
- 深入了解iOS开发中UIWindow的相关使用
- iOS开发之键盘类型UIKeyboardType
- 【安卓】使用Handler完成子线程更新ui
- UI常用界面和矢量图标素材下载站点
- <iOS>UIViewController的edgesForExtendedLayout属性