Hello,
I'm working on a WYSIWYG text editor and I'm working on the ability to switch between the WYSIWYG mode and BBcode mode. I'm having trouble getting it to display back in WYSIWYG mode after you make the switch.
function editormode()
{
var html;
var bbcode = new Array();
var htmlcode = new Array();
htmlcode[0] = "<b>"; bbcode[0] = "[b]";
htmlcode[1] = "</b>"; bbcode[1] = "[/b]";
htmlcode[2] = "<i>"; bbcode[2] = "[i]";
htmlcode[3] = "</i>"; bbcode[3] = "[/i]";
htmlcode[4] = "<u>"; bbcode[4] = "[u]";
htmlcode[5] = "</u>"; bbcode[5] = "[/u]";
htmlcode[6] = "<strike>"; bbcode[6] = "[strike]";
htmlcode[7] = "</strike>"; bbcode[7] = "[/strike]";
htmlcode[8] = "<sub>"; bbcode[8] = "[sub]";
htmlcode[9] = "</sub>"; bbcode[9] = "[/sub]";
htmlcode[10] = "<sup>"; bbcode[10] = "[sup]";
htmlcode[11] = "</sup>"; bbcode[11] = "[/sup]";
if (editormode == "true") {
htmltext = document.getElementById('editor').contentWindow.document.body.innerHTML;
for(i = 0; i < 12; i++){
searchtext = htmltext.search(htmlcode[i]);
if(searchtext != -1) {
htmltext = htmltext.replace(htmlcode[i], bbcode[i]);
}
}
html = document.createTextNode(htmltext);
document.getElementById('editor').contentWindow.document.body.innerHTML = "";
html = document.getElementById('editor').contentWindow.document.importNode(html,false);
document.getElementById('editor').contentWindow.document.body.appendChild(html);
editormode = "false";
} else {
htmltext = document.getElementById('editor').contentWindow.document.body.innerHTML;
for(i = 0; i < 12; i++){
searchtext = htmltext.search(bbcode[i]);
if(searchtext != -1) {
htmltext = htmltext.replace(bbcode[i], htmlcode[i]);
}
}
html = document.createTextNode(htmltext);
document.getElementById('editor').contentWindow.document.body.innerHTML = "";
html = document.getElementById('editor').contentWindow.document.importNode(html,false);
document.getElementById('editor').contentWindow.document.body.appendChild(html);
editormode = "true";
}
}