I have a problem. I tried to do this for a while, and I'm ready to explode. Here is my requirement:
I have an external toolbar (not part of the YUI) above the editor that I want to use to insert HTML tags. The user should be able to click the link on the toolbar, after which several things can happen:
- If there is selected text, this text will be transferred to the HTML tag
- If there is no selected text, an empty empty HTML tag in the editor
- Regardless of the scenario, the cursor MUST be placed inside the new element, so when the user enters more text, it is in the new element
The functionality is very similar to the functionality of pressing the "B" or "U" buttons on the editor toolbar (now, when I use this editor, it also works well :-)). He perfectly saves everything. So far I can do 1 or 2, but not 3. Step 3 is VERY important, because without it the user experience suffers a lot. I really need your help to implement it. The following is a simplified version of the method that performs the insertion (just pasting the DIV for simplicity). this._oEditor is a local instance of the YUI editor:
this._insertElement = function() {
var sSelection = this._oEditor._getSelection();
if (sSelection == '') sSelection = ' ';
var sNewElt = '<div>' + sSelection + '</div>';
this._oEditor.execCommand('inserthtml', sNewElt);
this._oEditor.focus();
}
What should I do to put the cursor in the right position? Is it possible? Also, if there is a better way to implement this, I am all for it. Thanks!
source
share