TinyMCE 将内容从对话框弹出窗口传递给编辑器

TinyMCE Pass Content from Dialog Popup to Editor

我一直在处理一个问题,但似乎找不到解决方案。我正在尝试将对话框 window 中的内容传递给编辑器。我想要做的是当用户点击我在编辑器上的自定义按钮时,一个对话框 window 打开(知道了)。然后,window 打开一个显示 table(明白了)的外部页面。然后,用户点击单选按钮,根据他们选中的行,传递某些属性(这是我无法得到的)。

这是我目前所拥有的代码:

$(document).ready(function() { 
    tinymce.init({
        selector: '#postContent',
        menubar: false,
        statusbar: false,
        plugins: 'code, hr, image, link, media, paste, table, textcolor',
        toolbar: 'undo redo pastetext | formatselect | bold italic underline | subscript superscript | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | filelibrary link unlink | hr table | code',
        setup: function(e) {
            e.addButton('filelibrary', {
                image: 'file-library.svg',
                title: 'File Library',
                onclick: function() {
                    e.windowManager.open({
                        title: 'File Library',
                        url: 'file-library.php',
                        width: $(window).width() * .75,
                        height: $(window).height() * .75,
                        buttons: [{
                            text: 'Insert to Post',
                            onclick: function(e) {
                                var d = $('.option:checked').attr('data');
                                tinymce.activeEditor.execCommand('mceInsertContent', false, '<p>' + d + '</p>');
                                top.tinymce.activeEditor.windowManager.close();
                            }
                        }, {
                            text: 'Cancel',
                            onclick: 'close'
                        }]
                    });
                }
            });
        }
    });
});

只是想指出正确的方向。任何 help/suggestions 将不胜感激。先谢谢你了。

终于!花了我一段时间,但我解决了自己的问题。我正在为已经或将要遇到此问题的任何人发布我的解决方案。

在我的 file-library.php 中,我需要添加:

$('.option').click(function() {
     parent.tinymce.activeEditor.d = $('.option:checked').attr('data');
});

而且,这是主要 onclick 函数中所需要的:

tinymce.activeEditor.execCommand('mceInsertContent', false, '<p>' + tinymce.activeEditor.d + '</p>');
top.tinymce.activeEditor.windowManager.close();

哇!真松了一口气...

它对我有用,但要替换:

parent.tinymce.activeEditor.d = $('.option:checked').attr('data');

用于:

parent.tinymce.activeEditor.d = $('.option:checked').attr('value');

也松了一口气!