Skip to content

Commit df5a9dc

Browse files
committed
Merge branch 't/12126' into major
2 parents 96d5130 + 7c933fa commit df5a9dc

File tree

12 files changed

+333
-30
lines changed

12 files changed

+333
-30
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ New Features:
1616
* [#12448](http://dev.ckeditor.com/ticket/12448): Set of new methods, params and events giving the developer more control over HTML insertion. See the [`editable.insertHtml()`](http://docs.ckeditor.com/#!/api/CKEDITOR.editable-method-insertHtml) param `range`, the [`editable.insertHtmlIntoRange()`](http://docs.ckeditor.com/#!/api/CKEDITOR.editable-method-insertHtmlIntoRange) method and the [`editor.afterInsertHtml`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-afterInsertHtml) event.
1717
* [#12036](http://dev.ckeditor.com/ticket/12036): Initialize editor in [`readOnly`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-property-readOnly) mode when `<textarea>` has `readonly` attribute.
1818
* [#11905](http://dev.ckeditor.com/ticket/11905): [`resize` event](http://docs.ckeditor.dev/#!/api/CKEDITOR.editor-event-resize) pass dimensions in data.
19+
* [#12126](http://dev.ckeditor.com/ticket/12126): Introduced [`image_prefillDimensions`](http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-image_prefillDimensions) and [`image2_prefillDimensions`](http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-image2_prefillDimensions) to make pre-filling 'width' and 'height' configurable.
1920

2021
Fixed Issues:
2122

plugins/image/dialogs/image.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,25 @@
151151
return dialog.lockRatio;
152152
};
153153

154-
var resetSize = function( dialog ) {
155-
var oImageOriginal = dialog.originalElement;
156-
if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' ) {
154+
var resetSize = function( dialog, emptyValues ) {
155+
var oImageOriginal = dialog.originalElement,
156+
ready = oImageOriginal.getCustomData( 'isReady' ) == 'true';
157+
158+
if ( ready ) {
157159
var widthField = dialog.getContentElement( 'info', 'txtWidth' ),
158-
heightField = dialog.getContentElement( 'info', 'txtHeight' );
159-
widthField && widthField.setValue( oImageOriginal.$.width );
160-
heightField && heightField.setValue( oImageOriginal.$.height );
160+
heightField = dialog.getContentElement( 'info', 'txtHeight' ),
161+
widthValue, heightValue;
162+
163+
if ( emptyValues ) {
164+
widthValue = 0;
165+
heightValue = 0;
166+
} else {
167+
widthValue = oImageOriginal.$.width;
168+
heightValue = oImageOriginal.$.height;
169+
}
170+
171+
widthField && widthField.setValue( widthValue );
172+
heightField && heightField.setValue( heightValue );
161173
}
162174
updatePreview( dialog );
163175
};
@@ -207,9 +219,10 @@
207219
if ( loader )
208220
loader.setStyle( 'display', 'none' );
209221

210-
// New image -> new domensions
211-
if ( !this.dontResetSize )
212-
resetSize( this );
222+
// New image -> new dimensions
223+
if ( !this.dontResetSize ) {
224+
resetSize( this, editor.config.image_prefillDimensions === false );
225+
}
213226

214227
if ( this.firstLoad ) {
215228
CKEDITOR.tools.setTimeout( function() {

plugins/image/plugin.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@
153153

154154
} )();
155155

156+
/**
157+
* Determine whether dimensions inputs should be automatically filled when image src changes in image dialog.
158+
*
159+
* @since 4.5.0
160+
* @cfg {Boolean} [image_prefillDimensions=true]
161+
* @member CKEDITOR.config
162+
*/
163+
156164
/**
157165
* Whether to remove links when emptying the link URL field in the image dialog.
158166
*

plugins/image2/dialogs/image2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ CKEDITOR.dialog.add( 'image2', function( editor ) {
145145
return toggleLockRatio( false );
146146

147147
// Fill width field with the width of the new image.
148-
widthField.setValue( width );
148+
widthField.setValue( editor.config.image2_prefillDimensions === false ? 0 : width );
149149

150150
// Fill height field with the height of the new image.
151-
heightField.setValue( height );
151+
heightField.setValue( editor.config.image2_prefillDimensions === false ? 0 : height );
152152

153153
// Cache the new width.
154154
preLoadedWidth = width;

plugins/image2/plugin.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@
789789
// </p>
790790
// </div>
791791
if ( hasCaption ) {
792-
wrapper.addClass( alignClasses[1] );
792+
wrapper.addClass( alignClasses[ 1 ] );
793793
}
794794
} else if ( align != 'none' ) {
795795
wrapper.addClass( alignClasses[ alignmentsObj[ align ] ] );
@@ -871,7 +871,7 @@
871871

872872
// Upcast linked image like <a><img/></a>.
873873
} else if ( isLinkedOrStandaloneImage( el ) ) {
874-
image = el.name == 'a' ? el.children[0] : el;
874+
image = el.name == 'a' ? el.children[ 0 ] : el;
875875
}
876876

877877
if ( !image )
@@ -1536,6 +1536,14 @@
15361536
*/
15371537
CKEDITOR.config.image2_captionedClass = 'image';
15381538

1539+
/**
1540+
* Determine whether dimensions inputs should be automatically filled when image src changes in image2 dialog.
1541+
*
1542+
* @since 4.5.0
1543+
* @cfg {Boolean} [image2_prefillDimensions=true]
1544+
* @member CKEDITOR.config
1545+
*/
1546+
15391547
/**
15401548
* CSS classes applied to aligned images. Useful to take control over the way
15411549
* the images are aligned, i.e. to customize output HTML and integrate external stylesheets.

tests/_benderjs/ckeditor/static/tools.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,37 @@
990990
}
991991

992992
return outputTests;
993-
}
993+
},
994+
995+
/**
996+
* Downloads image and call callback after that.
997+
*
998+
* @param {String} src Image source.
999+
* @param {Function} callback Callback function with image (CKEDITOR.dom.element)
1000+
* or `null` in case of error or abort.
1001+
*/
1002+
downloadImage: function( src, callback ) {
1003+
var img = new CKEDITOR.dom.element( 'img' );
1004+
1005+
img.once( 'load', function() {
1006+
// Because this function may be used to wait until editor download image, the callback in
1007+
// this test helper must be called later then editors.
1008+
setTimeout( function() {
1009+
callback( img );
1010+
}, 10 );
1011+
} );
1012+
1013+
img.once( 'error', function() {
1014+
callback( null );
1015+
} );
9941016

1017+
img.once( 'abort', function() {
1018+
callback( null );
1019+
} );
1020+
1021+
// Add random string to be sure that the image will be downloaded, not taken from cache.
1022+
img.setAttribute( 'src', src + '?' + Math.random().toString( 16 ).substring( 2 ) );
1023+
}
9951024
};
9961025

9971026
bender.tools.range = {

tests/plugins/image/image.js

Lines changed: 103 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
}
1111
};
1212

13-
var SRC = '%BASE_PATH%_assets/logo.png';
13+
var SRC = '%BASE_PATH%_assets/logo.png',
14+
imgs = [
15+
{ url: '%BASE_PATH%_assets/logo.png', width: '163', height: '61' },
16+
{ url: '%BASE_PATH%_assets/large.jpg', width: '1008', height: '550' }
17+
],
18+
downloadImage = bender.tools.downloadImage;
1419

1520
bender.test( {
1621
'test read image (inline styles)': function() {
@@ -348,6 +353,103 @@
348353
} );
349354
},
350355

356+
/**
357+
* #12126
358+
*
359+
* 1. Open image dialog.
360+
* 2. Set some proper image url and focus out.
361+
* 3. Dimensions inputs should be empty.
362+
* 4. Set another proper image url and focus out.
363+
* 5. Again dimensions inputs should be empty.
364+
*/
365+
'test dimensions not set automatically when disbled in option': function() {
366+
bender.editorBot.create( {
367+
name: 'editor_disabled_autodimensions',
368+
creator: 'inline',
369+
config: {
370+
image_prefillDimensions: false
371+
}
372+
},
373+
function( bot ) {
374+
bot.dialog( 'image', function( dialog ) {
375+
var i = 0,
376+
heightInput = dialog.getContentElement( 'info', 'txtHeight' ),
377+
widthInput = dialog.getContentElement( 'info', 'txtWidth' );
378+
379+
dialog.setValueOf( 'info', 'txtUrl', imgs[ i ].url );
380+
downloadImage( imgs[ i ].url, onDownload );
381+
382+
function onDownload() {
383+
resume( onResume );
384+
}
385+
386+
function onResume() {
387+
dialog.getContentElement( 'info', 'txtHeight' ).getValue();
388+
assert.areSame( '', widthInput.getValue() );
389+
assert.areSame( '', heightInput.getValue() );
390+
391+
if ( i === 0 ) {
392+
dialog.setValueOf( 'info', 'txtUrl', imgs[ ++i ].url );
393+
downloadImage( imgs[ i ].url, onDownload );
394+
wait();
395+
}
396+
}
397+
398+
wait();
399+
} );
400+
} );
401+
},
402+
403+
/**
404+
* #12126
405+
*
406+
* 1. Open image dialog.
407+
* 2. Set some proper image url and focus out.
408+
* 3. Click button "Reset Size".
409+
* 4. Set some proper image url and focus out.
410+
* 5. Dimensions inputs should be empty.
411+
*/
412+
'test dimension should be empty after resetting size and loading image': function() {
413+
bender.editorBot.create( {
414+
name: 'editor_disabled_autodimensions2',
415+
creator: 'inline',
416+
config: {
417+
image_prefillDimensions: false
418+
}
419+
},
420+
function( bot ) {
421+
bot.dialog( 'image', function( dialog ) {
422+
var i = 0,
423+
resetBtn = bot.editor.document.getById( dialog.getContentElement( 'info', 'ratioLock' ).domId ).find( '.cke_btn_reset' ).getItem( 0 );
424+
425+
dialog.setValueOf( 'info', 'txtUrl', imgs[ i ].url );
426+
downloadImage( imgs[ i ].url, onDownload );
427+
428+
function onDownload() {
429+
resume( onResume );
430+
}
431+
432+
function onResume() {
433+
resetBtn.fire( 'click' );
434+
assert.areSame( imgs[ i ].width, dialog.getContentElement( 'info', 'txtWidth' ).getValue() );
435+
assert.areSame( imgs[ i ].height, dialog.getContentElement( 'info', 'txtHeight' ).getValue() );
436+
437+
dialog.setValueOf( 'info', 'txtUrl', imgs[ ++i ].url );
438+
downloadImage( imgs[ i ].url, function() {
439+
resume( function() {
440+
assert.areSame( '', dialog.getContentElement( 'info', 'txtWidth' ).getValue() );
441+
assert.areSame( '', dialog.getContentElement( 'info', 'txtHeight' ).getValue() );
442+
} );
443+
} );
444+
445+
wait();
446+
}
447+
448+
wait();
449+
} );
450+
} );
451+
},
452+
351453
// This TC verifies also the above test's correctness.
352454
'test width and height are automatically set': function() {
353455
var bot = this.editorBot,
@@ -374,19 +476,5 @@
374476
} );
375477
}
376478
} );
377-
378-
function downloadImage( src, cb ) {
379-
var img = new CKEDITOR.dom.element( 'img' );
380-
381-
img.once( 'load', onDone );
382-
img.once( 'error', onDone );
383-
384-
function onDone() {
385-
setTimeout( cb, 0 );
386-
}
387-
388-
img.setAttribute( 'src', src );
389-
}
390-
391479
} )();
392480
//]]>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<textarea id="editor1">Hello moto.</textarea>
2+
<script>
3+
CKEDITOR.replace( 'editor1', {
4+
image_prefillDimensions: false
5+
} );
6+
</script>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@bender-tags: 4.5.0, tc
2+
@bender-ui: collapsed
3+
@bender-ckeditor-plugins: wysiwygarea, toolbar, floatingspace, image
4+
5+
**Please note**: You can use such link: `http://lorempixel.com/200/100`.
6+
7+
1. Open image dialog.
8+
2. Set some proper image url and focus out.
9+
* **Expected result**: Dimensions inputs should be empty.
10+
3. Set another proper image url and focus out.
11+
* **Expected result**: Again - dimensions inputs should be empty.
12+
13+
----
14+
15+
1. Open image dialog.
16+
2. Set some proper image url and focus out.
17+
3. Click button "Reset Size".
18+
4. Set some proper image url and focus out.
19+
* **Expected result**: Dimensions inputs should be empty.

0 commit comments

Comments
 (0)