Skip to content

Commit

Permalink
Merge pull request #2872 from ckeditor/t/2816
Browse files Browse the repository at this point in the history
Fix for: Resize handler was visible after entering read-only mode manually
  • Loading branch information
f1ames authored Mar 26, 2019
2 parents 3c4e2a3 + c4110e6 commit 4b08ca6
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 41 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Fixed Issues:

* [#1397](https://github.com/ckeditor/ckeditor-dev/issues/1397): Fixed: Using dialog to remove headers from the [table](https://ckeditor.com/cke4/addon/table) with one headers row only throws an error.
* [#1479](https://github.com/ckeditor/ckeditor-dev/issues/1479): Fixed: [Justification](https://ckeditor.com/cke4/addon/justify) for styled content in BR mode is disabled.
* [#2816](https://github.com/ckeditor/ckeditor-dev/issues/2816): Fixed: [Enhanced Image](https://ckeditor.com/cke4/addon/image2) resize handler is visible in [read-only mode](https://ckeditor.com/docs/ckeditor4/latest/guide/dev_readonly.html).
* [#2874](https://github.com/ckeditor/ckeditor-dev/issues/2874): Fixed: [Enhanced Image](https://ckeditor.com/cke4/addon/image2) resize handler is not added when editor is initialized in [read-only mode](https://ckeditor.com/docs/ckeditor4/latest/guide/dev_readonly.html).

## CKEditor 4.11.3

Expand Down
7 changes: 5 additions & 2 deletions plugins/image2/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
'.cke_image_resizer.cke_image_resizing{' +
'display:block' +
'}' +
// Hide resizer in read only mode (#2816).
'.cke_editable[contenteditable="false"] .cke_image_resizer{' +
'display:none;' +
'}' +
// Expand widget wrapper when linked inline image.
'.cke_widget_wrapper>a{' +
'display:inline-block' +
Expand Down Expand Up @@ -434,8 +438,7 @@

// Setup dynamic image resizing with mouse.
// Don't initialize resizer when dimensions are disallowed (https://dev.ckeditor.com/ticket/11004).
// Don't initialize resizer when editor.readOnly is set to true (#719).
if ( editor.filter.checkFeature( this.features.dimension ) && editor.config.image2_disableResizer !== true && editor.readOnly != true ) {
if ( editor.filter.checkFeature( this.features.dimension ) && editor.config.image2_disableResizer !== true ) {
setupResizer( this );
}

Expand Down
20 changes: 17 additions & 3 deletions tests/plugins/image2/manual/resizerwithreadonly.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
<h2>
Classic Editor
</h2>
<div id="editor1" contenteditable="true">
<img src="%BASE_PATH%/_assets/logo.png" />
</div>
<h2>
ReadOnly Editor
</h2>
<button id="disable">Toggle read-only mode</button>
<div id="editor2" contenteditable="true">
<img src="%BASE_PATH%/_assets/logo.png" />
</div>

<script>
CKEDITOR.replace( 'editor1' );
CKEDITOR.replace( 'editor2', {
readOnly: true
var editor2 = CKEDITOR.replace( 'editor2', {
readOnly: true,
on: {
instanceReady: function() {
CKEDITOR.document.getById( 'disable' ).on( 'click', function() {
editor2.setReadOnly( !editor2.readOnly );
} );
}
}
} );
</script>
</script>
18 changes: 16 additions & 2 deletions tests/plugins/image2/manual/resizerwithreadonly.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
@bender-tags: 4.7.3, bug, 719
@bender-tags: 4.7.3, 4.11.4, bug, 719, 2816, 2874
@bender-ui: collapsed
@bender-ckeditor-plugins: wysiwygarea, toolbar, image2

Only **first** editor should have enabled mouse resizer on image.
## Classic Editor

1. Focus the image.

**Expected:** The image resize handler is visible.

## ReadOnly Editor

1. Focus the image.

**Expected:** The image resize handler is not visible.

2. Click `Toggle read-only mode` multiple times focusing image every time after button click.

**Expected:** The image resize handler is enabled/disabled depending on the read-only mode state.
88 changes: 54 additions & 34 deletions tests/plugins/image2/resizerwithreadonly.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,74 @@
/* bender-tags: editor,widget */
/* bender-ckeditor-plugins: image2,toolbar */
/* bender-ckeditor-plugins: image2 */

( function() {
'use strict';

bender.test( {
// #719
'test readOnly set to false': function() {
bender.editorBot.create( {
name: 'editor1',
config: {
language: 'en'
}
}, function( bot ) {
var editor = bot.editor;
init: function() {
var css = CKEDITOR.getCss();
css = css.replace( '.cke_widget_wrapper:hover .cke_image_resizer', '.cke_widget_wrapper.hover .cke_image_resizer' );
CKEDITOR.addCss( css );
},

// #719, #2874
'test resizer creation without readOnly': testResizerPresence( { name: 'editor1' } ),

bot.dialog( 'image', function( dialog ) {
dialog.setValueOf( 'info', 'src', '_assets/foo.png' );
dialog.getButton( 'ok' ).click();
// #719, #2874
'test resizer creation with readOnly at initialization': testResizerPresence( { name: 'editor2', config: { readOnly: true } } ),

assert.sameData(
'cke_image_resizer',
editor.editable().getElementsByTag( 'span' ).$[ 2 ].outerHTML.match( /(cke_image_resizer)/g )[ 0 ]
);
// #719, #2874
'test resizer creation with readOnly after initialization': testResizerPresence( { name: 'editor3' }, true ),

// #719, #2816
'test hovering in read-only': function() {
bender.editorBot.create( { name: 'editor4', config: { readOnly: true } } , function( bot ) {
var editor = bot.editor;
editor.setData( '<img src="_assets/foo.png" alt="" />', function() {
resume( function() {
var wrapper = editor.editable().findOne( '.cke_widget_wrapper' ),
resizer = wrapper.findOne( '.cke_image_resizer' );

wrapper.addClass( 'hover' );
assert.isTrue( !resizer.isVisible() );
} );
} );
wait();
} );
},

// #719
'test readOnly set to true': function() {
bender.editorBot.create( {
name: 'editor2',
config: {
readOnly: true
}
}, function( bot ) {
var editor = bot.editor,
listener;

listener = editor.on( 'dataReady', function() {
listener.removeListener();

// #719, #2816
'test hovering without read-only': function() {
bender.editorBot.create( { name: 'editor5', config: { readOnly: false } } , function( bot ) {
var editor = bot.editor;
editor.setData( '<img src="_assets/foo.png" alt="" />', function() {
resume( function() {
assert.areSame( 2, editor.editable().getElementsByTag( 'span' ).$.length );
var wrapper = editor.editable().findOne( '.cke_widget_wrapper' ),
resizer = editor.editable().findOne( '.cke_widget_image .cke_image_resizer' );
wrapper.addClass( 'hover' );
assert.isTrue( resizer.isVisible() );
} );
} );

editor.setData( '<img src="_assets/foo.png" alt="" />' );
wait();
} );
}
} );
}() );

function testResizerPresence( profile, readOnly ) {
return function() {
bender.editorBot.create( profile, function( bot ) {
var editor = bot.editor;

editor.setData( '<img src="_assets/foo.png" alt="" />', function() {
resume( function() {
if ( readOnly ) {
editor.setReadOnly( readOnly );
}
assert.isNotNull( editor.editable().findOne( '.cke_widget_image .cke_image_resizer' ), 'Resizer should be created' );
} );
} );
wait();
} );
};
}

0 comments on commit 4b08ca6

Please sign in to comment.