自定义kindeditor附件上传插件开发

浏览:643 发布日期:2017/03/20 分类:功能实现 关键字: kindeditor 自定义插件
自定义一款kindeditor插件,该插件实现附件上传功能
1、环境依赖
本文环境依赖于tp3.2.3+kindeditor4.1.10
2、代码简述
插件存放位置
Public\plugins\kindeditor\plugins\attach
插件初始化<script charset="utf-8" src="/Public/plugins/kindeditor/kindeditor-min.js"></script>
        <script charset="utf-8" src="/Public/plugins/kindeditor/lang/zh-CN.js"></script>
        <script>
            var editor;
            KindEditor.ready(function(K) {
                editor = K.create('textarea[name="content"]', {
                    resizeType : 1,
                    allowPreviewEmoticons : false,
                    allowImageUpload : false,
                    items : [
                        'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                        'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                        'insertunorderedlist', '|', 'emoticons', 'image', 'link','attach']
                });
            });
        </script>
注意items 最后的 'attach' 即插件名称
插件核心js文件attach.js// Google Maps: http://code.google.com/apis/maps/index.html

KindEditor.plugin('attach', function(K) {
    var self = this, name = 'attach', lang = self.lang(name + '.');
        // TODO:用doc.write(iframeHtml)方式加载时,在IE6上第一次加载报错,暂时使用src方式
        var iframe = K('<iframe  class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'attach/attach.html" style="width:410px;height:210px;"></iframe>');
        var win, doc,dialog;
        function init(){
            var dialog = self.createDialog({
                name : name,
                width :400,
                height:60,
                title : self.lang(name),
                body : iframe,
                yesBtn : {
                    name : self.lang('yes'),
                    click : function(e) {
                        var ret = iframe[0].contentWindow.retvalue;
                        if(ret==null){
                            self.hideDialog()
                            alert("请先上传资料");
                            return ;
                        }
                        if(typeof ret=="string"){
                            ret = JSON.parse(ret);
                        }
                        if(ret.code!=0){
                            self.hideDialog()
                            alert(ret.errmsg);
                            return ;
                        }
                        var str = "<img src=\""+self.pluginsPath+"/attach/images/attach.jpg\" class=\"ke-attach\"/>";
                        self.insertHtml("<p style=\"text-align:center\"><a href=\""+ret.data+"\">"+str+"</a></p>");
                        
                        self.hideDialog()
                    }
                },
                beforeRemove : function() {
                    
                }
                
            });
            return dialog;
            
        }
        function ready() {
            win = iframe[0].contentWindow;
            doc = K.iframeDoc(iframe);
        }
        iframe.bind('load', function() {
            iframe.unbind('load');
            if (K.IE) {
                ready();
            } else {
                setTimeout(ready, 0);
            }
        });
        self.clickToolbar(name, function() {
            init()
        });

        
        
});
插件上传不了
需要插件的联系我
http://www.imwinlion.com/archives/38
评论( 相关
后面还有条评论,点击查看>>