Skip to content
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

Merged
merged 12 commits into from
Feb 14, 2020
Merged

Expose colorbutton#select method #3856

merged 12 commits into from
Feb 14, 2020

Conversation

jacekbogdanski
Copy link
Member

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

  • Unit tests
  • Manual tests

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.

  • PR is consistent with code style guide

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.

Copy link
Member

@Comandeer Comandeer left a 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:

  1. Bender's toolbar hides color buttons by default. Maybe it's way to switch it off?
  2. 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":

var colors = config.colorButton_colors.split( ',' ),
colorToSelect;

for ( var i = 0; i < colors.length; i++ ) {
Copy link
Member

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 ) );

Copy link
Member Author

@jacekbogdanski jacekbogdanski Feb 13, 2020

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 ) {
Copy link
Member

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.

Copy link
Member Author

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)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 👍

Comment on lines 16 to 18
editor.once( 'instanceReady', overwriteUIOpen( 'TextColor' ) );
editor.once( 'instanceReady', overwriteUIOpen( 'BGColor' ) );
editor.once( 'instanceReady', initializeColorSelector );
Copy link
Member

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?

Copy link
Member Author

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.

@jacekbogdanski
Copy link
Member Author

jacekbogdanski commented Feb 13, 2020

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":

Removed, this part didn't make sense as nothing bad happens if editor is not focused except that auto color won't be calculated.

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose color selection method
2 participants