Hi all. I've been using WYMeditor for a while now, it's a great editor. However, I'm stuck with something that should be pretty simple, even for a newbie like me. I've wrote a couple of custom buttons and all that part is done. There's one thing, however, that is drving me nuts. One of these buttons needs to take whatever text is selected by the user, do some formatting on it, then replace the original text in the editor. So far, I got it half-working. The problem is that I cannot found (and I've searched for hours in both the documentation and this forum) a simple, reliable method to get the selected text passed to my function. I'm aware of html() and xhtml(), but these methods retrieve the whole contents of the editor. I just need the part that is selected, and the important bit, even if the selection spans through several blocks (for example, if you have more than one paragraph highligted). I found a method that seemed to be working (just showing the relevant code):
- Code: Select all
var container = wym.selected();
var txt = $(container).html();
var output = my_custom_function(txt);
wym.insert(output);
But in this case $(container).html() returns only the text inside the first selected block. So, there's a way to iterate over all selected elements, or there's some magic method to do this simple task that I'm overlooking?
Many thanks in advance!
A desperate, sleepless developer.