目錄
回复内容:
首頁 後端開發 php教程 javascript - wordpress 3.8.1 版本安装 ck编辑器插件 4.0 js错误 Uncaught TypeError: Cannot read property 'add' of undefined

javascript - wordpress 3.8.1 版本安装 ck编辑器插件 4.0 js错误 Uncaught TypeError: Cannot read property 'add' of undefined

Jun 06, 2016 pm 08:45 PM
ajax ckeditor javascript php wordpress

安装插件后 不能正常预览
问题代码区域

c.onSubmit.add(function() {}) 的错误

下面是 wp中的js代码 那位大什么帮忙 解读一番也好

run: function() {
            var b = this;
            this.checkPost(), this.schedule = a.schedule({
                time: 15e3,
                func: function() {
                    wp.autosave.local.save()
                },
                repeat: !0,
                protect: !0
            }), 
            a("form#post").on("submit.autosave-local",
             function() {
                var c = "undefined" != typeof tinymce && tinymce.get("content"),
                    d = a("#post_ID").val() || 0;
                c && !c.isHidden() ? c.onSubmit.add(function() {
                    wp.autosave.local.save({
                        post_title: a("#title").val() || "",
                        content: a("#content").val() || "",
                        excerpt: a("#excerpt").val() || ""
                    })
                }) : b.save({
                    post_title: a("#title").val() || "",
                    content: a("#content").val() || "",
                    excerpt: a("#excerpt").val() || ""
                }), wpCookies.set("wp-saving-post-" + d, "check")
            })
        },

登入後複製
登入後複製

在autosave.min.js文件中

错误提示 Uncaught TypeError: Cannot read property 'add' of undefined

没太看懂这个js 关键是 ckeditor.utils.js 和这个文件的关系 以及 如何调用,作用域是什么完全搞不清楚。

<br>function autosave_parse_response(a) {
    var b, c, d = wpAjax.parseAjaxResponse(a, "autosave");
    return d && d.responses && d.responses.length && (d.responses[0].supplemental && (c = d.responses[0].supplemental, jQuery.each(c, function(a, b) {
        a.match(/^replace-/) && jQuery("#" + a.replace("replace-", "")).val(b)
    })), d.errors || ((b = parseInt(d.responses[0].id, 10)) && autosave_update_slug(b), d.responses[0].data && jQuery(".autosave-message").text(d.responses[0].data))), d
}
function autosave_saved(a) {
    blockSave = !1, autosave_parse_response(a), autosave_enable_buttons()
}
function autosave_saved_new(a) {
    blockSave = !1;
    var b, c = autosave_parse_response(a);
    c && c.responses.length && !c.errors ? (b = parseInt(c.responses[0].id, 10), b && (notSaved = !1, jQuery("#auto_draft").val("0")), autosave_enable_buttons(), autosaveDelayPreview && (autosaveDelayPreview = !1, doPreview())) : autosave_enable_buttons()
}
function autosave_update_slug(a) {
    "undefined" != makeSlugeditClickable && jQuery.isFunction(makeSlugeditClickable) && !jQuery("#edit-slug-box > *").size() && jQuery.post(ajaxurl, {
        action: "sample-permalink",
        post_id: a,
        new_title: fullscreen && fullscreen.settings.visible ? jQuery("#wp-fullscreen-title").val() : jQuery("#title").val(),
        samplepermalinknonce: jQuery("#samplepermalinknonce").val()
    }, function(a) {
        if ("-1" !== a) {
            var b = jQuery("#edit-slug-box");
            b.html(a), b.hasClass("hidden") && b.fadeIn("fast", function() {
                b.removeClass("hidden")
            }), makeSlugeditClickable()
        }
    })
}
function autosave_loading() {
    jQuery(".autosave-message").html(autosaveL10n.savingText)
}
function autosave_enable_buttons() {
    jQuery(document).trigger("autosave-enable-buttons"), wp.heartbeat && wp.heartbeat.hasConnectionError() || setTimeout(function() {
        var a = jQuery("#submitpost");
        a.find(":button, :submit").removeAttr("disabled"), a.find(".spinner").hide()
    }, 500)
}
function autosave_disable_buttons() {
    jQuery(document).trigger("autosave-disable-buttons"), jQuery("#submitpost").find(":button, :submit").prop("disabled", !0), setTimeout(autosave_enable_buttons, 5e3)
}
function delayed_autosave() {
    setTimeout(function() {
        blockSave || autosave()
    }, 200)
}
var autosave, autosavePeriodical, fullscreen, doPreview, autosaveLast = "",
    autosaveDelayPreview = !1,
    notSaved = !0,
    blockSave = !1,
    autosaveLockRelease = !0;
