1

I'm trying to implement a custom Image-Manager as a PlugIn into TinyMCE 4. My Image-Manager needs to be in an iFrame (Its a PHP page). This is how the code of my PlugIn looks like. The PlugIn code works alright.

How to return the image path from the PHP page inside the iframe back into the plugins ´scr` field?

A practical example would be wonderful (because I do not understand too much about javascript).

tinymce.PluginManager.add('example', function(editor, url) {

    editor.addButton('example', {
        text: 'My button',
        icon: false,
        onclick: function() {


            editor.windowManager.open({
                title: 'Example plugin',
                width: 980,
                height: 800,
                body: [
                    {type: 'textbox', name: 'scr', label: 'URL'},
                    {type: 'textbox', name: 'title', label: 'image-Beschreibung'},
                    {type: 'iframe', name: 'imageframe', url: 'imagedb.php', minWidth: '690', minHeight: '670'}

                ],
                onsubmit: function(e) {
                    editor.insertContent('<img src="' + e.data.scr + '">');
                }
            });
        }
    });
});
RononDex
  • 4,143
  • 22
  • 39
Uwe Kempf
  • 91
  • 8

1 Answers1

0

One way would to print out the php variable to the html document in a way that you would create a javascript variable holding the image_path as value. This value could be used later to be put inside the editor.

Example:

<?php
 $test1 = '1';

 print '
 <script type="text/javascript">
      var new_var = "<?php print($test1); ?>"
      console.log(new_var);
 </script>';
 ?>

You may also want to look at another example. Have a look at this thread: Pass a PHP string to a JavaScript variable (and escape newlines)

Community
  • 1
  • 1
Thariama
  • 50,002
  • 13
  • 138
  • 166
  • Thank you for your reply. The problem is "the usual way" doesn't work here. TinyMCE 4 generates the html stuff ( and so on) dynamically in realtime by javascript. IDs and names are not fix. Which means that there must be "an official tinyMCE way". Using their API... Any experience with that? – Uwe Kempf Feb 06 '14 at 08:42
  • hmm, i am not that much into tinymce 4 (but will be soon) – Thariama Feb 06 '14 at 09:30
  • the other way would be to print the image path directly into the textarea when rendering the page – Thariama Feb 06 '14 at 09:31
  • Hmmm... I suspect that the official API way might be the only way. (Wich is way to complex for me to understand ;-) – Uwe Kempf Feb 07 '14 at 07:00