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

i/5201: Add ImageResizeUI plugin. #7482

Merged
merged 26 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c7de16e
Init ImageResizeUI component
panr Jun 19, 2020
f4e1ac6
Add manual test.
panr Jun 23, 2020
392af13
Add unit test.
panr Jun 23, 2020
14bbc50
Make a proper plugin architecture.
panr Jul 3, 2020
3a873d4
Fix "def" shorthand.
panr Jul 3, 2020
55cf69b
Assign command.value on command execution.
panr Jul 3, 2020
dd634b8
Remove #_resizeUnit.
panr Jul 3, 2020
d73cda7
Extend the component tooltip message.
panr Jul 3, 2020
b8bdc73
Update manual test sample image and description.
panr Jul 3, 2020
e0f4ebb
Refactor unit tests for ImageResizeUI.
panr Jul 3, 2020
2184c01
Merge branch 'master' into i/5201
panr Jul 3, 2020
e110e01
Update contexts.
panr Jul 3, 2020
9e55ce3
Update ImageResizeUI plugin.
panr Jul 3, 2020
1d0788d
Update ResizeImage plugin.
panr Jul 3, 2020
34ed7cc
Update ImageResizeUI.
panr Jul 3, 2020
ac6e954
Update tests.
panr Jul 3, 2020
2410ff3
Remove plugin icon. This will have a follow-up.
panr Jul 6, 2020
076892e
Update manual test.
panr Jul 6, 2020
9b80a13
Update feature docs.
panr Jul 6, 2020
54e0687
Remove redundant test.
panr Jul 6, 2020
bbea228
Fix code style in resize options.
jodator Jul 7, 2020
d91150d
Fix code style in resize options.
jodator Jul 7, 2020
15eb996
Fix incorrect tooltip text when option's value is set to `null`.
panr Jul 7, 2020
1df5fbb
Add unit test for the tooltip of the dropdown button view.
panr Jul 7, 2020
686c333
Fix the plugin file structure and API documentation.
panr Jul 7, 2020
1229fd9
Refactor reset option button tooltip.
panr Jul 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div id="snippet-image-resizeui">
<h3>Resize me using image toolbar buttons!</h3>

<figure class="image">
<img src="%BASE_PATH%/assets/img/fields.jpg" alt="Autumn fields">
<figcaption>Autumn fields by Aleksander Nowodziński</figcaption>
</figure>

<h3>Resized image (width: 75%):</h3>

<figure class="image image_resized" style="width:75%;">
<img src="%BASE_PATH%/assets/img/fields.jpg" alt="Autumn fields">
</figure>
</div>
49 changes: 49 additions & 0 deletions packages/ckeditor5-image/docs/_snippets/features/image-resizeui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* globals ClassicEditor, console, window, document */

import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config.js';

ClassicEditor
.create( document.querySelector( '#snippet-image-resizeui' ), {
removePlugins: [ 'LinkImage' ],
toolbar: {
viewportTopOffset: window.getViewportTopOffsetConfig()
},
image: {
resizeOptions: [
{
name: 'imageResize:original',
label: 'Original size',
value: null
},
{
name: 'imageResize:50',
label: '50%',
value: '50'
},
{
name: 'imageResize:75',
label: '75%',
value: '75'
}
],
toolbar: [
'imageStyle:full',
'imageStyle:side', '|',
'imageResize:original',
'imageResize:50',
'imageResize:75'
]
},
cloudServices: CS_CONFIG
} )
.then( editor => {
window.editorResizeUI = editor;
} )
.catch( err => {
console.error( err );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div id="snippet-image-resizeui-dropdown">
<h3>Resize me using the dropdown!</h3>

<figure class="image">
<img src="%BASE_PATH%/assets/img/fields.jpg" alt="Autumn fields">
<figcaption>Autumn fields by Aleksander Nowodziński</figcaption>
</figure>

<h3>Resized image (width: 75%):</h3>

<figure class="image image_resized" style="width:75%;">
<img src="%BASE_PATH%/assets/img/fields.jpg" alt="Autumn fields">
</figure>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* globals ClassicEditor, console, window, document */

import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config.js';

ClassicEditor
.create( document.querySelector( '#snippet-image-resizeui-dropdown' ), {
removePlugins: [ 'LinkImage' ],
toolbar: {
viewportTopOffset: window.getViewportTopOffsetConfig()
},
image: {
resizeOptions: [
{
name: 'imageResize:original',
label: 'Original size',
value: null
},
{
name: 'imageResize:50',
label: '50%',
value: '50'
},
{
name: 'imageResize:75',
label: '75%',
value: '75'
}
],
toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageResize' ]
},
cloudServices: CS_CONFIG
} )
.then( editor => {
window.editorResizeUIDropdown = editor;
} )
.catch( err => {
console.error( err );
} );
63 changes: 63 additions & 0 deletions packages/ckeditor5-image/docs/features/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,71 @@ The [image styles](#image-styles) feature is meant to give the user the choice b

It is implemented by the {@link module:image/imageresize~ImageResize} plugin and enables four "resize handles" displayed over the selected image. The user can freely resize the image by dragging them. The feature can be configured to use either percentage (default) or pixel values.

The plugin also gives you an ability to change the size of the image through the image toolbar. You can set an optional static configuration with {@link module:image/image~ImageConfig#resizeOptions} and choose whether you want to use a dropdown or set of the standalone buttons.

### Resize image using handles

{@snippet features/image-resize}

### Resize image using the plugin dropdown

```js
const imageConfiguration = {
resizeOptions: [
{
name: 'imageResize:original',
label: 'Original size',
value: null
},
{
name: 'imageResize:50',
label: '50%',
value: '50'
},
{
name: 'imageResize:75',
label: '75%',
value: '75'
}
],
toolbar: [ ... , 'imageResize' ]
}
```

{@snippet features/image-resizeuidropdown}

### Resize image using the standalone buttons

```js
const imageConfiguration = {
resizeOptions: [
{
name: 'imageResize:original',
label: 'Original size',
value: null
},
{
name: 'imageResize:50',
label: '50%',
value: '50'
},
{
name: 'imageResize:75',
label: '75%',
value: '75'
}
],
toolbar: [
// ...,
'imageResize:original',
'imageResize:50',
'imageResize:75'
]
}
```

{@snippet features/image-resizeui}

### Enabling image resizing

The image resize feature is not enabled by default in any of the editor builds. In order to enable it, you need to load the {@link module:image/imageresize~ImageResize} plugin. Read more in the [Installation](#installation) section.
Expand Down
5 changes: 4 additions & 1 deletion packages/ckeditor5-image/lang/contexts.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"Enter image caption": "Placeholder text for image caption displayed when caption is empty.",
"Insert image": "Label for the insert image toolbar button.",
"Upload failed": "Title of the notification displayed when upload fails.",
"Image toolbar": "The label used by assistive technologies describing an image toolbar attached to an image widget."
"Image toolbar": "The label used by assistive technologies describing an image toolbar attached to an image widget.",
"Resize image to": "The label used for the standalone resize option buttons in the image toolbar",
"Resize image": "The label used for the dropdown in the image toolbar, containing defined resize options",
"Resize image to the original size": "The label used for the standalone resize reset option button in the image toolbar, when user set the value to `null`"
}
Loading