jQuery(document).ready(function(a) {
    autosaveLast = a("#wp-content-wrap").hasClass("tmce-active") && "undefined" != typeof switchEditors ? wp.autosave.getCompareString({
        post_title: a("#title").val() || "",
        content: switchEditors.pre_wpautop(a("#content").val()) || "",
        excerpt: a("#excerpt").val() || ""
    }) : wp.autosave.getCompareString(), autosavePeriodical = a.schedule({
        time: 1e3 * autosaveL10n.autosaveInterval,
        func: function() {
            autosave()
        },
        repeat: !0,
        protect: !0
    }), a("#post").submit(function() {
        a.cancel(autosavePeriodical), autosaveLockRelease = !1
    }), a('input[type="submit"], a.submitdelete', "#submitpost").click(function() {
        blockSave = !0, window.onbeforeunload = null, a(":button, :submit", "#submitpost").each(function() {
            var b = a(this);
            b.hasClass("button-primary") ? b.addClass("button-primary-disabled") : b.addClass("button-disabled")
        }), "publish" == a(this).attr("id") ? a("#major-publishing-actions .spinner").show() : a("#minor-publishing .spinner").show()
    }), window.onbeforeunload = function() {
        var b, c = "undefined" != typeof tinymce ? tinymce.activeEditor : !1;
        if (c && !c.isHidden()) {
            if (c.isDirty()) return autosaveL10n.saveAlert
        } else if (b = fullscreen && fullscreen.settings.visible ? wp.autosave.getCompareString({
            post_title: a("#wp-fullscreen-title").val() || "",
            content: a("#wp_mce_fullscreen").val() || "",
            excerpt: a("#excerpt").val() || ""
        }) : wp.autosave.getCompareString(), b != autosaveLast) return autosaveL10n.saveAlert
    }, a(window).unload(function(b) {
        autosaveLockRelease && (b.target && "#document" != b.target.nodeName || a.ajax({
            type: "POST",
            url: ajaxurl,
            async: !1,
            data: {
                action: "wp-remove-post-lock",
                _wpnonce: a("#_wpnonce").val(),
                post_ID: a("#post_ID").val(),
                active_post_lock: a("#active_post_lock").val()
            }
        }))
    }), a("#post-preview").click(function() {
        return "1" == a("#auto_draft").val() && notSaved ? (autosaveDelayPreview = !0, autosave(), !1) : (doPreview(), !1)
    }), doPreview = function() {
        a("input#wp-preview").val("dopreview"), a("form#post").attr("target", "wp-preview").submit().attr("target", "");
        var b = navigator.userAgent.toLowerCase(); - 1 != b.indexOf("safari") && -1 == b.indexOf("chrome") && a("form#post").attr("action", function(a, b) {
            return b + "?t=" + (new Date).getTime()
        }), a("input#wp-preview").val("")
    }, a("#title").on("keydown.editor-focus", function(b) {
        var c;
        9 == b.which && (b.ctrlKey || b.altKey || b.shiftKey || ("undefined" != typeof tinymce && (c = tinymce.get("content")), c && !c.isHidden() ? a(this).one("keyup", function() {
            a("#content_tbl td.mceToolbar > a").focus()
        }) : a("#content").focus(), b.preventDefault()))
    }), "1" == a("#auto_draft").val() && a("#title").blur(function() {
        this.value && "1" == a("#auto_draft").val() && delayed_autosave()
    }), a(document).on("heartbeat-connection-lost.autosave", function(b, c, d) {
        if ("timeout" === c || 503 == d) {
            var e = a("#lost-connection-notice");
            wp.autosave.local.hasStorage || e.find(".hide-if-no-sessionstorage").hide(), e.show(), autosave_disable_buttons()
        }
    }).on("heartbeat-connection-restored.autosave", function() {
        a("#lost-connection-notice").hide(), autosave_enable_buttons()
    })
}), autosave = function() {
    var a, b, c = wp.autosave.getPostData();
    return blockSave = !0, c.autosave ? "block" == jQuery("#TB_window").css("display") ? !1 : (a = wp.autosave.getCompareString(c), a == autosaveLast ? !1 : (autosaveLast = a, jQuery(document).triggerHandler("wpcountwords", [c.content]), autosave_disable_buttons(), b = "1" == c.auto_draft ? autosave_saved_new : autosave_saved, jQuery.ajax({
        data: c,
        beforeSend: autosave_loading,
        type: "POST",
        url: ajaxurl,
        success: b
    }), !0)) : !1
}, window.wp = window.wp || {}, wp.autosave = wp.autosave || {}, function(a) {
    wp.autosave.getPostData = function() {
        var b, c, d = "undefined" != typeof tinymce ? tinymce.activeEditor : null,
            e = [],
            f = {
                action: "autosave",
                autosave: !0,
                post_id: a("#post_ID").val() || 0,
                autosavenonce: a("#autosavenonce").val() || "",
                post_type: a("#post_type").val() || "",
                post_author: a("#post_author").val() || "",
                excerpt: a("#excerpt").val() || ""
            };
        if (d && !d.isHidden()) {
            if (d.plugins.spellchecker && d.plugins.spellchecker.active) return f.autosave = !1, f;
            "mce_fullscreen" == d.id && tinymce.get("content").setContent(d.getContent({
                format: "raw"
            }), {
                format: "raw"
            }), tinymce.triggerSave()
        }
        return "undefined" != typeof fullscreen && fullscreen.settings.visible ? (f.post_title = a("#wp-fullscreen-title").val() || "", f.content = a("#wp_mce_fullscreen").val() || "") : (f.post_title = a("#title").val() || "", f.content = a("#content").val() || ""), a('input[id^="in-category-"]:checked').each(function() {
            e.push(this.value)
        }), f.catslist = e.join(","), (b = a("#post_name").val()) && (f.post_name = b), (c = a("#parent_id").val()) && (f.parent_id = c), a("#comment_status").prop("checked") && (f.comment_status = "open"), a("#ping_status").prop("checked") && (f.ping_status = "open"), "1" == a("#auto_draft").val() && (f.auto_draft = "1"), f
    }, wp.autosave.getCompareString = function(b) {
        return "object" == typeof b ? (b.post_title || "") + "::" + (b.content || "") + "::" + (b.excerpt || "") : (a("#title").val() || "") + "::" + (a("#content").val() || "") + "::" + (a("#excerpt").val() || "")
    }, wp.autosave.local = {
        lastSavedData: "",
        blog_id: 0,
        hasStorage: !1,
        checkStorage: function() {
            var a = Math.random(),
                b = !1;
            try {
                sessionStorage.setItem("wp-test", a), b = sessionStorage.getItem("wp-test") == a, sessionStorage.removeItem("wp-test")
            } catch (c) {}
            return this.hasStorage = b, b
        },
        getStorage: function() {
            var a = !1;
            return this.hasStorage && this.blog_id && (a = sessionStorage.getItem("wp-autosave-" + this.blog_id), a = a ? JSON.parse(a) : {}), a
        },
        setStorage: function(a) {
            var b;
            return this.hasStorage && this.blog_id ? (b = "wp-autosave-" + this.blog_id, sessionStorage.setItem(b, JSON.stringify(a)), null !== sessionStorage.getItem(b)) : !1
        },
        getData: function() {
            var b = this.getStorage(),
                c = a("#post_ID").val();
            return b && c ? b["post_" + c] || !1 : !1
        },
        setData: function(b) {
            var c = this.getStorage(),
                d = a("#post_ID").val();
            if (!c || !d) return !1;
            if (b) c["post_" + d] = b;
            else {
                if (!c.hasOwnProperty("post_" + d)) return !1;
                delete c["post_" + d]
            }
            return this.setStorage(c)
        },
        save: function(b) {
            var c, d, e = !1;
            return b ? (c = this.getData() || {}, a.extend(c, b), c.autosave = !0) : c = wp.autosave.getPostData(), c.autosave ? (d = wp.autosave.getCompareString(c), d == this.lastSavedData ? !1 : (c.save_time = (new Date).getTime(), c.status = a("#post_status").val() || "", e = this.setData(c), e && (this.lastSavedData = d), e)) : !1
        },
        init: function(b) {
            var c = this;
            this.checkStorage() && (a("#content").length || a("#excerpt").length) && (b && a.extend(this, b), this.blog_id || (this.blog_id = "undefined" != typeof window.autosaveL10n ? window.autosaveL10n.blog_id : 0), a(document).ready(function() {
                c.run()
            }))
        },
        run: function() {
            var b = this;
            this.checkPost(), this.schedule = a.schedule({
                time: 15e3,
                func: function() {
                    wp.autosave.local.save()
                },
                repeat: !0,
                protect: !0
            }), 
            a("form#post").on("submit.autosave-local",
             function() {
                var c = "undefined" != typeof tinymce && tinymce.get("content"),
                    d = a("#post_ID").val() || 0;
                c && !c.isHidden() ? c.onSubmit.add(function() {
                    wp.autosave.local.save({
                        post_title: a("#title").val() || "",
                        content: a("#content").val() || "",
                        excerpt: a("#excerpt").val() || ""
                    })
                }) : b.save({
                    post_title: a("#title").val() || "",
                    content: a("#content").val() || "",
                    excerpt: a("#excerpt").val() || ""
                }), wpCookies.set("wp-saving-post-" + d, "check")
            })
        },
        compare: function(a, b) {
            function c(a) {
                return a.toString().replace(/[\x20\t\r\n\f]+/g, "")
            }
            return c(a || "") == c(b || "")
        },
        checkPost: function() {
            var b, c, d, e, f = this,
                g = this.getData(),
                h = a("#post_ID").val() || 0,
                i = wpCookies.get("wp-saving-post-" + h);
            if (g) return i && (wpCookies.remove("wp-saving-post-" + h), "saved" == i) ? (this.setData(!1), void 0) : (a("#has-newer-autosave").length || (b = a("#content").val() || "", c = a("#title").val() || "", d = a("#excerpt").val() || "", a("#wp-content-wrap").hasClass("tmce-active") && "undefined" != typeof switchEditors && (b = switchEditors.pre_wpautop(b)), "check" != i && this.compare(b, g.content) && this.compare(c, g.post_title) && this.compare(d, g.excerpt) || (this.restore_post_data = g, this.undo_post_data = {
                content: b,
                post_title: c,
                excerpt: d
            }, e = a("#local-storage-notice"), a(".wrap h2").first().after(e.addClass("updated").show()), e.on("click", function(b) {
                var c = a(b.target);
                c.hasClass("restore-backup") ? (f.restorePost(f.restore_post_data), c.parent().hide(), a(this).find("p.undo-restore").show()) : c.hasClass("undo-restore-backup") && (f.restorePost(f.undo_post_data), c.parent().hide(), a(this).find("p.local-restore").show()), b.preventDefault()
            }))), void 0)
        },
        restorePost: function(b) {
            var c;
            return b ? (this.lastSavedData = wp.autosave.getCompareString(b), a("#title").val() != b.post_title && a("#title").focus().val(b.post_title || ""), a("#excerpt").val(b.excerpt || ""), c = "undefined" != typeof tinymce && tinymce.get("content"), c && !c.isHidden() && "undefined" != typeof switchEditors ? (c.undoManager.add(), c.setContent(b.content ? switchEditors.wpautop(b.content) : "")) : (a("#content-html").click(), a("#content").val(b.content)), !0) : !1
        }
    }, wp.autosave.local.init()
}(jQuery);
登入後複製
登入後複製

