在Ueditor 1.4.3中自定义插件

1.定义js/ueditor/myCustomize/myCustomizeLine.js

UE.registerUI('customizeline',function(editor,uiName){
    //创建dialog
    var dialog = new UE.ui.Dialog({
        //指定弹出层中页面的路径
        iframeUrl:'js/ueditor/myCustomize/myCustomizeLinePage.html',
        //需要指定当前的编辑器实例
        editor:editor,
        //指定dialog的名字
        name:uiName,
        //dialog的标题
        title:"插入自定义XXX效果",

        //指定dialog的外围样式
        cssRules:"width:300px;height:170px;",

        //如果给出了buttons就代表dialog有确定和取消
        buttons:[
            {
                className:'edui-okbutton',
                label:'确定',
                onclick:function () {
                    dialog.close(true);
                }
            },
            {
                className:'edui-cancelbutton',
                label:'取消',
                onclick:function () {
                    dialog.close(false);
                }
            }
        ]});

    //参考myCustomizeLine.js
    var btn = new UE.ui.Button({
        name:'customizelinebutton',
        title: uiName,
        //需要添加的额外样式,指定icon图标,这里默认使用一个重复的icon
        cssRules :'background-position: -500px 0;',
        onclick:function () {
            //渲染dialog
            dialog.render();
            dialog.open();
        }
    });

    return btn;
}/*index 指定添加到工具栏上的那个位置,默认时追加到最后,editorId 指定这个UI是那个编辑器实例上的,默认是页面上所有的编辑器都会添加这个按钮*/);


2.定义myCustomizeLinePage.html

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
<div class="content">
     <p>
    名称:<input type="text" id="txtName" /><br/>
    </p>
</div>
<!--页面中一定要引入internal.js为了能直接使用当前打开dialog的实例变量-->
<!--internal.js默认是放到dialogs目录下的-->
<script type="text/javascript" src="../dialogs/internal.js"></script>
<script>
    //可以直接使用以下全局变量
    //当前打开dialog的实例变量
    //console.log('editor: '+editor);
    //一些常用工具
    //console.log('domUtils: '+domUtils);
    //console.log('utils: '+utils);
    //console.log('browser: '+browser);
    
    dialog.onok = function (){
        console.log("我点击了确定");
        var txtName= document.getElementById("txtName").value;
        var insertHtmlStr = '', txtNameAttr='';
        if(txtName!= null && txtName!= ""){
            txtNameAttr = 'name="'+txtName+'" ';
        }
        insertHtmlStr = '<input type="text"  ' + txtNameAttr+ '/>';
        console.log(insertHtmlStr);
        editor.execCommand('inserthtml', insertHtmlStr);
    };
    
    dialog.oncancel = function () {
        //console.log("我点击了取消");
    };
    
</script>
</body>
</html>


3.在ueditor.config.js中的whitList处添加,input:  ['type', 'id', 'name', 'width', 'height', 'title','class', 'style']


4.index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>完整demo</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <script type="text/javascript" charset="utf-8" src="js/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/ueditor/ueditor.all.min.js"> </script>
    
    <!--建议手动加在语言,避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型,比如你在配置项目里配置的是英文,这里加载的中文,那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="js/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/ueditor/myCustomize/myCustomizeLine.js"></script>

    <style type="text/css">
        div{
            width:100%;
        }
    </style>
</head>
<body>
<div>
    <h1>完整demo</h1>
    <script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>
</div>
<div id="btns">
    <div>
        <button οnclick="getAllHtml()">获得整个html的内容</button>
        <button οnclick="getContent()">获得内容</button>
        <button οnclick="setContent()">写入内容</button>
        <button οnclick="setContent(true)">追加内容</button>
        <button οnclick="getContentTxt()">获得纯文本</button>
        <button οnclick="getPlainTxt()">获得带格式的纯文本</button>
        <button οnclick="hasContent()">判断是否有内容</button>
        <button οnclick="setFocus()">使编辑器获得焦点</button>
        <button οnmοusedοwn="isFocus(event)">编辑器是否获得焦点</button>
        <button οnmοusedοwn="setblur(event)" >编辑器失去焦点</button>

    </div>
    <div>
        <button οnclick="getText()">获得当前选中的文本</button>
        <button οnclick="insertHtml()">插入给定的内容</button>
        <button id="enable" οnclick="setEnabled()">可以编辑</button>
        <button οnclick="setDisabled()">不可编辑</button>
        <button οnclick=" UE.getEditor('editor').setHide()">隐藏编辑器</button>
        <button οnclick=" UE.getEditor('editor').setShow()">显示编辑器</button>
        <button οnclick=" UE.getEditor('editor').setHeight(300)">设置高度为300默认关闭了自动长高</button>
    </div>

    <div>
        <button οnclick="getLocalData()" >获取草稿箱内容</button>
        <button οnclick="clearLocalData()" >清空草稿箱</button>
    </div>

</div>
<div>
    <button οnclick="createEditor()">
    创建编辑器</button>
    <button οnclick="deleteEditor()">
    删除编辑器</button>
