Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've added a shortcode button in the TinyMCE editor in the page/post pages that opens up a Thickbox form.

The button is working; it opens up the thickbox form like it should. However my stumbling point is getting the value BACK to the TinyMCE editor and closing the thickbox.

This is the code I'm using to display the button and opening Thickbox

ed.addButton('aesloop', {
            title: 'Adds a loop of recent posts with specific parameters to the page.',
            image: url+'/../img/shortcodeloop.png',
            onclick: function(){
                tb_show('Test', 'admin-ajax.php?action=aes_ajax_test');
            }
        });

which calls this function

add_action('wp_ajax_aes_ajax_test', 'aes_ajax_test');
function aes_ajax_test(){
    // echo the form
}

At the end of the form there will be a button that is supposed to take all the data and turn it into a shortcode.

My question is:

How do I get data from this thickbox upon a button press BACK to the TinyMCE editor and then close the thickbox?

I've done a lot of searching but I can't find proper documentation on Thickbox and can't find any on shortcodes and thickbox forms as well.

EDIT: I have tried using window.send_to_editor and tb_remove but I might have used these wrongly

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Okay so I spit through some existing themes I have to try and figure out how to achieve this. If anyone is reading this, this is how I did it:

In the onclick function of the TinyMCE I called the ajax form and then inside the form I added some javascript that uses the

tinyMCE.activeEditor.execCommand('mceInsertContent', 0, output);

command to put text back into the editor. This is ofcourse triggered by some sort of submit button.

Then I use

tb_remove();

To close the thickbox again.

So essentially that would make the function look a bit like this:

add_action('wp_ajax_aes_ajax_test', 'aes_ajax_test');
function aes_ajax_test(){
    ?>
    <script type="text/javascript">
        jQuery('#aes-submit').click(function(){
                    tinyMCE.activeEditor.execCommand('mceInsertContent', 0, 'swag');
                    tb_remove();
        })
    </script>
    <?php
    echo '<button id="aes-submit">Submit Data</button>';
}
share|improve this answer
    
I would suggest to declare a variable var custom_active_tiny_mce; on the Script you are adding buttons.Than onClick store ed variable like : custom_active_tiny_mce = ed; And you can send Output to the Active TinyMCE even if user did not clicked on TextArea. –  Burimi Jan 11 '13 at 20:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.