Opened 11 years ago
Closed 11 years ago
#11532 closed New Feature (fixed)
Create editor#addContentsCss() method
Reported by: | Marek Lewandowski | Owned by: | Marek Lewandowski |
---|---|---|---|
Priority: | Normal | Milestone: | CKEditor 4.4.0 |
Component: | General | Version: | |
Keywords: | Cc: |
Description (last modified by )
We should create more convenient way to add custom css files. Now we accept as editor.config.contentsCss
string or array of strings which is ok, but if we want to attach to it extra css styles in plugins, we have to do some extra checking. Such code is redundant.
Method should be editor member, so we will end up with editor.addContentsCss()
. Method itself should be injected from wysiwygarea
plugin, since contentsCss
works only for classic editor.
Method should accept as its parameter a string.
Change History (13)
comment:1 Changed 11 years ago by
Description: | modified (diff) |
---|---|
Milestone: | → CKEditor 4.4 |
Status: | new → confirmed |
comment:2 Changed 11 years ago by
comment:3 Changed 11 years ago by
Owner: | set to Marek Lewandowski |
---|---|
Status: | confirmed → review |
Pushed initial solution to t/11532 at dev and t/11532 at tests.
I belive we should still discuss whether we want to place this method only if wysiwyg plugin is added (which is current implementation).
I think it's bad because programmer needs to write extra code each time when he wants to use it (and needs to be aware of this fact):
editor.addContentsCss && editor.addContentsCss( 'assets/contents.css' )
vs simply:
editor.addContentsCss( 'assets/contents.css' )
The thing is that in inline mode it simply would not take effect.
comment:4 Changed 11 years ago by
Yes, just like config.contentsCss doesn't have any effect on inline, we can make the API stable, always offering this method, but without any effect on inline. Ofc, mentioning this in the docs is mandatory.
comment:5 follow-ups: 6 7 Changed 11 years ago by
IMO this option is better:
editor.addContentsCss && editor.addContentsCss( 'assets/contents.css' )
because it's visible then that it's a conditional execution. The same situation as with addButton, contextMenu, etc. Note that in this case, the entire duet config.contentsCss + editor.addContentsCss will be introduced by wysiwygarea plugin. Not by core + plugin in opposite situation.
comment:6 Changed 11 years ago by
Replying to Reinmar:
Well, considering this as a non-core feature, what you says makes sense.
comment:7 Changed 11 years ago by
Replying to Reinmar:
Ok, so branch currently is in this state and ready for review.
comment:8 follow-up: 9 Changed 11 years ago by
Status: | review → review_failed |
---|
- I pushed a commit fixing doc string.
- Method should be moved to editor's prototype. In current solution it's not available before wysiwygarea's init is executed and editor instances don't share them, so it's heavier for memory.
- Why checking with negation?
cfg.contentsCss = !curContentsCss ? [] : [ curContentsCss ]
- There's a new line missing after last assertion .
comment:9 Changed 11 years ago by
Status: | review_failed → review |
---|
Replying to Reinmar:
Repushed t/11532 with fixes.
Can you apply docfix to current branch once again, please? I've mistakenly skipped pull before applying changes.
- Why checking with negation?
cfg.contentsCss = !curContentsCss ? [] : [ curContentsCss ]
It's simplier to understand - if there's no val in curContentsCss, use empty array - otherwise wrap value within array.
comment:10 Changed 11 years ago by
Can you apply docfix to current branch once again, please? I've mistakenly skipped pull before applying changes.
I force pushed my previous branch. Overriding your fixes... sorry :D I should've first think. So you need to apply them again.
It's simplier to understand - if there's no val in curContentsCss, use empty array - otherwise wrap value within array.
I could write the exact opposite. Please remove the superfluous negation.
comment:11 Changed 11 years ago by
Changes applied. Could you take a look to updated docs:
* Adds given path to a stylesheet file to the exisiting {@link CKEDITOR.config#contentsCss} value.
I guess that we should still update it to sth like:
* Adds given stylesheet file path to the exisiting {@link CKEDITOR.config#contentsCss} value.
comment:12 Changed 11 years ago by
Status: | review → review_passed |
---|
R+ and your proposal regarding docs is better, so you can change it. Remember about squashing commits.
comment:13 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | review_passed → closed |
Merged with git:dcd4e97de870 to dev and f91f1e8e68313 at tests.
When writing a widget, I found attaching an external stylesheet not obvious. I found the below snippet working for an iframed instance:
I second the vote to have a method to append reference to a css file. I think many users would appreciate also more documentation as per the appropriate handler to act in (see http://stackoverflow.com/questions/21556106/ckeditor-widget-how-do-i-attach-css-in-onload)