thelos999 thelos999 - 27 days ago 11x
Javascript Question

TinyMCE Pass Content from Dialog Popup to Editor

I've been working on an issue for a while, and can't seem to find a solution. I'm trying to pass content from the dialog window to the editor. What I am looking to do is when the user clicks on my custom button on the editor, a dialog window opens (got that). Then, the window opens an external page which displays a table (got that). Then, the user is to click on radio button, and depending on which row they checked, certain attributes are passed (this is what I can't get).

Here is my code for what I have, so far:

$(document).ready(function() {
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() {{
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>');
}, {
text: 'Cancel',
onclick: 'close'

Just wanna get pointed in the right direction. Any help/suggestions would be greatly appreciated. Thank you in advanced.


FINALLY! Took me a while, but I solved my own issue. I'm posting my solution for anyone that has come, or will come, across this issue.

In my file-library.php, I needed to add:

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

And, in this is what was needed within the main onclick function:

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

Whew! What a relief...