如何使用CKEditor在Bootstrap模式? [英] How to use CKEditor in a Bootstrap Modal?
问题描述
如果我在基于Bootstrap模板的HTML页面中使用 CKEditor 插件,那么效果很好,但是如果我将编辑器插入a Bootstrap Modal like this
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">×</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?
这是一个小提示示例: http://jsfiddle.net/7zDay/
This is a fiddle example: http://jsfiddle.net/7zDay/
推荐答案
这应该有助于 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()
}
})
};
2016年10月更新:
CKEditor的CDN链接已更改,因此我更新了jsfiddle
CDN link for CKEditor has been changed, so I updated jsfiddle
这篇关于如何使用CKEditor在Bootstrap模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!