ckeditor 中的js

<br><br>var editorCKE;
jQuery(document).ready(function () {
    ckeditorSettings.configuration['on'] = {
        configLoaded : function ( evt ) {
            if (typeof(ckeditorSettings.externalPlugins) != 'undefined') {
                var externals=new Array();
                for (var x in ckeditorSettings.externalPlugins) {
                    CKEDITOR.plugins.addExternal(x, ckeditorSettings.externalPlugins[x]);
                    externals.push(x);
                }
            }
            evt.editor.config.extraPlugins += (evt.editor.config.extraPlugins ? ','+externals.join(',') : externals.join(','));
            if (evt.editor.config[evt.editor.config.toolbar +'_removeButtons']);
                evt.editor.config.removeButtons = evt.editor.config[evt.editor.config.toolbar +'_removeButtons'];
            CKEDITOR.addCss(evt.editor.config.extraCss);
        }
    };
    CKEDITOR.on( 'instanceReady', function( ev )
    {
        var dtd = CKEDITOR.dtd;
        for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) )
        {
            ev.editor.dataProcessor.writer.setRules( e, ckeditorSettings.outputFormat);
        }
        ev.editor.dataProcessor.writer.setRules( 'br',
        {
            breakAfterOpen : true
        });
        ev.editor.dataProcessor.writer.setRules( 'pre',
        {
            indent: false
        });
        editorCKE = CKEDITOR.instances['content'];
    });

    if (ckeditorSettings.textarea_id != 'comment'){
        edInsertContentOld = function () {
            return ;
        };
        if(typeof(window.edInsertContent) != 'undefined'){
            edInsertContentOld = window.edInsertContent;
        }
        window.edInsertContent = function (myField, myValue) {
            if(typeof(CKEDITOR) != 'undefined' && typeof(editorCKE) != 'undefined'){
                editorCKE.insertHtml(myValue);
            } else {
                edInsertContentOld(myField, myValue);
            }
        };
        var autosaveOld = function () {
            return ;
        };
        if(typeof(window.autosave) != 'undefined'){
            autosaveOld = window.autosave;
        }

        if(typeof(window.switchEditors) != 'undefined') {
            window.switchEditors.go = function(id, mode) {
                if ('tinymce' == mode || 'tmce' == mode) {
                    jQuery('#'+id).closest('.html-active').removeClass('html-active').addClass('tmce-active');
                    ckeditorOn(id);
                } else {
                    jQuery('#'+id).closest('.tmce-active').removeClass('tmce-active').addClass('html-active');
                    ckeditorOff(id);
                    jQuery('.js .theEditor').attr('style', 'color: black;');
                }
            };
        }
    }
    //if qTranslate plugin enabled
    if ( ckeditorSettings.qtransEnabled ){
        //custom version of switchEditors function when qTranslate plugin is enabled
        if(typeof(window.switchEditors) != 'undefined') {
            window.switchEditors.go = function(id, lang) {

                id = id || 'content';
                lang = lang || 'toggle';

                if ( 'toggle' == lang ) {
                    if ( ed && !ed.isHidden() )
                        lang = 'html';
                    else
                        lang = 'tmce';
                } else if( 'tinymce' == lang )
                    lang = 'tmce';

                var inst = tinyMCE.get('qtrans_textarea_' + id);
                var vta = document.getElementById('qtrans_textarea_' + id);
                var ta = document.getElementById(id);
                var wrap_id = 'wp-'+id+'-wrap';

                // update merged content
                if(inst && ! inst.isHidden()) {
                    tinyMCE.triggerSave();
                } else {
                    qtrans_save(vta.value);
                }
                // check if language is already active
                if(lang!='tmce' && lang!='html' && document.getElementById('qtrans_select_'+lang).className=='wp-switch-editor switch-tmce switch-html') {
                    return;
                }

                if(lang!='tmce' && lang!='html') {
                    document.getElementById('qtrans_select_'+qtrans_get_active_language()).className='wp-switch-editor';
                    document.getElementById('qtrans_select_'+lang).className='wp-switch-editor switch-tmce switch-html';
                }
                if(lang=='html') {
                    if ( inst && inst.isHidden() )
                        return false;
                    if ( inst ) {
                        vta.style.height = inst.getContentAreaContainer().offsetHeight + 20 + 'px';
                        inst.hide();
                    }
                    jQuery("#"+wrap_id).removeClass('tmce-active');
                    jQuery("#"+wrap_id).addClass('html-active');
                    setUserSetting( 'editor', 'html' );
                } else if(lang=='tmce') {
                    if(inst && ! inst.isHidden())
                        return false;
                    if ( tinyMCEPreInit.mceInit[id] && tinyMCEPreInit.mceInit[id].wpautop )
                        vta.value = this.wpautop(qtrans_use(qtrans_get_active_language(),ta.value));
                    if (inst) {
                        inst.show();
                    } else {
                        qtrans_hook_on_tinyMCE(id);
                    }
                    jQuery("#"+wrap_id).removeClass('html-active');
                    jQuery("#"+wrap_id).addClass('tmce-active');
                    setUserSetting('editor', 'tinymce');
                } else {
                    // switch content
                    qtrans_assign('qtrans_textarea_'+id,qtrans_use(lang,ta.value));
                }
            }
        }
        jQuery('#edButtonHTML').addClass('active');
        jQuery('#edButtonPreview').removeClass('active');
        if(ckeditorSettings.textarea_id != 'comment'){

            ckeditorSettings.textarea_id = 'qtrans_textarea_content';
            ckeditorSettings.configuration['on'].getData = function (evt) {
                evt.data.dataValue = evt.data.dataValue.replace(/(^<\/p>)|(<p>$)/g, '');
                evt.data.dataValue = evt.data.dataValue.replace(/^<p>(\s|\n|\r)*<p>/g, '<p>');
                evt.data.dataValue = evt.data.dataValue.replace(/<\/p>(\s|\n|\r)*<\/p>(\s|\n|\r)*$/g, '<\/p>');
                qtrans_save(evt.data.dataValue);
            };
            if ( jQuery('#'+ckeditorSettings.textarea_id).length && typeof CKEDITOR.instances[ckeditorSettings.textarea_id] == 'undefined' ) {
                CKEDITOR.replace(ckeditorSettings.textarea_id, ckeditorSettings.configuration);
                editorCKE = CKEDITOR.instances[ckeditorSettings.textarea_id];
                //add afterCommandExec exect to last created CKEditor instance
                editorCKE.on( 'afterCommandExec', function(ev) {
                    afterCommandEvent(ev);
                });
            }

            window.tinyMCE = tinymce =  getTinyMCEObject();
        }
    }else {
        if(ckeditorSettings.autostart && (typeof getUserSetting == 'undefined' || getUserSetting('editor') === '' || getUserSetting('editor') == 'tinymce')){
            ckeditorOn();
        }
    }
    jQuery("#update-gallery").click(function(){
        updateCkeGallery();
    });

    if (ckeditorSettings.excerpt_state && jQuery("textarea#excerpt").length > 0 && jQuery("#postexcerpt-hide").attr('checked') == 'checked') {
        //ckeditorOn('excerpt');
        CKEDITOR.replace('excerpt', ckeditorSettings.configuration);
    }
    if (typeof window.tinyMCE != 'undefined') {
        if (typeof QTags != 'undefined') {
            jQuery(".row-actions span.reply a").live('click', function(){
                if (typeof CKEDITOR.instances['replycontent'] != 'undefined') {
                    ckeditorOff('replycontent');
                }
                CKEDITOR.replace('replycontent', {'basicEntities' : false, 'entities': false,'toolbar_Comments' : [{ name: 'basicstyles', items : [ 'Bold','Italic','Underline'] }, { name: 'links', items : [ 'Link','Unlink' ] },{ name: 'paragraph', items : [ 'NumberedList','BulletedList'] }, { name: 'insert', items : [ 'Image' ] } ],  'toolbar' : 'Comments'});
            });
            jQuery("#replyrow a.save").unbind('click').live('click', function(){
                var data = null;
                if (typeof CKEDITOR.instances['replycontent'] != 'undefined') {
                    data = CKEDITOR.instances['replycontent'].getData();
                }
                if (data != null && data.length > 0 ) {
                    jQuery('textarea#replycontent').html(data);
                    ckeditorOff('replycontent');
                }
                commentReply.send();
                return;
            });
            jQuery("#replyrow a.cancel").unbind('click').live('click', function(){
                commentReply.revert()
                ckeditorOff('replycontent');
                return;
            });
            QTags.getInstance = function (editor_id) {
                return window.tinyMCE;
            }
        }
    }
});
function ckeditorOn(id) {
    var instance;
    if (typeof(id) != 'undefined' && typeof(CKEDITOR.instances[id]) == 'undefined' )
    {
        setUserSetting( 'editor', 'tinymce' );
        jQuery('#quicktags').hide();
        jQuery('#edButtonPreview').addClass('active');
        jQuery('#edButtonHTML').removeClass('active');
        instance = CKEDITOR.replace(id, ckeditorSettings.configuration);
    }
    if ( jQuery('textarea#'+ckeditorSettings.textarea_id).length && (typeof(CKEDITOR.instances) == 'undefined' || typeof(CKEDITOR.instances[ckeditorSettings.textarea_id]) == 'undefined' ) && jQuery("#"+ckeditorSettings.textarea_id).parent().parent().attr('id') != 'quick-press') {
        instance =  CKEDITOR.replace(ckeditorSettings.textarea_id, ckeditorSettings.configuration);
        if(ckeditorSettings.textarea_id == 'content') {
            setUserSetting( 'editor', 'tinymce' );
            jQuery('#quicktags').hide();
            jQuery('#edButtonPreview').addClass('active');
            jQuery('#edButtonHTML').removeClass('active');
        }
        else if(ckeditorSettings.textarea_id == 'comment') {
            var labelObj = jQuery('#'+ckeditorSettings.textarea_id).prev('label');
            if (labelObj){
                labelObj.hide();
            }
        }
    }
    if (typeof(instance) != 'undefined') {
        //add afterCommandExec exect to last created CKEditor instance
        instance.on( 'afterCommandExec', function(ev) {
            afterCommandEvent(ev);
        });
    }
}

