-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose colorbutton#select method #3856
Conversation
62ac76b
to
fc726b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, only some minor refactors in code and two issues:
- Bender's toolbar hides color buttons by default. Maybe it's way to switch it off?
- I wonder why correct behavior of the
select
method depends on editor focus. If I don't focus the editor first, color button will be always pointing to the "Automatic":
plugins/colorbutton/plugin.js
Outdated
var colors = config.colorButton_colors.split( ',' ), | ||
colorToSelect; | ||
|
||
for ( var i = 0; i < colors.length; i++ ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have CKEDITOR.tools.array#find()
method – it should increase the readability of this code.
In fact it would allow to pass callback
directly to colors
:
var colorToSelect = normalizeColor( CKEDITOR.tools.array.find( colors, callback ) );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was something wrong with this code but I couldn't catch up what (had some brain fart yesterday). Obviously, the find method, thanks 😄
@@ -154,6 +154,23 @@ CKEDITOR.plugins.add( 'colorbutton', { | |||
attributes: { role: 'listbox', 'aria-label': lang.panelTitle } | |||
}, | |||
|
|||
select: function( callback ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API docs for the new method are missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about namespace of the docs 🤔 Probably CKEDITOR.ui.colorButton
would be best but I'm not a fan of introducing empty namespace for this single private method. WDYT about just private docs i.e. commented out with //
(so commenting private functions according to https://github.com/ckeditor/ckeditor4/blob/major/dev/docs/codestyle.md#210-comments)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good 👍
editor.once( 'instanceReady', overwriteUIOpen( 'TextColor' ) ); | ||
editor.once( 'instanceReady', overwriteUIOpen( 'BGColor' ) ); | ||
editor.once( 'instanceReady', initializeColorSelector ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't it be joined into one listener?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can, I just like to pass callbacks by reference, so it's more readable. But I'm fine for merging it into a single listener.
👍
Removed, this part didn't make sense as nothing bad happens if editor is not focused except that auto color won't be calculated. |
…eclared colors from configuration option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
What is the purpose of this pull request?
New feature
Does your PR contain necessary tests?
All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.
This PR contains
Did you follow CKEditor 4 code style guide?
Your code should follow guidelines from CKEditor 4 code style guide which helps keep the entire codebase consistent.
What is the proposed changelog entry for this pull request?
Not required as it's an internal change.
What changes did you make?
Introduced new color button selection method. Due to fact that it's unlikely this method will be used by community, let's keep it internal for now, as public API would require more complicated refactoring of the colorbutton plugin.
Which issues your PR resolves?
Closes #3743.