KindEditor使用

1.KindEditor:
        1.初始化:
        <script>
                    var editor;
                    KindEditor.ready(function(K) {
                        editor = K.create('textarea[name="content"]', {
                            allowFileManager : true
                        });
                    });
        </script>
        2.自定义:
            var editor;
            KindEditor.ready(function(K) {
            editor = K.create('textarea[name="content"]', {
            allowFileManager : true,
            allowImageUpload : false,
            items:[
            'source', '|', 'fullscreen', 'undo', 'redo', 'cut', 'copy', 'paste',
            'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
            'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
            'superscript', '|', '-','selectall', 
            'title', 'fontname', 'fontsize', '|', 'textcolor', 'bgcolor', 'bold',
            'italic', 'underline', 'strikethrough', 'removeformat', '|', 'image',
             'advtable', 'hr', 'link', 'unlink', '|','preview'
            ]
            });
            });
        3.自定义插件:
        Css:
            .ke-icon-preview3 {
                            background-image: url(/libs/kindeditor/20.gif);
                            background-position: 0px -672px;
                            width: 16px;
                            height: 16px;
                        }
            
        JS:
        KindEditor.lang({
                        preview3 : '预览'
                    })
        KindEditor.plugin('preview3', function(K) {
            var self = this, name = 'preview3', undefined;
            self.clickToolbar(name, function() {
                var lang = self.lang(name + '.'),
                    html = '<div style="padding:10px 20px;">' +
                        '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
                        '</div>',
                    dialog = self.createDialog({
                        name : name,
                        width : 750,
                        title : self.lang(name),
                        body : html,
                        yesBtn : {
                        name : '确认提交',
                        click : function(e) {
                                $("#mail_form").submit();
                        }
                }
                    }),
                    iframe = K('iframe', dialog.div),
                    doc = K.iframeDoc(iframe);
                doc.open();
                var head_templet="<h1>模版3</h1>";
                
                var foot_templet="";
                doc.write(head_templet+self.fullHtml()+foot_templet);
                doc.close();
                K(doc.body).css('background-color', '#FFF');
                iframe[0].contentWindow.focus();
            });
        });
        调用:
        var template=$("#template").val();
        var oper='preview1';
        switch(template)
        {
            case '1':
            oper='preview1';
            break;
            case '2':
            oper='preview2';
            break;
            case '3':
            oper='preview3';
            break;
        }
        editor.clickToolbar(oper);
posted @ 2016-08-27 16:37  方白衣  阅读(1412)  评论(1编辑  收藏  举报