编辑:
查看这篇文章的底部以获得解决方案,但现在它引入了一个新问题。
我正在使用最新版本的 PageDown 和 Bootstrap 3。
这一系列事件导致以下错误:
Uncaught TypeError: Cannot call method 'removeChild' of null
此时 wmd-background 掩码可见并占据我的页面。
错误发生在第 4 步之后:
- 打开自定义模式对话框
- 关闭自定义模态对话框(使用 ok 或 cancel 无关紧要)
- 打开自定义模式对话框
- 关闭自定义模态对话框(使用 ok 或 cancel 无关紧要)
这是自定义的javascript代码:
var insert_image = $("#insert-image");
var submit_image = $("#insert-image-submit");
var insert_image_close = $("#insert-image-close-x, #insert-image-close");
var file_url = $("#file_url", insert_image);
var file_local = $("#file_local", insert_image);
editor.hooks.set("insertImageDialog", function(callback) {
submit_image.on("click", function(event) {
event.preventDefault();
console.log("submit image");
insert_image.modal("hide");
return callback(file_url.val().length > 0 ? file_url.val() : null);
});
insert_image_close.on("click", function() {
console.log("cancel");
return callback(null);
});
insert_image.modal("show");
return true;
});
editor.run();
我没有看到针对此特定问题发布的任何解决方案。我还尝试连接到 Bootstrap 的模态事件,并尝试附加我自己的或隐藏/显示 wmd-background 掩码,但我无法找到一个没有错误且没有额外背景掩码的解决方案。
我还应该补充一点,data-backdrop=""
当我构建模态对话框时,我也在我的 html 中进行了设置,但这除了防止背景变得特别暗之外没有任何作用。
解决方案:
我修补了库并更改了:
老破版本:
background.parentNode.removeChild(background);
新的半工作版本:
if (document.contains(background)) { background.parentNode.removeChild(background); }
新问题:随着您打开和关闭表单,提交和取消的回调越来越多。
每次关闭表单时,我都会收到 1 条,2 条,4 条,6 条,然后是 10 条 console.log 消息,因为我一直手动打开和关闭它。
我通过将其添加到编辑器钩子的顶部来临时修复此问题:
submit_image.unbind("click")
insert_image_close.unbind("click")
这似乎是一个 hack,肯定有更好的方法来处理记忆事件处理程序而不是取消绑定它+重新绑定它?