UEditor 编辑器使用

1、解决进入UEditor编辑器的空div被过滤

    在 ueditor.all.js 的 6984 行删除  //geckoSel.removeAllRanges()

2、解决UEditor内容div转换成p标签

    在 ueditor.config.js 的 356 行 修改 allowDivTransToP:true 为 allowDivTransToP:false

    在 ueditor.all.ja 的 9970 行 将 'allowDivTransToP':true, 改为  'allowDivTransToP':false,

3、解决进行编辑器默认内容

  <p><br/></p>

   在ueditor.all.js 的7015 行 把编辑器内容不能为空注释

    //编辑器不能为空内容
    // if (domUtils.isEmptyNode(me.body)) {
    //     me.body.innerHTML = '<p>' + (browser.ie ? '' : '<br/>') + '</p>';

    // }

4、解决style、script等标签被替换

  在ueditor.all.js 的 9948 行 添加 return;

    UE.plugins['defaultfilter'] = function () {
        return; // 添加的代码

        var me = this;

5、解决ueditor自动给 ul 添加 样式

   在 ueditor.all.ja 的 15284 行 function adjustListStyle(doc,ignore) 将方法里的代码全部注释

    //utils.each(domUtils.getElementsByTagName(doc,'ol ul'),function(node){

        //     if(!domUtils.inDoc(node,doc))
        //         return;

        //     var parent = node.parentNode;
        //     if(parent.tagName == node.tagName){
        //         var nodeStyleType = getStyle(node) || (node.tagName == 'OL' ? 'decimal' : 'disc'),
        //             parentStyleType = getStyle(parent) || (parent.tagName == 'OL' ? 'decimal' : 'disc');
        //         if(nodeStyleType == parentStyleType){
        //             var styleIndex = utils.indexOf(listStyle[node.tagName], nodeStyleType);
        //             styleIndex = styleIndex + 1 == listStyle[node.tagName].length ? 0 : styleIndex + 1;
        //             setListStyle(node,listStyle[node.tagName][styleIndex])
        //         }

        //     }
        //     var index = 0,type = 2;
        //     if( domUtils.hasClass(node,/custom_/)){
        //         if(!(/[ou]l/i.test(parent.tagName) && domUtils.hasClass(parent,/custom_/))){
        //             type = 1;
        //         }
        //     }else{
        //         if(/[ou]l/i.test(parent.tagName) && domUtils.hasClass(parent,/custom_/)){
        //             type = 3;
        //         }
        //     }

        //     var style = domUtils.getStyle(node, 'list-style-type');
        //     style && (node.style.cssText = 'list-style-type:' + style);
        //     node.className = utils.trim(node.className.replace(/list-paddingleft-\w+/,'')) + ' list-paddingleft-' + type;
        //     utils.each(domUtils.getElementsByTagName(node,'li'),function(li){
        //         li.style.cssText && (li.style.cssText = '');
        //         if(!li.firstChild){
        //             domUtils.remove(li);
        //             return;
        //         }
        //         if(li.parentNode !== node){
        //             return;
        //         }
        //         index++;
        //         if(domUtils.hasClass(node,/custom_/) ){
        //             var paddingLeft = 1,currentStyle = getStyle(node);
        //             if(node.tagName == 'OL'){
        //                 if(currentStyle){
        //                     switch(currentStyle){
        //                         case 'cn' :
        //                         case 'cn1':
        //                         case 'cn2':
        //                             if(index > 10 && (index % 10 == 0 || index > 10 && index < 20)){
        //                                 paddingLeft = 2
        //                             }else if(index > 20){
        //                                 paddingLeft = 3
        //                             }
        //                             break;
        //                         case 'num2' :
        //                             if(index > 9){
        //                                 paddingLeft = 2
        //                             }
        //                     }
        //                 }
        //                 li.className = 'list-'+customStyle[currentStyle]+ index + ' ' + 'list-'+currentStyle+'-paddingleft-' + paddingLeft;
        //             }else{
        //                 li.className = 'list-'+customStyle[currentStyle]  + ' ' + 'list-'+currentStyle+'-paddingleft';
        //             }
        //         }else{
        //             li.className = li.className.replace(/list-[\w\-]+/gi,'');
        //         }
        //         var className = li.getAttribute('class');
        //         if(className !== null && !className.replace(/\s/g,'')){
        //             domUtils.removeAttributes(li,'class')
        //         }
        //     });
        //     !ignore && adjustList(node,node.tagName.toLowerCase(),getStyle(node)||domUtils.getStyle(node, 'list-style-type'),true);
        // })/

6、解决ueditor自动给 li 添加 p 标签

  在 ueditor.all.js 的15159 行 将下面代码注释

  // utils.each(root.getNodesByTagName('li'),function(li){
        //     var tmpP = UE.uNode.createElement('p');
        //     for(var i= 0,ci;ci=li.children[i];){
        //         if(ci.type == 'text' || dtd.p[ci.tagName]){
        //             tmpP.appendChild(ci);
        //         }else{
        //             if(tmpP.firstChild()){
        //                 li.insertBefore(tmpP,ci);
        //                 tmpP = UE.uNode.createElement('p');
        //                 i = i + 2;
        //             }else{
        //                 i++;
        //             }

        //         }
        //     }
        //     if(tmpP.firstChild() && !tmpP.parentNode || !li.firstChild()){
        //         li.appendChild(tmpP);
        //     }
        //     //trace:3357
        //     //p不能为空
        //     if (!tmpP.firstChild()) {
        //         tmpP.innerHTML(browser.ie ? '&nbsp;' : '<br/>')
        //     }
        //     //去掉末尾的空白
        //     var p = li.firstChild();
        //     var lastChild = p.lastChild();
        //     if(lastChild && lastChild.type == 'text' && /^\s*$/.test(lastChild.data)){
        //         p.removeChild(lastChild)
        //     }

        // });

7、修改 ueditor.config.js 中的 358-363行

        // xss 过滤是否开启,inserthtml等操作
        ,xssFilterRules: false
        //input xss过滤
        ,inputXssFilter: false
        //output xss过滤

        ,outputXssFilter: false

8、修改 ueditor.config.js 中的 305-308 行

    ,autotypeset: {
            mergeEmptyline: false,           //合并空行
            removeClass: false,              //去掉冗余的class

            removeEmptyline: false         //去掉空行

9、在ueditor.all.js 的9967行 可搜索 UE.plugins['defaultfilter']  添加return代码;不就行内容处理

    UE.plugins['defaultfilter'] = function () {

        return;var me = this;

10、处理 ueditor 自动将空格转换成&nbsp;

    function isText(node, arr) {
        if(node.parentNode.tagName == 'pre'){
            //源码模式下输入html标签,不能做转换处理,直接输出
            arr.push(node.data)
        }else{
            arr.push(
                notTransTagName[node.parentNode.tagName] ? utils.html(node.data) : node.data.replace(/[ ]{2}/g,''))
        }

    }

修改成

function isText(node, arr) {
        if(node.parentNode.tagName == 'pre'){
            //源码模式下输入html标签,不能做转换处理,直接输出
            arr.push(node.data)
        }else{
            arr.push(utils.html(node.data))
        }

    }

11、在ueditor.all.js 的 10100行 解决dt dd 变成 ul li 注释掉如下代码

// case 'dl':
//     node.tagName = 'ul';
//     break;
// case 'dt':
// case 'dd':
//     node.tagName = 'li';
//     break;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值