Thứ Tư, 28 tháng 8, 2013

tinyMCE init /paste event /set content event/ get content event

tinyMCE.init({
        selector: "textarea#content",
        language: "vi",
        theme: "advanced",
        skin: "ugceditor",
        skin_variant: "m3_1.02",
        plugins: "media,paste",
        width: 715,
        height: 650,
        theme_advanced_buttons1: "bold,italic,underline,fontselect,fontsizeselect,forecolor,backcolor,|,bullist,numlist,outdent,indent,|,justifyleft,justifycenter,justifyright,justifyfull,|,link,unlink, zcode",
        theme_advanced_buttons2: "",
        theme_advanced_buttons3: "",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "",
        theme_advanced_path: false,
        theme_advanced_resize_horizontal: false,
        theme_advanced_resizing_max_width: 720,
        theme_advanced_resizing_min_width: 720,
        theme_advanced_resizing_min_height: 650,
        paste_auto_cleanup_on_paste: true,
        paste_remove_spans: true,
        paste_remove_styles: true,
        relative_urls : false,
        tab_focus: ":prev,:next",
        entity_encoding: "raw",
        media_strict: false,
        forced_root_block: 'div',        
        content_css: a + "/skins/ugceditor/content-1.04.css",
        debug: false,
        insertPhotos: {},
        force_br_newlines: true,
        force_p_newlines: false,
        setup: function (b) {
            //            b.addButton("zemotions", {
            //                title: "Chèn biểu tượng",
            //                "class": "mce_emotions",
            //                onclick: blog.Emotion
            //            });
            //            b.addButton("zimage", {
            //                title: "Chèn hình ảnh",
            //                "class": "mce_image",
            //                onclick: blog.UploadImageNormal2
            //            });
            //            b.addButton("zmusic", {
            //                title: "Chèn nhạc",
            //                "class": "mce_music",
            //                onclick: blog.SearchMusic2
            //            });
            b.addButton("zcode", {
                title: "Sửa HTML Source",
                "class": "mce_code",
                onclick: function () {
                    this.windowManager.open({
                        url: a + "/source_editor.htm",
                        width: parseInt(b.getParam("theme_advanced_source_editor_width", 720)),
                        height: parseInt(b.getParam("theme_advanced_source_editor_height", 580)),
                        inline: true,
                        resizable: true,
                        maximizable: true
                    }, {
                        theme_url: a
                    })
                }
            });
            b.onGetContent.add(function (c, d) {
                if (d.source_view) {
                    d.content = d.content.replace(/<img([^>]*)id="imgContent_(\d+)"([^>]*)class="imgContent"([^>]*)src="([^">]+)"([^>]*)\/>/gi, function (f, j, k, h, g, i, e) {
                        tinyMCE.settings.insertPhotos[k] = i;
                        return '<span id="imgContent_' + k + '" class="imgContent"' + j + h + g + e + "></span>"
                    })
                }
            });
            b.onBeforeSetContent.add(function (c, d) {
                if (d.source_view) {
                    d.content = d.content.replace(/<span\sid="imgContent_(\d+)"\sclass="imgContent"([^>]*)>\s*<\/span>/gi, function (e, h, g) {
                        var f = tinyMCE.settings.insertPhotos[h];
                        if (f) {
                            return '<img id="imgContent_' + h + '" class="imgContent" src="' + f + '"' + g + " />"
                        }
                        return e
                    })
                }
            });
            b.onSaveContent.add(function (c, d) {
                d.content = d.content.replace(/<img([^>]*)id="imgContent_(\d+)"([^>]*)class="imgContent"([^>]*)\/>/gi, '<span class="imgContent" rel="$2"$1$3$4></span>')
            });
            b.onPostRender.add(function (c) {
                c.dom.bind(c.getBody(), "focus", blog.showToolbar)
            })
        },
        paste_preprocess : function(pl, o) {
            // Content string containing the HTML from the clipboard
            var htmlObject = document.createElement('div');
            htmlObject.innerHTML = o.content;
            var a = htmlObject.getElementsByTagName("p");
            for(var i=0;i<a.length;i++){
                console.log(a[i].innerHTML);
            }
        //            o.content = "-: CLEANED :-\n" + o.content;
        },
        paste_postprocess : function(pl, o) {
        // Content DOM node containing the DOM structure of the clipboard
        //            alert(o.node.innerHTML);
        //            o.node.innerHTML = o.node.innerHTML + "\n-: CLEANED :-";
        }
    })
});

Không có nhận xét nào:

Đăng nhận xét