Search code examples
javascripttinymcemodalpopup

Javascript TinyMCE and Tinybox2


I am using [tinyMCE][1] and [tinybox2][2] i can get both to work independently but what i am tryng to achieve is that i click on edit button tinybox2 opens the url with the relevant id string on the page the link opens up this has tinyMCE on it with the update form, but i dont understand why tinymce does not load within the popup.

Is there a way to allow javascript to go to this popup of tinybox? or why is it preventing more javascript to load?

Thanks for any help :D

I have done this so far:

  1. <script type="text/javascript" src="js/jquery-1.8.2.js"></script>
  2. get test.php content via $.ajax(); -no idea on this one-
  3. <p><a class="Forumusername" onclick="TINY.box.show({url:'test.php',width:750,height:300})">CLICK ME</a>
  4. reinit TinyMCE editor with tinyMCE.init call. -i dont know how to implement this either-

Edited links but question is answered.


Solution

  • I'm not good in updating old code, so I will rewrite it completely. That's content of two my files test.php and edit.php:

    test.php

    <!doctype html>
    
    <link rel="stylesheet" href="js/tinybox2/style.css" type="text/css" />
    
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript" src="js/tiny_mce/tiny_mce.js"></script>
    <script type="text/javascript" src="js/tinybox2/tinybox.js"></script>
    
    <script type="text/javascript">
    $(function(){
        $('#open_editor').click(function(){
            $.get(this.href).done(function(html){
                TINY.box.show({ 
                    html: html,
                    width: 500, 
                    height: 400, 
                    openjs: function(){
                        tinyMCE.init({ mode: 'textareas', theme: 'advanced' });
                    }
                });
            });
            return false;
        });
        tinyMCE.init({ mode: 'textareas', theme: 'advanced' });
    });
    </script>
    
    <a id="open_editor" href="edit.php">Open editor</a>
    
    <textarea></textarea>
    

    edit.php

    <textarea name="body" rows="10" cols="50"></textarea>
    

    Correct paths to stylesheets and scripts before running test.php.

    These scripts are checked and tested.