This is the second post about CKEditor, be sure to read first the prerequisites to use CKEditor.
As explained in the integration guide you must add the CKEditor library to the head of your document. I would like to add a little remark for the moment: instead of ckeditor.js you can use ckeditor_basic.js if you don't need the features before the page is loaded, it will load only a small stub and delay the full load to make the page ready quicker. I explain this feature in detail here.
So go ahead and add it:
Now the CKEDITOR object is ready to be used in your page. This is the entry point for all the CKEditor functionality.
The most common situation is to use a textarea for your content and replace it with CKEditor:
Ok, so far I haven't said anything interesting, but I think that it's better to start step by step, reviewing what's available before explaining new things. So the next step is to look at the CKEDITOR object.
You just need to add the class "ckeditor" to you textareas and you're done! Look at the _samples/replacebyclass.html file.
If you want to the magic to work with other class names then you must use the replaceClass property. This is how your page would look if you have already some textareas with the class "html" and you want to use now CKEditor without any further changes:
As you can see, with minimal changes to your existing pages you can use CKEditor.
Other times you might want to use CKEditor in all the textareas of your page, no matter what are their classes. Then replaceAll is your friend. As the replace call, you must use it only after your textarea, or if you must add it in the head of the document, use the document "onload" event (be careful: if you assign directly document.onload other script might want to also use it in the same "stupid" way and will erase your listener, or you could erase that other listener)
In fact, the replaceClass and replaceByClassEnabled is just some syntactic sugar to easily use the replaceAll at page load with a className.
The replaceAll method can be called in three ways:
- No parameters: All the textareas are replaced
- A string parameter: Only the textareas that have their class matching that parameter will be replaced
- A function parameter: This is the most powerful option, each textarea will be passed to that function, along an empty config object that can be used to apply custom configuration options to each instance.
So if you want to replace all the textareas in the page, except those that have a class of "text" or whose id is "summary" you should use this code at the end of the page (or on the onload event):
Finally there's the appendTo method, but for the moment I
can't figure out why that is interesting, so I won't bother to explain it