我寫了這段代碼來初始化一個編輯器,但我的代碼在Firefox瀏覽器中的表現不同。
這是我的部分代碼:
這是我的部分代碼。
window.hexbit.widget = {
.
.
.
initEditorOn: function (editorId, mediaButtons = false) {
//檢查id是真實的。
if (!document.getElementById(editorId) ||
editorId.endsWith('__i__')) {
return;
}
//用戶已禁用TinyMCE.。
if (typeof window.tinyMCE =='undefined') {
wp.editor.initialize( editorId, {
quicktags: true。
});
return;
}
if (window.tinyMCE.get( editorId) !== null) {
console.log('window.tinyMCE.get(editorId) ! == null', window.tinyMCE.get(editorId))
//reinitialize editor.
window.tinyMCE.get(editorId)。 on('remove', function () {
console.log('removed')。
window.setTimeout(function () {
window.hexbit.widget.initEditorOn( editorId, mediaButtons)。
}, 50)。)
});
wp.editor.remove(editorId)。
return。
}
//init tinyMCE。
window.wp.editor.initialize( editorId, {
mediaButtons: mediaButtons,
tinymce: {
forced_root_block: false,
remove_lineebreaks: false,
remove_trailing_brs: false,
verify_html: false,
mode: 'html',
textarea_rows: 4,
entity_encoding: "raw",
init_instance_callback: function (editor) {
editor.getBody().style.backgroundColor = "#F4FFFF"/span>;
//重建編輯器,如果框架被破壞。
jQuery(editor.getWin()。 on('unload', function () {
console.log('#########HERE############ ' )
window.hexbit.widget.initEditorOn( editorId, mediaButtons)。
});
},
setup: function (editor) {
//重要的是在實時編輯中保存。
editor.on('keyup execcommand paste', window.tinyMCE。 util.Delay.debounce(function(e) {
window.tinyMCE.triggerSave()。
}, 1000))。)
editor.on('keyup execcommand paste', window.tinyMCE。 util.Delay.debounce(function(e){
$('body #' editorId).trigger('change')。
}, 3000))。)
},
});
},
.
.
.
}
問題是。雖然這段代碼在Chrome中運行良好,但在Firefox中,當這個jQuery(editor.getWin()).on('unload', function () {}回呼呼叫時,我的除錯日志console.log('#########HERE############ ')按預期列印出來,但這一行window.hexbit.widget.initEditorOn(editorId, mediaButtons);_code>沒有呼叫!
我找不到這個錯誤的原因,如果有人知道,請解釋一下。
謝謝...
uj5u.com熱心網友回復:
我通過使用延遲為0的setTimeOut解決了這個問題,另外underscore js有一個函式_.defer(function, *arguments) 推遲呼叫函式直到當前呼叫堆疊被清除,類似于使用延遲為0的setTimeout。
這對于執行昂貴的作業或分塊渲染HTML而不阻塞UI執行緒的更新非常有用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/320693.html
標籤:
下一篇:preventDefault、stopPropagation和cancelBubble不足以防止contextMenu試圖在Firefox移動測驗視圖中打開。