function ckeditorOff(id) {
    if (typeof(id) != 'undefined')
    {
        editorCKE = CKEDITOR.instances[id];
    }else
    {
        editorCKE = CKEDITOR.instances[ckeditorSettings.textarea_id];
    }
    if(typeof(editorCKE) != 'undefined'){
        editorCKE.destroy();
        if(ckeditorSettings.textarea_id == 'content') {
            setUserSetting( 'editor', 'html' );
            jQuery('#quicktags').show();
            jQuery('#edButtonHTML').addClass('active');
            jQuery('#edButtonPreview').removeClass('active');
        }
    }
}

if ( !ckeditorSettings.qtransEnabled ){
    var tinymce = window.tinyMCE = getTinyMCEObject();
}
function getTinyMCEObject()
{
    var tinymce = window.tinyMCE = (function () {
        var tinyMCE = {
            isOpera : function() {
                return CKEDITOR.env.opera;
            },
            onAddEditor : { add : function() {
                // this function did nothing else apart from resizing TinyMCE
            } },
            get : function (id) {
                var instant = {
                    isHidden : function (){
                        editor = CKEDITOR.instances[id];
                        if (typeof editorCKE == 'undefined') editorCKE = editor;
                        if(typeof(editor) != 'undefined')
                        {
                                return false;
                        }else{
                                return true;
                        }
                    },
                    isDirty : function (){
                        return false;
                    },
                    execCommand : function (command, integer, val) {
                        if(command == 'mceSetContent') {
                            editorCKE.setData(val);
                        }
                        if (command == 'mceInsertContent')
                        {
                            editorCKE.insertHtml(val);
                        }
                    },
                    onSaveContent : {
                        add : function (func) {
                            window.tinymceosc = func;
                        }
                    },
                    getContentAreaContainer : function () {
                        return {
                            offsetHeight : editorCKE.config.height
                        };
                    },
                    hide : function () {
                        ckeditorOff(id);
                    },
                    show : function () {
                        ckeditorOn(id);
                    },
                    save : function(){
                        return;
                    },
                    focus : function(){
                        return;
                    },
                    plugins: {}
                };

                return instant;
            },
            execCommand : function (command, integer, val) {
                if(command == 'mceAddControl'){
                    ckeditorSettings.textarea_id = val;
                    if(ckeditorSettings.autostart) {
                        ckeditorOn();
                    } else {
                        document.getElementById('qtrans_textarea_content').removeAttribute('style');
                    }
                }
            },
            triggerSave : function(param) {
                if(typeof(CKEDITOR) != 'undefined' && typeof(editorCKE) != 'undefined')
                    editorCKE.updateElement();
            },
            activeEditor : {
                isHidden : function (){
                    return false;
                },
                isDirty : function (){
                    return false;
                },
                focus : function (){
                    return;
                },
                plugins : {},
                execCommand : function(command, state, text)
                {
                    if (command == "mceInsertContent")
                    {
                        //test if image has caption and make necessary text format
                        pattern = /\[caption(.*)\]<.*>(.*)\[\/caption\]/i;
                        if (pattern.test(text)) {
                            replace_match = pattern.exec(text);
                            text = text.replace(/<img  (.*) \/ alt="javascript - wordpress 3.8.1 版本安装 ck编辑器插件 4.0 js错误  Uncaught TypeError: Cannot read property &#039;add&#039; of undefined" >/g, function( match, cont )
                            {
                                cont = cont.replace(/class="(.*)"/g, function( match, cont ){
                                    tmp = 'class="' + cont + ' wp-caption"';
                                    return tmp;
                                });
                                tmp = '<img  ' + cont + ' data-cke-caption=\'' + replace_match[1] + '\' data-cke-caption-text=\'' + replace_match[2] + '\' / alt="javascript - wordpress 3.8.1 版本安装 ck编辑器插件 4.0 js错误  Uncaught TypeError: Cannot read property &#039;add&#039; of undefined" >' ;
                                return tmp;
                            });
                        }
                        //setTimeout is required in IE8 when inserting Image gallery from an external modal dialog
                        if (typeof editorCKE == 'undefined') editorCKE = CKEDITOR.instances[ckeditorSettings.textarea_id];
                        setTimeout(function(){
                            editorCKE.insertHtml(text);
                        }, 0);
                    }
                },
                selection : {
                    getBookmark : function(name) {
                        return '';
                    }
                },
                windowManager : {
                    bookmark: {}
                }
            },
            EditorManager :{
                activeEditor: {
                    selection : {
                        getNode : function(){
                            var obj = jQuery(editorCKE.document.getBody().getHtml());
                            var index = 0;
                            jQuery.each(obj,function(i, val){
                                var images = jQuery("img",jQuery(val));
                                jQuery.each(images, function(key, value){
                                    if (jQuery(value).hasClass('wpGallery, cke_wpgallery'))
                                    {
                                        index = i;
                                        return;
                                    }
                                });
                            });
                            if (obj.length === 0)
                            {
                                obj = document.createElement("p");
                                return obj;
                            }
                            return obj[index];
                        },
                        getBookmark : function(name) {
                            return ;
                        }
                    },
                    dom :{
                        select : function(selector) {

                            //get CKEditor content
                            var obj = editorCKE.document.getBody().getHtml();
                            images =  editorCKE.document.getElementsByTag('img');
                            if ( typeof images.$ == 'undefined' || images.$.length == 0) return [];
                            for (var i in images.$)
                            {
                                if ( typeof images.$[i] != 'undefined' && ((CKEDITOR.env.ie && images.$[i].className == 'wpGallery, cke_wpgallery') || images.$[i].classList == 'wpGallery, cke_wpgallery'))
                                {
                                    var element = new CKEDITOR.dom.element(images.$[i]);
                                    index = i;
                                    break;
                                }
                            }
                            var results =[];

                            if (typeof element != 'undefined')
                            {
                                results[0] = images.$[index];
                                return  results;

                            }else
                            {
                                return [];
                            }
                        },
                            getAttrib : function(el, selector)
                            {
                                    return jQuery(el).attr(selector);
                            },
                            //function to set new gallery attributes
                            setAttrib : function(el, selector, value)
                            {
                                //get CKEditor content
                                var obj = editorCKE.document.getBody().getHtml();
                                images =  editorCKE.document.getElementsByTag('img');
                                for (var i in images.$)
                                {
                                    if ( typeof images.$[i] != 'undefined' && ((CKEDITOR.env.ie && images.$[i].className == 'wpGallery, cke_wpgallery') || images.$[i].classList == 'wpGallery, cke_wpgallery'))
                                    {
                                        var element = new CKEDITOR.dom.element(images.$[i]);
                                        element.setAttribute('title', value);
                                        element.setAttribute('data-gallery', '['+value+']');
                                    }
                                }
                            },
                            decode : function(text) {
                                return text;
                            },
                            hasClass : function(element, name)
                            {
                                var hasClass = jQuery(element).attr('class');
                                var pattern = /wpGallery/;
                                return pattern.test(hasClass);
                            }
                    }
            },
            get : function(id) {return;}
            },
            DOM :{
                removeClass : function(id, className) {return;},
                addClass : function(id, className) {return;}
            },
            addI18n : function(language, param){
                return ;
            }
        };
    return tinyMCE;
})();
    return tinymce;
}
var tinyMCEPreInit =  {
    mceInit : function(){
        language : 'en';
    }
};

