[英]Can't seem to close tinymce 4 popup from a custom plugin
I have created a custom plugin inside of tinyMCE 4. It pops up a modal window and displays images in a said directory. 我在tinyMCE 4中创建了一个自定义插件。它弹出一个模态窗口并在所述目录中显示图像。 You pick the image, then it adds it to the content and closes the popup. 您选择图像,然后将其添加到内容并关闭弹出窗口。 I have it inserting the image into the content, but I can't seem to close the popup. 我把它插入到内容中,但我似乎无法关闭弹出窗口。 I've tried many different ways and none of them work. 我尝试了许多不同的方法,但没有一种方法可行。
One of the errors I get is: 我得到的一个错误是:
Uncaught TypeError: Cannot read property 'win' of undefined
That's happening with the current code which follows: 随后的当前代码正在发生这种情况:
Plugin: 插入:
tinymce.PluginManager.add('imageuploads', function(editor, url) {
// Add a button that opens a window
editor.addButton('imageuploads', {
text: 'Insert Image',
icon: false,
onclick: function() {
// Open window
editor.windowManager.open({
title: "Insert Uploaded Image",
url: 'insertimage.php',
width: 700,
height: 600,
inline: true,
close_previous: "yes"
});
}
});
});
Plugin File: 插件文件:
$(document).ready(function(){
$('#submit-image-url').bind('click', function(){
var image_url = $('.image_choice:checked').val();
var insert_url = '<img src="/editor/uploads/' + image_url + '">';
parent.tinymce.activeEditor.selection.setContent(insert_url);
parent.tinymce.activeEditor.windowManager.close(this);
});
});
There is some HTML before that, but all it is is the images listed out with a radio input to determine which one is selected. 之前有一些HTML,但它只是用无线电输入列出的图像来确定选择哪一个。 Inserting works, but I can't seem to close the popup. 插入作品,但我似乎无法关闭弹出窗口。
Any help would be greatly appreciated! 任何帮助将不胜感激! Thanks! 谢谢!
The errors are coming from tinymce.js on line #22746, so the close() method is getting called. 错误来自第22746行的tinymce.js,因此调用close()方法。 It just can't see the popup for some reason. 由于某种原因,它无法看到弹出窗口。
I fixed it with the following: 我修复了以下内容:
var ed = parent.tinymce.editors[0];
ed.windowManager.windows[0].close();
So, now my jQuery code looks like this: 所以,现在我的jQuery代码如下所示:
$('.image_choice').bind('click', function(){
var image_url = $('.image_choice:checked').val();
var insert_url = '<img src="/editor/uploads/' + image_url + '">';
parent.tinymce.activeEditor.selection.setContent(insert_url);
var ed = parent.tinymce.editors[0];
ed.windowManager.windows[0].close();
});
I hope this helps someone that runs into the same problem. 我希望这可以帮助遇到同样问题的人。 This one puzzled me for a few days now. 这个让我困惑了好几天了。
You can use this code, if your page has more than two TinyMCE editors: 如果您的页面有两个以上的TinyMCE编辑器,则可以使用此代码:
tinymce.activeEditor.windowManager.close();
I used it for TinyMCE 4. 我用它来制作TinyMCE 4。
I was fighting with this for while too. 我也一直在和它斗争。 I tried to implement TinyMCE 4: http://www.roxyfileman.com/ for MVC. 我试图为MVC实现TinyMCE 4: http ://www.roxyfileman.com/。
Changing this code helps me: win.tinyMCE.activeEditor.windowManager.close(); 更改此代码有助于我:win.tinyMCE.activeEditor.windowManager.close(); / win.tinyMCE.activeEditor.windowManager.windows[1].close(); / win.tinyMCE.activeEditor.windowManager.windows [1] .close();
In my case when I selected file, wrong popup get closed. 在我选择文件时,错误的弹出窗口关闭。 Maybe it helps to someone ;) 也许对某人有帮助;)
try to use thi code ` 尝试使用这个代码`
<script type="text/javascript">
var parentWin = (!window.frameElement && window.dialogArguments) || opener || parent || top;
$(function() {
$('img').click(function(e){
e.preventDefault();
imgSrc = $(this).attr('src');
imgAlt = $(this).attr('alt');
divInput = $("input#"+parentWin.inputSrc,parent.document).parent().attr('id');
divInputSplit = divInput.split("_");
divTitle = "mce_"+(parseInt(divInputSplit[1],10) +1);
$("input#"+parentWin.inputSrc,parent.document).val(imgSrc);
$("input#"+divTitle,parent.document).val(imgAlt);
$(".mce-close",parent.document).last().trigger("click");
});
});
</script>
or visit tinymce4 file browser ` 或访问tinymce4文件浏览器 `
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.