如何在 Bootstrap Modal 中使用 CKEditor? [英] How to use CKEditor in a Bootstrap Modal?

查看:22
本文介绍了如何在 Bootstrap Modal 中使用 CKEditor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在基于 Bootstrap 模板的 HTML 页面中使用 CKEditor 插件,效果很好,但是如果我在像这样的 Bootstrap Modal

<div class="modalfade" 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">添加品牌</h4>

<div class="modal-body"><表格><textarea name="editor1" id="editor1" rows="10" cols="80">这是我要替换为 CKEditor 的 textarea.</textarea><脚本>CKEDITOR.replace('editor1');</表单>

<div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">关闭</button><button id="AddBrandButton" type="button" class="btn btn-primary">保存</button>

编辑器可以工作,但编辑器弹出窗口上的所有表单控件都被禁用,例如,如果您尝试添加链接或图像,则无法插入 URL 或任何描述,因为输入被禁用.

这个问题有什么解决方法吗?

这是一个小提琴示例:http://jsfiddle.net/7zDay/

解决方案

这应该有助于 http://jsfiddle.净/pvkovalev/4PACy/

$.fn.modal.Constructor.prototype.enforceFocus = function () {var $modalElement = this.$element;$(document).on('focusin.modal', function (e) {var $parent = $(e.target.parentNode);if ($modalElement[0] !== e.target && !$modalElement.has(e.target).length//在此处添加您需要的任何条件:&&!$parent.hasClass('cke_dialog_ui_input_select') &&!$parent.hasClass('cke_dialog_ui_input_text')) {$modalElement.focus()}})};

2016 年 10 月更新:

CKEditor 的 CDN 链接已更改,因此我更新了 jsfiddle

If I use the CKEditor plugin in an HTML page based on a Bootstrap template, it works great, however if I insert the editor on a Bootstrap Modal like this

<!-- Modal --> 
<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 brand</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>            <script>
             CKEDITOR.replace('editor1');
             </script>
             </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>

The editor works, but all the form controls on the popup windows of the editor are disabled, if you try to add a link or an image, for example, you cannot insert the URL or any description because the inputs are disabled.

Any workaround for this issue?

This is a fiddle example: http://jsfiddle.net/7zDay/

解决方案

This should help http://jsfiddle.net/pvkovalev/4PACy/

$.fn.modal.Constructor.prototype.enforceFocus = function () {
    var $modalElement = this.$element;
    $(document).on('focusin.modal', function (e) {
        var $parent = $(e.target.parentNode);
        if ($modalElement[0] !== e.target && !$modalElement.has(e.target).length
            // add whatever conditions you need here:
            &&
            !$parent.hasClass('cke_dialog_ui_input_select') && !$parent.hasClass('cke_dialog_ui_input_text')) {
            $modalElement.focus()
        }
    })
};

Update October 2016:

CDN link for CKEditor has been changed, so I updated jsfiddle

这篇关于如何在 Bootstrap Modal 中使用 CKEditor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