var tinyMCEPopup = {
    onInit : {
        add : function() {return ;}
    },
    editor : {
        windowManager : {
            createInstance : function(id) {return; }
        }
    }
};
/*
 * Function to move cursor after fake gallery image. Turn on frame show
 */
function updateCkeGallery()
{
    jQuery("#add_image").unbind('click');
    jQuery("#add_image").bind('click',function(){
        return true;
    });
}
function afterCommandEvent(ev)
{
    if (ev.data.name != 'maximize') { return; }
        //if maximize button was clicked hide/show WP admin bar - prevention of hiding buttton under WP admin bar
        if (ev.data.command.state == CKEDITOR.TRISTATE_ON) { jQuery("#wpadminbar").hide() } else { jQuery("#wpadminbar").show() }
}

登入後複製

回复内容:

安装插件后 不能正常预览
问题代码区域

c.onSubmit.add(function() {}) 的错误

下面是 wp中的js代码 那位大什么帮忙 解读一番也好

run: function() {
            var b = this;
            this.checkPost(), this.schedule = a.schedule({
                time: 15e3,
                func: function() {
                    wp.autosave.local.save()
                },
                repeat: !0,
                protect: !0
            }), 
            a("form#post").on("submit.autosave-local",
             function() {
                var c = "undefined" != typeof tinymce && tinymce.get("content"),
                    d = a("#post_ID").val() || 0;
                c && !c.isHidden() ? c.onSubmit.add(function() {
                    wp.autosave.local.save({
                        post_title: a("#title").val() || "",
                        content: a("#content").val() || "",
                        excerpt: a("#excerpt").val() || ""
                    })
                }) : b.save({
                    post_title: a("#title").val() || "",
                    content: a("#content").val() || "",
                    excerpt: a("#excerpt").val() || ""
                }), wpCookies.set("wp-saving-post-" + d, "check")
            })
        },

登入後複製
登入後複製

在autosave.min.js文件中

错误提示 Uncaught TypeError: Cannot read property 'add' of undefined

没太看懂这个js 关键是 ckeditor.utils.js 和这个文件的关系 以及 如何调用,作用域是什么完全搞不清楚。

<br>function autosave_parse_response(a) {
    var b, c, d = wpAjax.parseAjaxResponse(a, "autosave");
    return d && d.responses && d.responses.length && (d.responses[0].supplemental && (c = d.responses[0].supplemental, jQuery.each(c, function(a, b) {
        a.match(/^replace-/) && jQuery("#" + a.replace("replace-", "")).val(b)
    })), d.errors || ((b = parseInt(d.responses[0].id, 10)) && autosave_update_slug(b), d.responses[0].data && jQuery(".autosave-message").text(d.responses[0].data))), d
}
function autosave_saved(a) {
    blockSave = !1, autosave_parse_response(a), autosave_enable_buttons()
}
function autosave_saved_new(a) {
    blockSave = !1;
    var b, c = autosave_parse_response(a);
    c && c.responses.length && !c.errors ? (b = parseInt(c.responses[0].id, 10), b && (notSaved = !1, jQuery("#auto_draft").val("0")), autosave_enable_buttons(), autosaveDelayPreview && (autosaveDelayPreview = !1, doPreview())) : autosave_enable_buttons()
}
function autosave_update_slug(a) {
    "undefined" != makeSlugeditClickable && jQuery.isFunction(makeSlugeditClickable) && !jQuery("#edit-slug-box > *").size() && jQuery.post(ajaxurl, {
        action: "sample-permalink",
        post_id: a,
        new_title: fullscreen && fullscreen.settings.visible ? jQuery("#wp-fullscreen-title").val() : jQuery("#title").val(),
        samplepermalinknonce: jQuery("#samplepermalinknonce").val()
    }, function(a) {
        if ("-1" !== a) {
            var b = jQuery("#edit-slug-box");
            b.html(a), b.hasClass("hidden") && b.fadeIn("fast", function() {
                b.removeClass("hidden")
            }), makeSlugeditClickable()
        }
    })
}
function autosave_loading() {
    jQuery(".autosave-message").html(autosaveL10n.savingText)
}
function autosave_enable_buttons() {
    jQuery(document).trigger("autosave-enable-buttons"), wp.heartbeat && wp.heartbeat.hasConnectionError() || setTimeout(function() {
        var a = jQuery("#submitpost");
        a.find(":button, :submit").removeAttr("disabled"), a.find(".spinner").hide()
    }, 500)
}
function autosave_disable_buttons() {
    jQuery(document).trigger("autosave-disable-buttons"), jQuery("#submitpost").find(":button, :submit").prop("disabled", !0), setTimeout(autosave_enable_buttons, 5e3)
}
function delayed_autosave() {
    setTimeout(function() {
        blockSave || autosave()
    }, 200)
}
var autosave, autosavePeriodical, fullscreen, doPreview, autosaveLast = "",
    autosaveDelayPreview = !1,
    notSaved = !0,
    blockSave = !1,
    autosaveLockRelease = !0;
