CKEditor与Bootstrap模态框的问题

6
我遇到了与如何在Bootstrap模态框中使用CKEditor?中指出的相同问题。但问题是修复方法似乎不再有效。
<button type="button" data-toggle="modal" data-target="#modalAddBrand">Launch modal</button>
<div class="modal fade" id="modalAddBrand" tabindex="-1" role="dialog" aria-labelledby="modalAddBrandLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="modalAddBrandLabel">add</h4>
      </div>
      <div class="modal-body">
            <form>
            <textarea name="editor1" id="editor1" rows="10" cols="80">
            This is my textarea to be replaced with CKEditor.
            </textarea>
            </form> 
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button id="AddBrandButton" type="button" class="btn btn-primary">Save</button>
      </div>
    </div>
  </div>
</div>

我已经在http://jsfiddle.net/7zDay/16/上发布了一个演示(包含推荐的修复),请尝试使用数学编辑器(使用sigma图标)并您会发现它不允许您在框中输入。如有任何帮助,将不胜感激。
3个回答

18

请尝试按照此指南中描述的解决方案:

$.fn.modal.Constructor.prototype.enforceFocus = function() {
    $( document )
        .off( 'focusin.bs.modal' ) // guard against infinite focus loop
        .on( 'focusin.bs.modal', $.proxy( function( e ) {
            if (
                this.$element[ 0 ] !== e.target && !this.$element.has( e.target ).length
                // CKEditor compatibility fix start.
                && !$( e.target ).closest( '.cke_dialog, .cke' ).length
                // CKEditor compatibility fix end.
            ) {
                this.$element.trigger( 'focus' );
            }
        }, this ) );
};

演示:http://jsfiddle.net/7zDay/17/。对我来说很好用。据我所知,这是一个更通用的修复方法。


Chrome和Firefox中的WFM。 - Reinmar
这是我在Mac上使用Chrome和Safari看到的内容。你在jsFiddle中看到工具栏了吗? - new name
非常好用!! - CrsCaballero
这对我没有用。我的CKEditor链接弹出窗口出现在主源模态对话框的后面。可能是z-index或其他什么东西。 - gene b.
浪费了7个小时后,我终于找到了可行的方法,谢谢。 - Muhammad Safeeullah Sarhandi

1

对于那些发现已接受的解决方案不起作用的人,只需添加这个CSS类:

.ck {z-index: 9999 !important;}

-1
It's so simple and doesn't create any script conflict.    
<!DOCTYPE html>
    <html>

    <head>
        <meta charset="utf-8">
        <meta name="robots" content="noindex, nofollow">
        <title>Classic editor with default styles</title>
        <script src="http://cdn.ckeditor.com/4.6.2/standard-all/ckeditor.js"></script>
    </head>

    <body>

        <textarea cols="80" id="editor1" name="editor1" rows="10" >&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;
        </textarea>

        <script>
            CKEDITOR.replace( 'editor1', {
                height: 260,
                width: 700,
            } );
        </script>
    </body>

    </html>

这个问题涉及到引导模态框,但这里没有涉及到。 - Alex

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接