views:

237

answers:

3

Hi All,

I'm currently working with CKEditor (http://ckeditor.com/). I'm looking for:

1) an exhaustive list of commands available by default via 'execCommand'.

2) a mechanism by which to set styles (as in the same way the FONT and SIZE combo boxes do it). I saw the function called 'setStyle' in the documentation, however it seems to require an exact element. I can't for the life of me figure out how to do so based on the selection -- there is no way to use ID or CLASS, as the selected portions have none.

I've posted to the forums but they don't seem to be terribly active as far as replies are concerned. Any assistance would be most appreciated.

Best.

A: 

I have not used the execCommand, but from my understanding you can execute anything that is in the toolbar.

editor.execCommand( "div" );
editor.execCommand( "bold" );

To set style add this to you config.js file.

CKEDITOR.editorConfig = function(config) {
    CKEDITOR.addStylesSet('customStyles',
    [
        { name: 'Header 1', element: 'h1' },
        { name: 'Header 2', element: 'h2' },
        { name: 'Header 3', element: 'h3' },
        { name: 'Text', element: 'p' },
        { name: 'Left Align', element: 'img', attributes: { 'class': 'ImageLeft'} },
        { name: 'Right Align', element: 'img', attributes: { 'class': 'ImageRight'} }
    ]);
};
Dustin Laine
Thanks for the post durilai. However, I'm looking to execute the changes directly in Javascript. I'm not planning to use their default buttons. I'm actually hooking into it from a desktop application. I have the ability to execute javascript on the fly, and I need to be able to execute the changes manually.
humble_coder
A: 

best thing I can recommend is to to look at the javscript api

ok with a little research some trial and error I was able to change the font color

 $('#test').click(function (){
 //   fck is the instace name of the editor
    editor = CKEDITOR.instances.fck;
    var selected_text = editor.getSelection().getNative();
 // editor.insertHtml('[foo]' + selected_text + '[bar]');
    var element = editor.getSelection().getStartElement();
    element.setStyle( 'color', '#ff0000' );
 })

just got to put in a little elbow grease to get what you want my friend.

mcgrailm
Thanks, but I've already scoured it.
humble_coder
note I used jquery and button input to trigger
mcgrailm
did you try this out?
mcgrailm
Yes. I got it to work. However, I see three issues:1) I'm not interested in acquiring an "element" so much as the general selection. If I'm understanding "getStartElement" correctly then it grabs the entire encompassing tag/element -- I only want the exact text selection.2) I certainly don't want to insert HTML as I may need to remove it during follow-up edits.3) jQuery edits preclude the ability to UNDO. So this might not be the greatest option.Thanks so much for your willingness to assist, btw.
humble_coder
CORRECTION: #3 doesn't seem to be an issue. It appears to be more of a timing/delay issue. Anyway, the rest stands.
humble_coder
I see what you mean there has to be a way to do this we just don't know what the correct path is
mcgrailm
+1  A: 

You can do a little search in the _source folder for ".addCommand" and that will give you a full list of all commands that can be executed on an editor. I guess that you are interested only in a part of that list, as some are meant for internal use.

AlfonsoML
Hrm, did that but it wasn't much help. Perhaps if someone could provide an example of how to, say, change the FONT or COLOR of a selection, I could extrapolate from the example. As it stands (and as is often the case with items of this nature) none of the documentation covers *any* edge cases. Thanks though!
humble_coder
That should provide all the commands that you requested in your first question, I didn't mention anything about styles. The documentation can't cover edge cases, at least it must cover properly the common use cases first, and when that part is ready and everything works as expected then maybe it's time to improve the docs with edge cases.Meanwhile, the source is the best documentation as it really shows how things are done.To set a style you can start by looking at the "basicstyles" plugin
AlfonsoML
I understand what you're saying. However, what I need involves more than basic styling. I need to provide both the ITEM I wish to adjust, as well as its VALUE -- not simply BOLD or ITALIC, etc. Based on the current implementation I'd have to provide a specific function for each FONTSIZE, which doesn't seem right. Perhaps I can genericize it.
humble_coder
The styles system allows that. After understanding how the basicstyles plugin works, look at the font or stylescombo plugin (and the stylesSet defined by default)
AlfonsoML
Ok, I'm not afraid to admit I'm COMPLETELY missing something. However, what I need is to be able to apply formatting on the fly. Creating a "style" for each and every permutation (e.g. font-size 10, font-size 11, font-size 12, etc.) is not reasonable. Therefore, I need CKEDITOR.selection (or whatever is available) to return something useful to me so as to edit.
humble_coder
Why isn't reasonable? If you don't want to keep them precomputed, then you create one on the fly and throw it away.
AlfonsoML