jQuery(document).ready(function(a) {
    autosaveLast = a("#wp-content-wrap").hasClass("tmce-active") && "undefined" != typeof switchEditors ? wp.autosave.getCompareString({
        post_title: a("#title").val() || "",
        content: switchEditors.pre_wpautop(a("#content").val()) || "",
        excerpt: a("#excerpt").val() || ""
    }) : wp.autosave.getCompareString(), autosavePeriodical = a.schedule({
        time: 1e3 * autosaveL10n.autosaveInterval,
        func: function() {
            autosave()
        },
        repeat: !0,
        protect: !0
    }), a("#post").submit(function() {
        a.cancel(autosavePeriodical), autosaveLockRelease = !1
    }), a('input[type="submit"], a.submitdelete', "#submitpost").click(function() {
        blockSave = !0, window.onbeforeunload = null, a(":button, :submit", "#submitpost").each(function() {
            var b = a(this);
            b.hasClass("button-primary") ? b.addClass("button-primary-disabled") : b.addClass("button-disabled")
        }), "publish" == a(this).attr("id") ? a("#major-publishing-actions .spinner").show() : a("#minor-publishing .spinner").show()
    }), window.onbeforeunload = function() {
        var b, c = "undefined" != typeof tinymce ? tinymce.activeEditor : !1;
        if (c && !c.isHidden()) {
            if (c.isDirty()) return autosaveL10n.saveAlert
        } else if (b = fullscreen && fullscreen.settings.visible ? wp.autosave.getCompareString({
            post_title: a("#wp-fullscreen-title").val() || "",
            content: a("#wp_mce_fullscreen").val() || "",
            excerpt: a("#excerpt").val() || ""
        }) : wp.autosave.getCompareString(), b != autosaveLast) return autosaveL10n.saveAlert
    }, a(window).unload(function(b) {
        autosaveLockRelease && (b.target && "#document" != b.target.nodeName || a.ajax({
            type: "POST",
            url: ajaxurl,
            async: !1,
            data: {
                action: "wp-remove-post-lock",
                _wpnonce: a("#_wpnonce").val(),
                post_ID: a("#post_ID").val(),
                active_post_lock: a("#active_post_lock").val()
            }
        }))
    }), a("#post-preview").click(function() {
        return "1" == a("#auto_draft").val() && notSaved ? (autosaveDelayPreview = !0, autosave(), !1) : (doPreview(), !1)
    }), doPreview = function() {
        a("input#wp-preview").val("dopreview"), a("form#post").attr("target", "wp-preview").submit().attr("target", "");
        var b = navigator.userAgent.toLowerCase(); - 1 != b.indexOf("safari") && -1 == b.indexOf("chrome") && a("form#post").attr("action", function(a, b) {
            return b + "?t=" + (new Date).getTime()
        }), a("input#wp-preview").val("")
    }, a("#title").on("keydown.editor-focus", function(b) {
        var c;
        9 == b.which && (b.ctrlKey || b.altKey || b.shiftKey || ("undefined" != typeof tinymce && (c = tinymce.get("content")), c && !c.isHidden() ? a(this).one("keyup", function() {
            a("#content_tbl td.mceToolbar > a").focus()
        }) : a("#content").focus(), b.preventDefault()))
    }), "1" == a("#auto_draft").val() && a("#title").blur(function() {
        this.value && "1" == a("#auto_draft").val() && delayed_autosave()
    }), a(document).on("heartbeat-connection-lost.autosave", function(b, c, d) {
        if ("timeout" === c || 503 == d) {
            var e = a("#lost-connection-notice");
            wp.autosave.local.hasStorage || e.find(".hide-if-no-sessionstorage").hide(), e.show(), autosave_disable_buttons()
        }
    }).on("heartbeat-connection-restored.autosave", function() {
        a("#lost-connection-notice").hide(), autosave_enable_buttons()
    })
}), autosave = function() {
    var a, b, c = wp.autosave.getPostData();
    return blockSave = !0, c.autosave ? "block" == jQuery("#TB_window").css("display") ? !1 : (a = wp.autosave.getCompareString(c), a == autosaveLast ? !1 : (autosaveLast = a, jQuery(document).triggerHandler("wpcountwords", [c.content]), autosave_disable_buttons(), b = "1" == c.auto_draft ? autosave_saved_new : autosave_saved, jQuery.ajax({
        data: c,
        beforeSend: autosave_loading,
        type: "POST",
        url: ajaxurl,
        success: b
    }), !0)) : !1
}, window.wp = window.wp || {}, wp.autosave = wp.autosave || {}, function(a) {
    wp.autosave.getPostData = function() {
        var b, c, d = "undefined" != typeof tinymce ? tinymce.activeEditor : null,
            e = [],
            f = {
                action: "autosave",
                autosave: !0,
                post_id: a("#post_ID").val() || 0,
                autosavenonce: a("#autosavenonce").val() || "",
                post_type: a("#post_type").val() || "",
                post_author: a("#post_author").val() || "",
                excerpt: a("#excerpt").val() || ""
            };
        if (d && !d.isHidden()) {
            if (d.plugins.spellchecker && d.plugins.spellchecker.active) return f.autosave = !1, f;
            "mce_fullscreen" == d.id && tinymce.get("content").setContent(d.getContent({
                format: "raw"
            }), {
                format: "raw"
            }), tinymce.triggerSave()
        }
        return "undefined" != typeof fullscreen && fullscreen.settings.visible ? (f.post_title = a("#wp-fullscreen-title").val() || "", f.content = a("#wp_mce_fullscreen").val() || "") : (f.post_title = a("#title").val() || "", f.content = a("#content").val() || ""), a('input[id^="in-category-"]:checked').each(function() {
            e.push(this.value)
        }), f.catslist = e.join(","), (b = a("#post_name").val()) && (f.post_name = b), (c = a("#parent_id").val()) && (f.parent_id = c), a("#comment_status").prop("checked") && (f.comment_status = "open"), a("#ping_status").prop("checked") && (f.ping_status = "open"), "1" == a("#auto_draft").val() && (f.auto_draft = "1"), f
    }, wp.autosave.getCompareString = function(b) {
        return "object" == typeof b ? (b.post_title || "") + "::" + (b.content || "") + "::" + (b.excerpt || "") : (a("#title").val() || "") + "::" + (a("#content").val() || "") + "::" + (a("#excerpt").val() || "")
    }, wp.autosave.local = {
        lastSavedData: "",
        blog_id: 0,
        hasStorage: !1,
        checkStorage: function() {
            var a = Math.random(),
                b = !1;
            try {
                sessionStorage.setItem("wp-test", a), b = sessionStorage.getItem("wp-test") == a, sessionStorage.removeItem("wp-test")
            } catch (c) {}
            return this.hasStorage = b, b
        },
        getStorage: function() {
            var a = !1;
            return this.hasStorage && this.blog_id && (a = sessionStorage.getItem("wp-autosave-" + this.blog_id), a = a ? JSON.parse(a) : {}), a
        },
        setStorage: function(a) {
            var b;
            return this.hasStorage && this.blog_id ? (b = "wp-autosave-" + this.blog_id, sessionStorage.setItem(b, JSON.stringify(a)), null !== sessionStorage.getItem(b)) : !1
        },
        getData: function() {
            var b = this.getStorage(),
                c = a("#post_ID").val();
            return b && c ? b["post_" + c] || !1 : !1
        },
        setData: function(b) {
            var c = this.getStorage(),
                d = a("#post_ID").val();
            if (!c || !d) return !1;
            if (b) c["post_" + d] = b;
            else {
                if (!c.hasOwnProperty("post_" + d)) return !1;
                delete c["post_" + d]
            }
            return this.setStorage(c)
        },
        save: function(b) {
            var c, d, e = !1;
            return b ? (c = this.getData() || {}, a.extend(c, b), c.autosave = !0) : c = wp.autosave.getPostData(), c.autosave ? (d = wp.autosave.getCompareString(c), d == this.lastSavedData ? !1 : (c.save_time = (new Date).getTime(), c.status = a("#post_status").val() || "", e = this.setData(c), e && (this.lastSavedData = d), e)) : !1
        },
        init: function(b) {
            var c = this;
            this.checkStorage() && (a("#content").length || a("#excerpt").length) && (b && a.extend(this, b), this.blog_id || (this.blog_id = "undefined" != typeof window.autosaveL10n ? window.autosaveL10n.blog_id : 0), a(document).ready(function() {
                c.run()
            }))
        },
        run: function() {
            var b = this;
            this.checkPost(), this.schedule = a.schedule({
                time: 15e3,
                func: function() {
                    wp.autosave.local.save()
                },
                repeat: !0,
                protect: !0
            }), 
            a("form#post").on("submit.autosave-local",
             function() {
                var c = "undefined" != typeof tinymce && tinymce.get("content"),
                    d = a("#post_ID").val() || 0;
                c && !c.isHidden() ? c.onSubmit.add(function() {
                    wp.autosave.local.save({
                        post_title: a("#title").val() || "",
                        content: a("#content").val() || "",
                        excerpt: a("#excerpt").val() || ""
                    })
                }) : b.save({
                    post_title: a("#title").val() || "",
                    content: a("#content").val() || "",
                    excerpt: a("#excerpt").val() || ""
                }), wpCookies.set("wp-saving-post-" + d, "check")
            })
        },
        compare: function(a, b) {
            function c(a) {
                return a.toString().replace(/[\x20\t\r\n\f]+/g, "")
            }
            return c(a || "") == c(b || "")
        },
        checkPost: function() {
            var b, c, d, e, f = this,
                g = this.getData(),
                h = a("#post_ID").val() || 0,
                i = wpCookies.get("wp-saving-post-" + h);
            if (g) return i && (wpCookies.remove("wp-saving-post-" + h), "saved" == i) ? (this.setData(!1), void 0) : (a("#has-newer-autosave").length || (b = a("#content").val() || "", c = a("#title").val() || "", d = a("#excerpt").val() || "", a("#wp-content-wrap").hasClass("tmce-active") && "undefined" != typeof switchEditors && (b = switchEditors.pre_wpautop(b)), "check" != i && this.compare(b, g.content) && this.compare(c, g.post_title) && this.compare(d, g.excerpt) || (this.restore_post_data = g, this.undo_post_data = {
                content: b,
                post_title: c,
                excerpt: d
            }, e = a("#local-storage-notice"), a(".wrap h2").first().after(e.addClass("updated").show()), e.on("click", function(b) {
                var c = a(b.target);
                c.hasClass("restore-backup") ? (f.restorePost(f.restore_post_data), c.parent().hide(), a(this).find("p.undo-restore").show()) : c.hasClass("undo-restore-backup") && (f.restorePost(f.undo_post_data), c.parent().hide(), a(this).find("p.local-restore").show()), b.preventDefault()
            }))), void 0)
        },
        restorePost: function(b) {
            var c;
            return b ? (this.lastSavedData = wp.autosave.getCompareString(b), a("#title").val() != b.post_title && a("#title").focus().val(b.post_title || ""), a("#excerpt").val(b.excerpt || ""), c = "undefined" != typeof tinymce && tinymce.get("content"), c && !c.isHidden() && "undefined" != typeof switchEditors ? (c.undoManager.add(), c.setContent(b.content ? switchEditors.wpautop(b.content) : "")) : (a("#content-html").click(), a("#content").val(b.content)), !0) : !1
        }
    }, wp.autosave.local.init()
}(jQuery);
登入後複製
登入後複製

