Thanks, John, but I am really lost. Here is the code that I have so far:
Code:
function start_JEMpad(){
//JEMPAD is the id of a textarea
document.getElementById("JEMPAD").style.display = "none";
var pad = document.createElement("IFRAME");
pad.name = pad.id = "JEMp";
if(pad.addEventListener){
pad.addEventListener("load",function(e){this.contentWindow.document.designMode = "on";}, false);
}else if(pad.attachEvent){
pad.attachEvent("load", function(e){this.contentWindow.document.designMode = "on";});
}
document.body.insertBefore(pad, document.getElementById("JEMPAD"));
JEMp.document.designMode = "on";
JEMp.document.open();
JEMp.document.write('<html>\n\t<head>\n\t\t<style type="text/css">\n\t\t\tbody{ font-family:arial; font-size:13px; }\n\t\t</style>');
JEMp.document.write('\n\t</head>\n\t<body>\n\t</body>\n</html>');
//I tried adding JS functions in here too, but they don't seem to work since the IFrame in in design mode
JEMp.document.close();
JEMp.focus();
JEMp.document.body.innerHTML = formattext(document.getElementById("JEMPAD").innerHTML);
try{
JEMp.document.body.attachEvent("onkeyup", update_pad, false); //triggers error in FF unless I use try/catch
}catch(e){
JEMp.addEventListener("keyup", update_pad, false);
}
}
function setCursorPosition(oInput,oStart,oEnd) {
if( oInput.setSelectionRange ) {
oInput.setSelectionRange(oStart,oEnd);
}
else if( oInput.createTextRange ) {
var range = oInput.createTextRange();
range.collapse(true);
range.moveEnd('character',oEnd);
range.moveStart('character',oStart);
range.select();
}
}
function update_pad(){
JEMp.document.body.innerHTML = formattext(JEMp.document.body.innerHTML); //PUSHES CURSOR TO END OF IFRAME
//How do I capture the cursor's previous position and put it back? (obviously the capture would need to be before the previous line)
setCursorPosition(document.getElementById("JEMp"),1,1); // I obviously need to use this, but it's not working
}
function formattext(string){
return string;
}
function decompiletext(string){
return string;
}
function addtag(tag1, tag2){
//How do I do this?
}
Two questions on the above: 1) how do I capture the caret position and put it back after I format the IFrame, 2) how do I insert text at the insertion point? (i.e. the user highlights "Hello" and clicks bold, so the text becomes "[b]Hello[/b]". This would then be processed by the formattext() function and become XHTML-- I already have that part done.)
Any help/suggestions would be amazing. I know it's asking a lot.
Bookmarks