TinyMCE opened in jqueryUI modal dialog

家住魔仙堡 提交于 2019-12-07 01:03:14

问题


When using tinyMCE in a jqueryUI modal dialog, I can't use the hyperlink or 'insert image' features.

Basically, after lots of searching, I've found this:

http://www.tinymce.com/develop/bugtracker_view.php?id=5917

The weird thing is that to me it seams less of a tinyMCE issue and more of a jqueryUI issue since the problem is not present when jqueryUI's modal property is set to false.

With a richer form I saw that what happens is that whenever the tinyMCE loses focus, the first element in the form gets focus even if it's not the one focused / clicked.

Does some JavaScript guru have any idea how I might be able to keep the dialog modal and make tinyMCE work?


回答1:


This fixed it for me when overriding _allowInteraction would not:

$(document).on('focusin', function(e) {
    if ($(event.target).closest(".mce-window").length) {
        e.stopImmediatePropagation();
    }
});

I can't really take credit for it. I got it from this thread on the TinyMCE forums. (They have moved their bugtracker to github. tinymce/issues/703 is the corresponding github issue.)




回答2:


It seems there are no propper solution for this issue yet. This is kind of a hack but it really worked for me. Every time you open the Dialog remove the text area and re add it like following,

var myDialog = $('#myDialog');
var myTextarea = myDialog.find('textarea');
var clonedTextArea = myTextarea.clone(); // create a copy before deleting from the DOM
var myTextAreaParent = myTextarea.parent(); // get the parent to add the created copy later

myTextarea.remove(); // remove the textarea

myDialog.find('.mce-container').remove(); // remove existing mce control if exists

myTextAreaParent.append(clonedTextArea); // re-add the copy

myDialog.dialog({
   open: function(e1,e2){
        setTimeout(function () {
             // Add your tinymce creation code here
       },50);
   }
});

myDialog.dialog('open');



回答3:


This seems to fix it for me, or at least work around it (put it somewhere in your $(document).ready()):

$.widget('ui.dialog', $.ui.dialog, {
    _allowInteraction: function(event) {
        return ($('.mce-panel:visible').length > 0);
    }
});


来源:https://stackoverflow.com/questions/17073353/tinymce-opened-in-jqueryui-modal-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!