ckeditor 中的js

<code class="lang-javascript"><br><br>var editorCKE;
jQuery(document).ready(function () {
    ckeditorSettings.configuration['on'] = {
        configLoaded : function ( evt ) {
            if (typeof(ckeditorSettings.externalPlugins) != 'undefined') {
                var externals=new Array();
                for (var x in ckeditorSettings.externalPlugins) {
                    CKEDITOR.plugins.addExternal(x, ckeditorSettings.externalPlugins[x]);
                    externals.push(x);
                }
            }
            evt.editor.config.extraPlugins += (evt.editor.config.extraPlugins ? ','+externals.join(',') : externals.join(','));
            if (evt.editor.config[evt.editor.config.toolbar +'_removeButtons']);
                evt.editor.config.removeButtons = evt.editor.config[evt.editor.config.toolbar +'_removeButtons'];
            CKEDITOR.addCss(evt.editor.config.extraCss);
        }
    };
    CKEDITOR.on( 'instanceReady', function( ev )
    {
        var dtd = CKEDITOR.dtd;
        for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) )
        {
            ev.editor.dataProcessor.writer.setRules( e, ckeditorSettings.outputFormat);
        }
        ev.editor.dataProcessor.writer.setRules( 'br',
        {
            breakAfterOpen : true
        });
        ev.editor.dataProcessor.writer.setRules( 'pre',
        {
            indent: false
        });
        editorCKE = CKEDITOR.instances['content'];
    });

    if (ckeditorSettings.textarea_id != 'comment'){
        edInsertContentOld = function () {
            return ;
        };
        if(typeof(window.edInsertContent) != 'undefined'){
            edInsertContentOld = window.edInsertContent;
        }
        window.edInsertContent = function (myField, myValue) {
            if(typeof(CKEDITOR) != 'undefined' && typeof(editorCKE) != 'undefined'){
                editorCKE.insertHtml(myValue);
            } else {
                edInsertContentOld(myField, myValue);
            }
        };
        var autosaveOld = function () {
            return ;
        };
        if(typeof(window.autosave) != 'undefined'){
            autosaveOld = window.autosave;
        }

        if(typeof(window.switchEditors) != 'undefined') {
            window.switchEditors.go = function(id, mode) {
                if ('tinymce' == mode || 'tmce' == mode) {
                    jQuery('#'+id).closest('.html-active').removeClass('html-active').addClass('tmce-active');
                    ckeditorOn(id);
                } else {
                    jQuery('#'+id).closest('.tmce-active').removeClass('tmce-active').addClass('html-active');
                    ckeditorOff(id);
                    jQuery('.js .theEditor').attr('style', 'color: black;');
                }
            };
        }
    }
    //if qTranslate plugin enabled
    if ( ckeditorSettings.qtransEnabled ){
        //custom version of switchEditors function when qTranslate plugin is enabled
        if(typeof(window.switchEditors) != 'undefined') {
            window.switchEditors.go = function(id, lang) {

                id = id || 'content';
                lang = lang || 'toggle';

                if ( 'toggle' == lang ) {
                    if ( ed && !ed.isHidden() )
                        lang = 'html';
                    else
                        lang = 'tmce';
                } else if( 'tinymce' == lang )
                    lang = 'tmce';

                var inst = tinyMCE.get('qtrans_textarea_' + id);
                var vta = document.getElementById('qtrans_textarea_' + id);
                var ta = document.getElementById(id);
                var wrap_id = 'wp-'+id+'-wrap';

                // update merged content
                if(inst && ! inst.isHidden()) {
                    tinyMCE.triggerSave();
                } else {
                    qtrans_save(vta.value);
                }
                // check if language is already active
                if(lang!='tmce' && lang!='html' && document.getElementById('qtrans_select_'+lang).className=='wp-switch-editor switch-tmce switch-html') {
                    return;
                }

                if(lang!='tmce' && lang!='html') {
                    document.getElementById('qtrans_select_'+qtrans_get_active_language()).className='wp-switch-editor';
                    document.getElementById('qtrans_select_'+lang).className='wp-switch-editor switch-tmce switch-html';
                }
                if(lang=='html') {
                    if ( inst && inst.isHidden() )
                        return false;
                    if ( inst ) {
                        vta.style.height = inst.getContentAreaContainer().offsetHeight + 20 + 'px';
                        inst.hide();
                    }
                    jQuery("#"+wrap_id).removeClass('tmce-active');
                    jQuery("#"+wrap_id).addClass('html-active');
                    setUserSetting( 'editor', 'html' );
                } else if(lang=='tmce') {
                    if(inst && ! inst.isHidden())
                        return false;
                    if ( tinyMCEPreInit.mceInit[id] && tinyMCEPreInit.mceInit[id].wpautop )
                        vta.value = this.wpautop(qtrans_use(qtrans_get_active_language(),ta.value));
                    if (inst) {
                        inst.show();
                    } else {
                        qtrans_hook_on_tinyMCE(id);
                    }
                    jQuery("#"+wrap_id).removeClass('html-active');
                    jQuery("#"+wrap_id).addClass('tmce-active');
                    setUserSetting('editor', 'tinymce');
                } else {
                    // switch content
                    qtrans_assign('qtrans_textarea_'+id,qtrans_use(lang,ta.value));
                }
            }
        }
        jQuery('#edButtonHTML').addClass('active');
        jQuery('#edButtonPreview').removeClass('active');
        if(ckeditorSettings.textarea_id != 'comment'){

            ckeditorSettings.textarea_id = 'qtrans_textarea_content';
            ckeditorSettings.configuration['on'].getData = function (evt) {
                evt.data.dataValue = evt.data.dataValue.replace(/(^)|(<p>$)/g, '');
                evt.data.dataValue = evt.data.dataValue.replace(/^</p>
<p>(\s|\n|\r)*</p>
<p>/g, '</p>
<p>');
                evt.data.dataValue = evt.data.dataValue.replace(/(\s|\n|\r)*(\s|\n|\r)*$/g, '');
                qtrans_save(evt.data.dataValue);
            };
            if ( jQuery('#'+ckeditorSettings.textarea_id).length && typeof CKEDITOR.instances[ckeditorSettings.textarea_id] == 'undefined' ) {
                CKEDITOR.replace(ckeditorSettings.textarea_id, ckeditorSettings.configuration);
                editorCKE = CKEDITOR.instances[ckeditorSettings.textarea_id];
                //add afterCommandExec exect to last created CKEditor instance
                editorCKE.on( 'afterCommandExec', function(ev) {
                    afterCommandEvent(ev);
                });
            }

            window.tinyMCE = tinymce =  getTinyMCEObject();
        }
    }else {
        if(ckeditorSettings.autostart && (typeof getUserSetting == 'undefined' || getUserSetting('editor') === '' || getUserSetting('editor') == 'tinymce')){
            ckeditorOn();
        }
    }
    jQuery("#update-gallery").click(function(){
        updateCkeGallery();
    });

    if (ckeditorSettings.excerpt_state && jQuery("textarea#excerpt").length > 0 && jQuery("#postexcerpt-hide").attr('checked') == 'checked') {
        //ckeditorOn('excerpt');
        CKEDITOR.replace('excerpt', ckeditorSettings.configuration);
    }
    if (typeof window.tinyMCE != 'undefined') {
        if (typeof QTags != 'undefined') {
            jQuery(".row-actions span.reply a").live('click', function(){
                if (typeof CKEDITOR.instances['replycontent'] != 'undefined') {
                    ckeditorOff('replycontent');
                }
                CKEDITOR.replace('replycontent', {'basicEntities' : false, 'entities': false,'toolbar_Comments' : [{ name: 'basicstyles', items : [ 'Bold','Italic','Underline'] }, { name: 'links', items : [ 'Link','Unlink' ] },{ name: 'paragraph', items : [ 'NumberedList','BulletedList'] }, { name: 'insert', items : [ 'Image' ] } ],  'toolbar' : 'Comments'});
            });
            jQuery("#replyrow a.save").unbind('click').live('click', function(){
                var data = null;
                if (typeof CKEDITOR.instances['replycontent'] != 'undefined') {
                    data = CKEDITOR.instances['replycontent'].getData();
                }
                if (data != null && data.length > 0 ) {
                    jQuery('textarea#replycontent').html(data);
                    ckeditorOff('replycontent');
                }
                commentReply.send();
                return;
            });
            jQuery("#replyrow a.cancel").unbind('click').live('click', function(){
                commentReply.revert()
                ckeditorOff('replycontent');
                return;
            });
            QTags.getInstance = function (editor_id) {
                return window.tinyMCE;
            }
        }
    }
});
function ckeditorOn(id) {
    var instance;
    if (typeof(id) != 'undefined' && typeof(CKEDITOR.instances[id]) == 'undefined' )
    {
        setUserSetting( 'editor', 'tinymce' );
        jQuery('#quicktags').hide();
        jQuery('#edButtonPreview').addClass('active');
        jQuery('#edButtonHTML').removeClass('active');
        instance = CKEDITOR.replace(id, ckeditorSettings.configuration);
    }
    if ( jQuery('textarea#'+ckeditorSettings.textarea_id).length && (typeof(CKEDITOR.instances) == 'undefined' || typeof(CKEDITOR.instances[ckeditorSettings.textarea_id]) == 'undefined' ) && jQu</p></code>
登入後複製
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1665
14
CakePHP 教程
1424
52
Laravel 教程
1321
25
PHP教程
1269
29
C# 教程
1249
24
wordpress文章列表怎麼調 wordpress文章列表怎麼調 Apr 20, 2025 am 10:48 AM

有四種方法可以調整 WordPress 文章列表:使用主題選項、使用插件(如 Post Types Order、WP Post List、Boxy Stuff)、使用代碼(在 functions.php 文件中添加設置)或直接修改 WordPress 數據庫。

wordpress主機怎麼建站 wordpress主機怎麼建站 Apr 20, 2025 am 11:12 AM

要使用 WordPress 主機建站,需要:選擇一個可靠的主機提供商。購買一個域名。設置 WordPress 主機帳戶。選擇一個主題。添加頁面和文章。安裝插件。自定義您的網站。發布您的網站。

wordpress主題頭部圖片如何更換 wordpress主題頭部圖片如何更換 Apr 20, 2025 am 10:00 AM

更換 WordPress 主題頭部圖片的分步指南:登錄 WordPress 儀錶盤,導航至“外觀”&gt;“主題”。選擇要編輯的主題,然後單擊“自定義”。打開“主題選項”面板並尋找“網站標頭”或“頭部圖片”選項。單擊“選擇圖像”按鈕並上傳新的頭部圖片。裁剪圖像並單擊“保存並裁剪”。單擊“保存並發布”按鈕以更新更改。

IIS和PHP的兼容性:深度潛水 IIS和PHP的兼容性:深度潛水 Apr 22, 2025 am 12:01 AM

IIS和PHP可以兼容,通過FastCGI實現。 1.IIS通過配置文件將.php文件請求轉發給FastCGI模塊。 2.FastCGI模塊啟動PHP進程處理請求,提高性能和穩定性。 3.實際應用中需注意配置細節、錯誤調試和性能優化。

wordpress怎麼導入源碼 wordpress怎麼導入源碼 Apr 20, 2025 am 11:24 AM

導入 WordPress 源碼需要以下步驟:創建子主題以進行主題修改。導入源碼,覆蓋子主題中的文件。激活子主題,使其生效。測試更改,確保一切正常。

wordpress怎麼查看前端 wordpress怎麼查看前端 Apr 20, 2025 am 10:30 AM

可以通過以下方法查看 WordPress 前端:登錄儀錶盤並切換到“查看站點”選項卡;使用無頭瀏覽器自動化查看過程;安裝 WordPress 插件在儀錶盤內預覽前端;通過本地 URL 查看前端(如果 WordPress 在本地設置)。

如果session_start()被多次調用會發生什麼? 如果session_start()被多次調用會發生什麼? Apr 25, 2025 am 12:06 AM

多次調用session_start()會導致警告信息和可能的數據覆蓋。 1)PHP會發出警告,提示session已啟動。 2)可能導致session數據意外覆蓋。 3)使用session_status()檢查session狀態,避免重複調用。

wordpress編輯日期怎麼取消 wordpress編輯日期怎麼取消 Apr 20, 2025 am 10:54 AM

WordPress 編輯日期可以通過三種方法取消:1. 安裝 Enable Post Date Disable 插件;2. 在 functions.php 文件中添加代碼;3. 手動編輯 wp_posts 表中的 post_modified 列。

See all articles