I'd like to create a drop down of links above the editor that, when changed, immediately links the selected text to the chosen link. We were able to accomplish this fairly simply with FCKEditor using the internal CreateLink command, but I'm having trouble locating its counterpart in the CKEditor API docs.
old way: FCK.ExecuteNamedCommand( 'CreateLink', theUrl ) ;
Can anyone suggest a way to do this with CKEditor?
Many thanks,
Ryan
old way: FCK.ExecuteNamedCommand( 'CreateLink', theUrl ) ;
Can anyone suggest a way to do this with CKEditor?
Many thanks,
Ryan
Re: CreateLink alternative in CKEditor / CMS Integration
Re: CreateLink alternative in CKEditor / CMS Integration
Hi simshaun, I think you're right. This is really just to continue to support a feature we've had for a while. We do get a lot of positive feedback about this from users as it allows one-click link creation to any page in their site. Nevertheless, it's messy because it's not even in the editor -- it sits up above it when it should really be a plugin with a spot in the toolbar. Logically, it should also exist in the link dialog. Maybe one day.
Anyway, I did cobble some code that seems to work, though it's untested and certainly not refined. I'll leave it here for anyone else who might need it. (Of course, making sure that CKEDITOR.instances.MYINSTANCENAME actually references the editor.)
// Delete any existing links on the selected text
// I'd rather use the unlinkCommand function, but I can't get it working properly
CKEDITOR.instances.MYINSTANCENAME.document.$.execCommand( 'unlink', false, null );
// Create a new link
var attributes = Array();
attributes["href"] = "http://www.TheUrl.com";
var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
style.type = CKEDITOR.STYLE_INLINE;
style.apply(CKEDITOR.instances.MYINSTANCENAME);
Re: CreateLink alternative in CKEditor / CMS Integration
The code by rchuber works good in Firefox, but not in IE.
We've been trying to implement such function based on FCK CreateLink source, but there are some differences between 2 and 3 API versions.
For example, how we can get selection object and then remove it from DOM (if current selection type is CKEDITOR.SELECTION_TEXT)?