Firefox and TinyMCE 3.4.9 won't play together
I've filed a bug for tiny MCE users, but I hope someone else comes across this and finds a suitable solution.
Here's the situation: I have a form with a tinyMCE control that I am loading into a jquery dialog. it works fine the first time after they close it and open a new one. any interaction with tinyMCE control gives:
"Node cannot be used in a document other than the one in which it was created"
it also does not populate the control with the text it should prepopulate.
In my jquery dialog, I have the following scripts in my beforeClose handler:
if (typeof tinyMCE != 'undefined') {
$(this).find(':tinymce').each(function () {
var theMce = $(this);
tinyMCE.execCommand('mceFocus', false, theMce.attr('id'));
tinyMCE.execCommand('mceRemoveControl', false, theMce.attr('id'));
$(this).remove();
});
}
and here's my tinyMCE script setup:
$('#' + controlId).tinymce({
script_url: v2ScriptPaths.TinyMCEPath,
mode: "none",
elements: controlId,
theme: "advanced",
plugins: "paste",
paste_retain_style_properties: "*",
theme_advanced_toolbar_location: "top",
theme_advanced_buttons1: "bold, italic, underline, strikethrough, separator, justifyleft, justifycenter, justifyright, justifyfull, indent, outdent, separator, undo, redo, separator, numlist, bullist, hr, link, unlink,removeformat",
theme_advanced_buttons2: "fontsizeselect, forecolor, backcolor, charmap, pastetext,pasteword,selectall, sub, sup",
theme_advanced_buttons3: "",
language: v2LocalizedSettings.languageCode,
gecko_spellcheck : true,
onchange_callback: function (editor) {
tinyMCE.triggerSave();
},
setup: function (editor) {
editor.onInit.add(function (editor, event) {
if (typeof v2SetInitialContent == 'function') {
v2SetInitialContent();
}
})
}
});
Is there something obvious here? i have all that complicated removal process in close b / c tinymce doesn't like if it removed the html without removing it.
the setInitialContent () property is just so that I can preload it with my email if there is one. it broke with or without this code so as not to be a problem.
I was forced to upgrade to 3.4.9 due to this problem:
http://www.tinymce.com/forum/viewtopic.php?id=28400
so if someone can work it out it will help this situation. I tried the offer from aknosis with no luck.
EDIT: Originally I thought this only affected firefox 11, but I downloaded 10 and this also affected.
EDIT: Okay, I have truncated all my convoluted dynamic forms and links that trigger this pretty simple example.
base page code:
<a href="<%=Url.Action(MVC.Temp.GetRTEDialogContent)%>" id="TestSendEmailDialog">Get Dialog</a>
<div id="TestDialog"></div>
<script type="text/javascript">
$('#TestSendEmailDialog').click(function (e) {
e.preventDefault();
var theDialog = buildADialog('Test', 500, 800, 'TestDialog');
theDialog.dialog('open');
theDialog.empty().load($(this).attr('href'), function () {
});
});
function buildADialog(title, height, width, dialogId, maxHeight) {
var customDialog = $('#' + dialogId);
customDialog.dialog('destory');
customDialog.dialog({
title: title,
autoOpen: false,
height: height,
modal: true,
width: width,
close: function (ev, ui) {
$(this).dialog("destroy");
$(this).empty();
},
beforeClose: function (event, ui) {
if (typeof tinyMCE != 'undefined') {
$(this).find(':tinymce').each(function () {
var theMce = $(this);
tinyMCE.execCommand('mceFocus', false, theMce.attr('id'));
tinyMCE.execCommand('mceRemoveControl', false, theMce.attr('id'));
$(this).remove();
});
}
}
});
return customDialog;
}
</script>
and the code of the page loaded into the dialog:
<form id="SendAnEmailForm" name="SendAnEmailForm" enctype="multipart/form-data" method="post">
<textarea cols="50" id="MessageBody" name="MessageBody" rows="10" style="width: 710px; height:200px;"></textarea>
</form>
<script type="text/javascript">
$(function () {
$('#MessageBody').tinymce({
script_url: v2ScriptPaths.TinyMCEPath,
mode: "exact",
elements: 'MessageBody',
theme: "advanced",
plugins: "paste, preview",
paste_retain_style_properties: "*",
theme_advanced_toolbar_location: "top",
theme_advanced_buttons1: "bold, italic, underline, strikethrough, separator, justifyleft, justifycenter, justifyright, justifyfull, indent, outdent, separator, undo, redo, separator, numlist, bullist, hr, link, unlink,removeformat",
theme_advanced_buttons2: "fontsizeselect, forecolor, backcolor, charmap, pastetext,pasteword,selectall, sub, sup, preview",
theme_advanced_buttons3: "",
language: 'EN',
gecko_spellcheck: true,
onchange_callback: function (editor) {
tinyMCE.triggerSave();
}
});
});
</script>
A very interesting thing I noticed, if I translate the tinyMCE setting into a load callback, it seems to work. this is not really a solution because when I load the dialogs I don't know in the code ahead of time if it has tinyMCE controls or not!
source to share