I have a style sheet that gets appended using
editor.on('instanceReady', function () {
this.document.appendStyleSheet(cssPath);
});
I have it set the background color to green so I can easily see that its working. When i click on the Source button and then switch back the background is no longer green. Checking the source code, my stylesheet is no longer there as well. Is there a better way to append style sheets or a hook that would be called everytime the editor is put into rich text mode?
stylesheet in <head>
Seems you have the stylesheet inside the editing area ???
If you call in in the <head> of the page, I don't see how CKEditor should be able to remove it.
Yeah its super weird. My
Yeah its super weird. My solution i figured out is this:
contentsCss.push() only works after the rich text mode is renabled and appendStyleSheet() only works when its first initilized. No clue how or why this happens, it isnt very logical.
It is very logical, but it
It is very logical, but it requires some knowledge how CKEditor works.
You listen to instanceReady event. It's fired after everything was set up and therefore changing configuration option at this point makes no difference - the option has already been used. However, it will be used again when switching between modes, because every time you do that entire editable area is being rebuilt from scratch.
Then, appending stylesheet to document has an immediate effect, because it's not a config option - it's a live DOM operation. But it works only once because you execute it once - after editor is ready.
The event you're looking for is editor#contentDom. It's fired every time editable area is rebuilt. However, you must add it quickly (on instanceReady is too late). For example you can do this right after creating editor instance:
Piotrek (Reinmar) Koszuliński
CKEditor JavaScript Developer
--
CKSource - http://cksource.com
--
Follow CKEditor on: Twitter | Facebook | Google+
Hello,
Hello,
Thanks for explaining the difference between the config and dom elements, makes a lot more sense now. I downloaded another plugin and looked at their source to find the contentDom listener.
What I ended up doing is
Posting that incase anyone is ever looking how to add a stylesheet with other attributes. In my case I had to add an ID so I could easily disable and enable the style sheet with jquery.