Hi, I was looking to add a css id and/or class to the editor contents ala FCK 2:
http://docs.cksource.com/FCKeditor_2.x/ ... _BodyClass
I found the bug/feature post, now planned for CKE 3.1:
http://dev.fckeditor.net/ticket/4342
http://dev.fckeditor.net/ticket/4067
The functionality to include the body class and id is already present in the 3.0 code (conditional adding of id with editor.document.getBody().getAttribute('id'), etc), but I was unable to find any documentation on how to set these when building the editor. Looking at the on: instanceReady function mentioned here:
http://docs.cksource.com/CKEditor_3.x/D ... Formatting
I was able to find a temporary solution that I am using:
CKEDITOR.on('instanceReady', function(ev) { ev.editor.document.getBody().setAttributes({ 'class': 'someclass', 'id': 'someid' }); });
And since I use an external config script, I just added the above to the end of that and it works. If I set these in the config function itself then, like:
config.bodyId = 'someid';
config.bodyClass = 'someclass';
I can call this instead at the end:
CKEDITOR.on('instanceReady', function(ev) { ev.editor.document.getBody().setAttributes({ 'class': ev.editor.config.bodyClass, 'id': ev.editor.config.bodyId }); });
Which I'm now hoping to incorporate more directly into the source code. I need to find some point in ckeditor where the body is created and attached to the document object that is created and attached to the editor object. There should be some point where the last piece of all that drops into place and I want to add the above code to set the attributes based on the editor's config at that point.
To look for that place, I did a search for "customConfig" through the cke source and found _source/core/editor.js that actually sets the editor's config with the data from a custom config (and in-page config as well?) in onConfigLoaded, where I'd like to add this to the original source, thinking it'd go there:
editor.document.getBody().setAttributes({
class: editor.config.bodyClass,
id: editor.config.bodyId });
Which in the release/minified version ckeditor.js is right before "x.fireOnce('configLoaded');" (search for it, there's only one) and I tried inserting this just before that:
x.document.getBody().setAttributes({class:x.config.bodyClass,id:x.config.bodyId});
But that throws an error because the editor (x in that function) has no document to call getBody on yet. Can anyone tell me where I'd find the point in the code where the document object has been attached to the editor object and the body has been created/attached as well, so I could then set these attributes on the editor body there?
Thanks.
Thu, 10/29/2009 - 20:01
#1
Re: setting body id and class from config
Re: setting body id and class from config
What I was looking for is where I can get those config variables set into the body's class and id by the editor code itself rather than needing to do a universal or editor at a time change in an on:instanceReady function myself.
I don't necessarily want to edit the official source code myself, but I was hopeful that with the idea of where to put this code, I could figure out how to fix it myself and submit the change for a sooner to be released version than 3.1, so it'd be ready for others to use as well already.
I love ckeditor 3.0. It is a truly excellent tool, so thanks for making it available like this.