Hi all,
Would anyone have an idea how to detect what current <span> style tag is in effect at any given time? More specifically, if i clicked somewhere in the content editor, then performed a 'keydown', is there a way to grab the relevant <span> style tag (if any) that will be applied to the string being entered in the content area? In my case i just need to know how to get the <span> tag to the "left" of the current cursor position.. again, thank you very much for your time!
Would anyone have an idea how to detect what current <span> style tag is in effect at any given time? More specifically, if i clicked somewhere in the content editor, then performed a 'keydown', is there a way to grab the relevant <span> style tag (if any) that will be applied to the string being entered in the content area? In my case i just need to know how to get the <span> tag to the "left" of the current cursor position.. again, thank you very much for your time!
RE: detecting current <span> tags
For this I wrote a "HOWTO - Work with the selection in the editor", see https://sourceforge.net/forum/forum.php ... _id=257180
RE: detecting current <span> tags
Thanks again saul
The solution turned out to be fairly simple, but no surprise there.
The goal was to wrap text automatically with span tags. In this case we wanted to automatically highlight anything the user typed into the editor, but this can be extended to any type of span. The solution ended up looking like this:
if (!(e.keyCode>=16&&e.keyCode<=18)) {
var SpecialClass = "<class name here>";
var rng=FCK.EditorDocument.selection.createRange();
var rngTag=rng.parentElement().tagName;
var rngClass = rng.parentElement().className;
if (!(rngTag == "SPAN" && rngClass == SpecialClass)){// is this the special span tag
// no span tag, thus we wrap the span tag around this charecter
rng.expand("character");
rng=FCK.EditorDocument.selection.createRange();
rng.pasteHTML("<span class="+SpecialClass+">x</span>");
rng.moveStart('character',-1);
rng.select();
}
Doc_OnKeyDownUndo();
}
"SpecialClass" is the name of the type of style (in the stylesheet) you want to use, and the code is placed within fckeditorcode_xx.js.