emukie's picture
Joined: 15/09/2009
Posts: 4
Inserting html around selected text
If some text is selected, the link is made. However the selected text/link gets moved to the start of the alinea. If no text is selected, the link is placed at the right position.

My current code:
var temp = new CKEDITOR.dom.element( 'span' );
temp.append(editor.getSelection().getRanges()[ 0 ].cloneContents());
if(temp.getText() == "")
{
   editor.insertHtml('<a href=\"' + file_link + '\">' + file_link + '</a>');    
}
else
{
   editor.insertHtml('<a href=\"' + file_link + '\">' + temp.getText() + '</a>');  
}


Any suggestions?
emukie's picture
Joined: 15/09/2009
Posts: 4
Re: Inserting html around selected text
Anyone?
garry.yao's picture
Joined: 03/01/2009
Posts: 170
Re: Inserting html around selected text
FYI, There's a even more simple way to achieve this:
// Apply style.
var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
style.type = CKEDITOR.STYLE_INLINE;      // need to override... dunno why.
style.apply( editor.document );