I wanted to ask the community for advice, as I myself, due to inexperience in this matter, cannot find a solution.
I describe the situation:
I am writing the editor of the site structure. It is made as follows: when you click on a section, the thickbox window pops up, into which the section editor is loaded, of which TinyMCE is a part. In the editor, there is a “apply” button, the function of which is to serialize the form data, send this data to the server, receive a response and replace the content with the thickbox. It looks like this:
function submit_form(button) {
var str = $("#edit_form").serialize()+"&"+button+"=true";
$.post("update", str, function(data) {
$("#container").parent().html(data);
});
}
The content of TinyMCE is not contained in the textarea and, accordingly, is not serialized. I see two possible solutions: either copy the contents of the editor to the textarea before serialization, or somehow serialize it separately and attach to the sent string. This is where the rake comes up on which I have been dancing for a while: in TinyMCE, there is no variable that simply contained the content of the editor, nor a function that would return this content without any unnecessary frauds (or I just couldn’t find - in this case, stick me with my nose and I will leave behind you, sprinkling ashes on my head). The only thing I found was the
getContent method, which "I get the meaning of this phrase, but if I use this method since I tried it:
function submit_form(button) {
$("#text").val(tinyMCE.get('text').getContent());
var str = $("#edit_form").serialize()+"&"+button+"=true";
$.post("update", str, function(data) {
$("#container").parent().html(data);
});
}
then when you load the thickbox for the second time, the line
$("#text").val(tinyMCE.get('text').getContent());
does not work. The editor is there, the content is there, but the method does not work, and accordingly the entire function submit_form () is also.
Teach young Padawan, eh?
')
If you need any additional information - tell me, I will add.
PS I am not a javascript expert and use it only insofar as I have to go without it - nowhere. Therefore, the statements “go out of sight” with a sad look are accepted, but I recommend to do without them - this is understandable. I turned to the community only after poking myself for a long time and did not find a solution.
Update:
The problem was solved like this:
function submit_form(button) {
tinyMCE.get('text').save();
var str = $("#edit_form").serialize()+"&"+button+"=true";
$.post("update", str, function(data) {
tinyMCE.get('text').remove();
$("#container").parent().html(data);
});
}
Well, the easiest way to get content is through tinyMCE.get ('text'). GetBody (). InnerHTML;
Apparently, when replacing the contents of the thickbox, a new copy of the editor was created and the old one did not go anywhere, so you had to use remove (), which I placed in $ .post so that the moment the
princess transformed
into a frog editor in textarea happened most invisibly to the user.