I try do simple thing:
Copy HTML from TinyMCE editor to textarea
(programmatically)...
How i copy:
tinymce_apply_function(function(editor){
$(editor.getElement()).html(editor.getContent());
});
Description: Here i copy HTML from TinyMCE to <textarea>
. I need it, because after it, $('form').serializeArray();
will executed, and all fields from form will saved to database
About tinymce_apply_function():
/**
* applies function for all editors
* @param par_callback
*/
function tinymce_apply_function(par_callback) {
if (common.tinymce) {
for (var i = 0; i < tinyMCE.editors.length; i++) {
par_callback(tinyMCE.editors[i]);
}
}
}
Description: just apply some function for all TinyMCE editors (page may have more than one TinyMCE editor)
And finally i do:
Load saved HTML from database
Put code to
<textarea>
Put code from
<textarea>
to TinyMCE$.each(data, function(i, field){ var tmp_el = $('[name=' + field.name + ']'); if (tmp_el.length) { if (tmp_el.prop("tagName") == 'TEXTAREA') { tmp_el.html(field.value); if (common.tinymce && typeof(tmp_el.attr('id')) !== 'undefined' && typeof(tinyMCE.get(tmp_el.attr('id'))) !== 'undefined') { tinyMCE.get(tmp_el.attr('id')).setContent(tmp_el.html()); } // ... // other code is not important
My problem:
When i get HTML from TinyMCE, then this code looks like:
<p><p><strong>_..-~*"````"*~-._ < { (: BOLD :) } ></strong> <br></p><p> _____<br>[_____]<br data-mce-bogus="1"></p></p>
i.e. HTML has been encoded (why?) And because of it, when i put this "code" to TinyMCE back, it looks like 'plain' text :
What i doing wrong?
p.s. sorry for bad english, i still learn it