1

Topic: Initialisation problem after a XMLHttpRequest

Hi and thank's for the great editor.
I have a page where textareas are not available when loading the page, but will occure by replacement of the div content after a XMLHttpRequest query. Then I try to fire tinyMCE, but there is an error message and the browser (FF on MacOSX) hangs trying to load something from the server.

Here is the code. First a XMLHttpRequest is opened and the retrieved code is replacing the div content (element.innerHTML).

 ...
      xrequest.onreadystatechange = function() {
         if (xrequest.readyState == 4 && xrequest.status == 200) {
         element.innerHTML = xrequest.responseText;
         initEditor();
      }
    }
    xrequest.send(null);    
...

There are two textareas to transform in editors in the retrieved code. The function initEditor looks like this:

function initEditor(){
  tinyMCE.init({
      mode : "exact",
      elements: "u_abstract,u_content",
      debug : "true",
      langugage: "en"
   });
   }

The debug of TinyMCE is showing that the settings are correct, but then the page loading dies with a javascript error: tinyMCE is not defined. The build in Mozilla javascript console says the bug is there:

    document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + tinyMCE.baseURL + '/langs/' + this.settings['language'] +  '.js"></script>');

A similar code is working flawlessly with FCKeditor, so I can't guess where is the problem.
TinyMCE is firing normally if the textareas are present when loadin the page. I guess the error is related to the later initialisation from within a function. Any ideas?

2

Re: Initialisation problem after a XMLHttpRequest

I've got this working flawlessly.

FCKEditor was easier to implement by far as with tiny you have to be a lot more clever with the creating and removal of the editor instances when there is no page refresh goin on.

Here is my code for doing this. You can copy and use it as much as you like.

// Track TinyMCE controls and turn them on and off as needed.
var TinyMCEArr = [];
function AddTinyMCE(TinyMCEName)
{
    TinyMCEArr.push(TinyMCEName);
    tinyMCE.execCommand('mceAddControl',false,TinyMCEName);
}

function RemoveTinyMCE(TinyMCEName)
{
    //Find the one and remove from array
    var testvalue = "";
    var TMPTinyMCEArr = [];
    while(TinyMCEArr.length)
    {
        testvalue = TinyMCEArr.pop();
        if(testvalue != TinyMCEName)
        {
            TMPTinyMCEArr.push(testvalue);
        }
    }
    TinyMCEArr = TMPTinyMCEArr;
    tinyMCE.execCommand('mceRemoveControl',false,TinyMCEName);
}

function RemoveAllTinyMCE(TinyMCEName)
{
    var testvalue = "";
    while(TinyMCEArr.length)
    {
        var testvalue = TinyMCEArr.pop();
        tinyMCE.execCommand('mceRemoveControl',false,testvalue);
    }
}

I hope this helps. But i can assure you if your skill is able to create http posts in javascript then your bound to be able to get this working!

3

Re: Initialisation problem after a XMLHttpRequest

Hi, i got the last error that you say, and it's because the document.write() isn't allowed in javascripts  for xhtml

4

Re: Initialisation problem after a XMLHttpRequest

By the way,

   Anyone knows how i can use TinyMCE on a XHTML page?

   I need use TinyMCE and MathML  in the same page, in Mozilla if it can be.

   Ii think that changing  the document .write()  for something   that XHTML support may work but  i don't know enougth of the TinyMCE to do by myself.

   Is this easy or hard?