I was searching around for some info and came acrross this archived bit of discussion.
http://www.ozoneasylum.com/18264?threadOption=noPages
Currently I have a small rich text editor and have been using the method DmS described (with execCommand etc). The limitation of this being IE only, otherwise it works quite well.
What I am curious about is the method below which pugzly used... was just wondering how (if at all) it could handle overlapping tags etc. For example using the execCommand method, if we have a string.
"This is a test String"
if I was to highlight String and bold it ("This is a test String") then the html behind it would have <b>String</b>
If however i then went and highlighted the whole string and applied bold, using execCommand it adjusts the HTML automatically and you would still only have one set of <b> tags - which is fine. <b>This is a test String</b>
With the method below however, from what i can tell, you would end up with <b>This is a test <b>String</b></b> , doubling up on the tags. Am I thinking correctly with this, or am I missing something?
The code pugzly suggested is below:
quote:
All we do is make a textarea with the body of the article in it. Above the textarea are various buttons such as
<input type="button" value="B" onclick="hiliteToBold(body);" style="font-weight: bold" title="Make the highlighted text bold." />
And that calls this simple function:
function hiliteToBold(txtArea){
txtAreaName = txtArea.name;
txtRange = document.all[txtAreaName].createTextRange();
txtContainer = txtRange.parentElement().name;
objRange = document.selection.createRange();
hiliteTxt = objRange.text;
toBoldTxt = "<b>" + hiliteTxt + "</b>";
if(hiliteTxt != ""){ objRange.text = toBoldTxt;
}
}
We have them for various effects like bold, italics, line breaks, font sizes, and smart quotes
It's simple, easy to add to, and doesn't leave the content editors in the dark.
Thanks all