</div>

<script type="text/javascript">

      ///
      //创建一个在选中的图片单击时添加边框的插件,其实质就是在baidu.editor.plugins塞进一个闭包
    /* UE.plugins["testMyPlugin"] = function () {
        var me = this;
        //创建一个改变图片边框的命令
        me.commands["myPluginCmd"] = {
            execCommand:function () {
                alert(1);
            }
        };
        //注册一个触发命令的事件,同学们可以在任意地放绑定触发此命令的事件
        me.addListener( 'click', function () {
            setTimeout(function(){
                me.execCommand( "myPluginCmd" );
            })

        } );
    }; */
      ///
       
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor' , {'enterTag':'br'});


    function isFocus(e){
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }
    function getAllHtml() {
        alert(UE.getEditor('editor').getAllHtml())
    }
    function getContent() {
        var arr = [];
        arr.push("使用editor.getContent()方法可以获得编辑器的内容");
        arr.push("内容为:");
        arr.push(UE.getEditor('editor').getContent());
        alert(arr.join("\n"));
    }
    function getPlainTxt() {
        var arr = [];
        arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
        arr.push("内容为:");
        arr.push(UE.getEditor('editor').getPlainTxt());
        alert(arr.join('\n'))
    }
    function setContent(isAppendTo) {
        var arr = [];
        arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
        UE.getEditor('editor').setContent('欢迎使用ueditor', isAppendTo);
        alert(arr.join("\n"));
    }
    function setDisabled() {
        UE.getEditor('editor').setDisabled('fullscreen');
        disableBtn("enable");
    }

    function setEnabled() {
        UE.getEditor('editor').setEnabled();
        enableBtn();
    }

    function getText() {
        //当你点击按钮时编辑区域已经失去了焦点,如果直接用getText将不会得到内容,所以要在选回来,然后取得内容
        var range = UE.getEditor('editor').selection.getRange();
        range.select();
        var txt = UE.getEditor('editor').selection.getText();
        alert(txt)
    }

    function getContentTxt() {
        var arr = [];
        arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
        arr.push("编辑器的纯文本内容为:");
        arr.push(UE.getEditor('editor').getContentTxt());
        alert(arr.join("\n"));
    }
    function hasContent() {
        var arr = [];
        arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
        arr.push("判断结果为:");
        arr.push(UE.getEditor('editor').hasContents());
        alert(arr.join("\n"));
    }
    function setFocus() {
        UE.getEditor('editor').focus();
    }
    function deleteEditor() {
        disableBtn();
        UE.getEditor('editor').destroy();
    }
    function disableBtn(str) {
        var div = document.getElementById('btns');
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            if (btn.id == str) {
                UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
            } else {
                btn.setAttribute("disabled", "true");
            }
        }
    }
    function enableBtn() {
        var div = document.getElementById('btns');
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
        }
    }

    function getLocalData () {
        alert(UE.getEditor('editor').execCommand( "getlocaldata" ));
    }

    function clearLocalData () {
        UE.getEditor('editor').execCommand( "clearlocaldata" );
        alert("已清空草稿箱")
    }
</script>
</body>
</html>


几个注意:iframeUrl的设置(在web工程里要设置路径,否则可能报404错误)

                    internal.js的设置

                    index中要引用自定义JS


参考: http://formdesign.leipi.org/doc.html

          http://blog.csdn.net/u014224349/article/details/39037141

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
UEditor是一款基于JavaScript的富文本编辑器,1.4.3是其一个版本。而在.NET平台上,将该富文本编辑器与.NET框架进行了结合,形成了UEDitor1.4.3 .NET版本。 UEDitor1.4.3 .NET版本是一个为开发者提供的快速、灵活的富文本编辑器解决方案。它完全基于.NET平台进行开发,因此可以充分利用.NET平台的强大功能和特性。开发者可以使用该版本的UEDitor来实现多种富文本编辑需求,比如在网页嵌入、编辑和保存富文本内容等。 UEDitor1.4.3 .NET版本具备了多种功能和特性,包括文字格式设置(字体、颜色、大小等)、段落样式设置(对齐、缩进等)、插入图片、插入表格、插入链接、上传附件等。开发者可以根据自己的需求选择相应的功能来实现富文本编辑。 UEDitor1.4.3 .NET版本还支持自定义配置和扩展。开发者可以根据自己的需求,设置编辑器的样式、功能和行为等。同时,还可以通过扩展插件的方式来增加新的功能或者修改现有功能逻辑。 UEDitor1.4.3 .NET版本的使用也相对简单。开发者只需在.NET项目引入相关资源文件,并进行简单的配置即可使用。同时,UEDitor1.4.3 .NET版本还提供了丰富的API接口,方便开发者通过代码来操作和控制编辑器的行为。 综上所述,UEDitor1.4.3 .NET版本是一款功能丰富、易用灵活的富文本编辑器解决方案,可在.NET平台上进行开发和应用。无论是网页编辑,还是后台管理系统的富文本内容管理,UEDitor1.4.3 .NET版本都可以提供可靠的支持。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值