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

Added CKEDITOR.config.image2_maxSize #2683

Merged
merged 26 commits into from
Feb 7, 2019
Merged

Added CKEDITOR.config.image2_maxSize #2683

merged 26 commits into from
Feb 7, 2019

Conversation

engineering-this
Copy link
Contributor

@engineering-this engineering-this commented Dec 17, 2018

What is the purpose of this pull request?

New feature + Bugfix

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

What changes did you make?

  • Added new config option CKEDITOR.config.image2_maxSize that limits maximum size that image can be resized with resizer.
  • Fixed resizer mousemove listener to update widget data with last correct value which is same as one set on element.

Closes #2048
Closes #2672
Closes #2714

@Comandeer Comandeer self-requested a review December 27, 2018 09:12
@Comandeer Comandeer self-assigned this Dec 27, 2018
plugins/image2/plugin.js Show resolved Hide resolved
updateData = true;
} else {
updateData = false;
if ( isAllowedSize() ) {
Copy link
Member

Choose a reason for hiding this comment

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

IMO it would be more readable if isAllowedSize required new width and height as parameters.

maxSize = CKEDITOR.tools.copy( maxSize );
natural = CKEDITOR.plugins.image2.getNatural( image );

maxSize.width = Math.max( maxSize.width === 'naturalWidth' ? natural.width : maxSize.width, min.width );
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't be better to accept natural as a keyword? It'd be the same for both width and height.


function isAllowedSize() {
var isTooSmall = newWidth < min.width || newHeight < min.height,
isTooBig = max && ( ( max.width && newWidth > max.width ) || ( max.height && newHeight > max.height ) );
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't the existence of max mean that both width and height has to be declared?

@@ -0,0 +1,31 @@
@bender-tags: 4.12.0, feature, bug
Copy link
Member

Choose a reason for hiding this comment

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

Please add issues numbers.

Copy link
Member

Choose a reason for hiding this comment

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

OTOH it seems a little bit strange to test both feature and bug in one test.

bot.setData( '<img src="%BASE_PATH%/_assets/logo.png">', function() {
var image = editor.editable().findOne( 'img' );

if ( CKEDITOR.env.chrome ) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this branch necessary? For the sake of the simplicity, Chrome can also wait for image.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually at this point Chrome unlike other browsers has image loaded, and waitForImage triggers on load event which won't happen in Chrome (#2714).

@@ -0,0 +1,15 @@
@bender-tags: 4.12.0, feature, bug, 2672
Copy link
Member

Choose a reason for hiding this comment

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

After splitting test into two separate ones, declaring them as feature & bug is no longer needed – one is for feature and one is for bug.


## Expected:

Dialog fields are populated with correct width/height.
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear, which values are correct and which are not.

};

var tests = {
//2672
Copy link
Member

Choose a reason for hiding this comment

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

Our convention for such comments is // (#<issue number>).

},

// #2714
'test waitForImage when image is loaded': function() {
Copy link
Member

Choose a reason for hiding this comment

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

This test should not be here, as it's connected to the test helper, not to the plugin itself. In fact helpers usually don't have tests.

@engineering-this
Copy link
Contributor Author

  • Updated manual test.
  • waitForImage unit test extracted to separate file.
  • Made waitForImage callback call asynchronous when image is loaded early.

@Comandeer Comandeer self-assigned this Feb 7, 2019
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
2 participants