如果我在窗口外单击,我想关闭CKEditor。
停止在包含被ckeditor替换的textarea的div上的传播,如此
$('#resumo_div')。click(function(event){ event.stopPropagation(); });
然后检测到点击这似乎主要起作用。
例外情况是点击ckeditor小部件,例如Link小部件,它们被检测为外部。有没有一种标准的方法来做到这一点?
答案 0 :(得分:0)
您的问题是事件处理程序将从小部件开始,因为它们是单击的最顶层元素。当事件到达您的包含div时,该小部件将被制定。而不是将ckeditor包含在div中(覆盖我的例子,点击时将关闭ckeditor)。将ckeditor移到div(叠加)之外。
<div class="overlay"></div>
<div id="ckeditor-container"></div>
<style>
.overlay {
position: fixed;
width: 100%;
height: 100%;
}
#ckeditor-container {
position: fixed;
top: 50%;
height: 200px;
margin: -100px auto 0 auto; /* center the container */
}
</style>
答案 1 :(得分:0)
在发现How to hide ckeditor when we click outside of the editor?后,我能够通过拦截小部件中的点击次数来改进在那里发布的满足我需求的解决方案
$('body').click(function(event){
if($(event.target).parents('#articleEditor').length <= 0 && $(event.target).parents('.cke_dialog').length <= 0)
$('#articleEditor').hide();
})