zoukankan      html  css  js  c++  java
  • ueditor1.4.3.1版本二次开发记录

    最近项目需要拿ueditor做一些个性化功能,在此特意把修改的内容记录在这,一来方便自己知道改动过的地方,二来也是希望后来者如何需要做到类似的功能可以直接拿去用了。

    1.去除复制粘贴内容中的图片、段落所包含的样式及类名

    在ueditor.config.js中找到“filterTxtRules”配置,并修改为以下代码

     1 filterTxtRules : function(){
     2            function transP(node){
     3                node.tagName = 'p';
     4                node.attrs=''; //清空所有属性
     5                node.setStyle();               
     6            }
     7            return {
     8                //直接删除及其字节点内容
     9                '-' : 'script style object iframe embed input select',
    10                'p': function(node){
    11                    node.attrs=''; //清空粘贴内容中p元素所带的属性
    12                },
    13                'img':function(node){
    14                 node.attrs['class']='';//清除class属性,此处不能使用node.attrs.class='',在ie8下报错,因为class是关键字
    15                 node.attrs['style']='';//清除style属性
    16                 node.setStyle();
    17                },
    18                'br':{'$':{}},
    19                'div':{'$':{}},
    20                'li':{'$':{}},
    21                'caption':transP,
    22                'th':transP,
    23                'tr':transP,
    24                'h1':transP,'h2':transP,'h3':transP,'h4':transP,'h5':transP,'h6':transP,
    25                'td':function(node){
    26                    //没有内容的td直接删掉
    27                    var txt = !!node.innerText();
    28                    if(txt){
    29                        node.parentNode.insertAfter(UE.uNode.createText('    '),node);
    30                    }
    31                    node.parentNode.removeChild(node,node.innerText())
    32                }
    33            }
    34         }()

     2.选中图片时段落居中等操作按钮灰色不可点

    这个功能需要修改到ueditor源码,所以需要你下载的是完整源码版本,然后找到"_src/adapter/editorui.js"这个文件并定位到" //排版,图片排版,文字方向"这里,如截图

    修改代码如下:

     1 //排版,图片排版,文字方向
     2     var typeset = {
     3         'justify':['left', 'right', 'center', 'justify'],
     4         'imagefloat':['none', 'left', 'center', 'right'],
     5         'directionality':['ltr', 'rtl']
     6     };
     7 
     8     for (var p in typeset) {
     9 
    10         (function (cmd, val) {
    11             var uilist = [];
    12             for (var i = 0, ci; ci = val[i++];) {
    13                 (function (cmd2) {
    14                     editorui[cmd.replace('float', '') + cmd2] = function (editor) {
    15                         var ui = new editorui.Button({
    16                             className:'edui-for-' + cmd.replace('float', '') + cmd2,
    17                             title:editor.options.labelMap[cmd.replace('float', '') + cmd2] || editor.getLang("labelMap." + cmd.replace('float', '') + cmd2) || '',
    18                             theme:editor.options.theme,
    19                             onclick:function () {
    20                                 editor.execCommand(cmd, cmd2);
    21                             }
    22                         });
    23                         uilist.push(ui);
    24                         editorui.buttons[cmd] = ui;
    25                         editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
    26                             var range = this.selection.getRange(),
    27                                 startNode;
    28                             startNode = range.getClosedNode();
    29                             if (startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG') {
    30                                 if(/image/g.test(ui.className)){
    31                                     ui.setDisabled(editor.queryCommandState(cmd) == -1);
    32                                     ui.setChecked(editor.queryCommandValue(cmd) == cmd2 && !uiReady);
    33                                 }else{
    34                                     ui.setDisabled(true);
    35                                 }
    36 
    37                             }else{
    38                                 ui.setDisabled(editor.queryCommandState(cmd) == -1);
    39                                 ui.setChecked(editor.queryCommandValue(cmd) == cmd2 && !uiReady);
    40                             }
    41                             
    42                         });
    43                         return ui;
    44                     };
    45                 })(ci)
    46             }
    47         })(p, typeset[p])
    48     }
  • 相关阅读:
    学习笔记-Python基础4-九九乘法表练习
    学习笔记-Python基础4-函数
    学习笔记-Python基础3-程序结构:顺序、分支、循环
    JS根据获取的navigator.userAgent,判断用户打开页面的终端
    代理模式,CGLIB 与Spring AOP实现原理
    ueditor不过滤保存html
    ecstore 新增input控件方法
    ecstore前台模板保留css样式
    ecstore 当前网址
    mysql 导入数据过大报错
  • 原文地址:https://www.cnblogs.com/zhouzone/p/4866131.html
Copyright © 2011-2022 走看看