我已经解决了一段时间的问题,似乎无法找到解决方案。我试图将内容从对话框窗口传递到编辑器。我要做的是当用户点击编辑器上的自定义按钮时,会打开一个对话框窗口(得到它)。然后,窗口打开一个显示表格的外部页面(得到该表格)。然后,用户将单击单选按钮,并根据他们检查的行,传递某些属性(这是我无法获得的)。
到目前为止,这是我的代码:
$(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'
}]
});
}
});
}
});
});
只想指向正确的方向。任何帮助/建议将不胜感激。先谢谢你。
答案 0 :(得分:1)
最后!我花了一段时间,但我解决了自己的问题。我正在为任何已经或即将来到这个问题的人发布我的解决方案。
在我的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();
呼!真是一种解脱......
答案 1 :(得分:0)
它适用于我,但取代:
parent.tinymce.activeEditor.d = $('.option:checked').attr('data');
有:
parent.tinymce.activeEditor.d = $('.option:checked').attr('value');
真是太宽慰了!