Skip to content

Commit 6cdf588

Browse files
author
Piotr Jasiun
committed
Merge branch 't/11905' into major
2 parents f5d711d + b9bcdce commit 6cdf588

File tree

9 files changed

+164
-9
lines changed

9 files changed

+164
-9
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ New Features:
1515
* [#12416](http://dev.ckeditor.com/ticket/12416): Added [`widget.definition.upcastPriority`](http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.widget.definition-property-upcastPriority) property which gives more control over widgets upcasting order to the widget author.
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.
18+
* [#11905](http://dev.ckeditor.com/ticket/11905): [`resize` event](http://docs.ckeditor.dev/#!/api/CKEDITOR.editor-event-resize) pass dimensions in data.
1819

1920
Fixed Issues:
2021

core/creators/themedui.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,8 @@ CKEDITOR.replaceClass = 'ckeditor';
217217
editor.ui.space( 'contents' ).setHtml( '' );
218218

219219
editor.mode = '';
220-
} else {
220+
} else
221221
editor._.previousModeData = editor.getData( 1 );
222-
}
223222

224223
// Fire the mode handler.
225224
this._.modes[ newMode ]( function() {
@@ -287,15 +286,24 @@ CKEDITOR.replaceClass = 'ckeditor';
287286
contentsFrame && ( contentsFrame.style.width = '1%' );
288287

289288
// Get the height delta between the outer table and the content area.
289+
var contentsOuterDelta = ( outer.$.offsetHeight || 0 ) - ( contents.$.clientHeight || 0 ),
290+
290291
// If we're setting the content area's height, then we don't need the delta.
291-
var delta = isContentHeight ? 0 : ( outer.$.offsetHeight || 0 ) - ( contents.$.clientHeight || 0 );
292-
contents.setStyle( 'height', Math.max( height - delta, 0 ) + 'px' );
292+
resultContentsHeight = Math.max( height - ( isContentHeight ? 0 : contentsOuterDelta ), 0 ),
293+
resultOuterHeight = ( isContentHeight ? height + contentsOuterDelta : height );
294+
295+
contents.setStyle( 'height', resultContentsHeight + 'px' );
293296

294297
// WebKit needs to refresh the iframe size to avoid rendering issues. (2/2) (#8348)
295298
contentsFrame && ( contentsFrame.style.width = '100%' );
296299

297300
// Emit a resize event.
298-
this.fire( 'resize' );
301+
this.fire( 'resize', {
302+
outerHeight: resultOuterHeight,
303+
contentsHeight: resultContentsHeight,
304+
// Sometimes width is not provided.
305+
outerWidth: width || outer.getSize( 'width' )
306+
} );
299307
};
300308

301309
/**
@@ -419,9 +427,8 @@ CKEDITOR.replaceClass = 'ckeditor';
419427
if ( elementMode == CKEDITOR.ELEMENT_MODE_REPLACE ) {
420428
element.hide();
421429
container.insertAfter( element );
422-
} else {
430+
} else
423431
element.append( container );
424-
}
425432

426433
editor.container = container;
427434

@@ -482,6 +489,10 @@ CKEDITOR.config.startupMode = 'wysiwyg';
482489
*
483490
* @event resize
484491
* @param {CKEDITOR.editor} editor This editor instance.
492+
* @param {Object} data Available since CKEditor 4.5.0.
493+
* @param {Number} data.outerHeight Entire height area, which the editor covers.
494+
* @param {Number} data.contentsHeight Editable area height in pixels.
495+
* @param {Number} data.outerWidth Entire width area, which the editor covers.
485496
*/
486497

487498
/**

plugins/maximize/plugin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,11 @@
239239

240240
// Emit a resize event, because this time the size is modified in
241241
// restoreStyles.
242-
editor.fire( 'resize' );
242+
editor.fire( 'resize', {
243+
outerHeight: editor.container.$.offsetHeight,
244+
contentsHeight: contents.$.offsetHeight,
245+
outerWidth: editor.container.$.offsetWidth
246+
} );
243247
}
244248

245249
this.toggleState();

plugins/toolbar/plugin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,11 @@
353353
var dy = toolboxContainer.$.offsetHeight - previousHeight;
354354
contents.setStyle( 'height', ( contentHeight - dy ) + 'px' );
355355

356-
editor.fire( 'resize' );
356+
editor.fire( 'resize', {
357+
outerHeight: editor.container.$.offsetHeight,
358+
contentsHeight: contents.$.offsetHeight,
359+
outerWidth: editor.container.$.offsetWidth
360+
} );
357361
},
358362

359363
modes: { wysiwyg: 1, source: 1 }

tests/core/creators/themedui.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* bender-ckeditor-plugins: wysiwygarea,toolbar,table */
2+
( function() {
3+
'use strict';
4+
5+
function getEditorContentHeight( editor ) {
6+
return editor.ui.space( 'contents' ).$.offsetHeight;
7+
}
8+
9+
function getEditorOuterHeight( editor ) {
10+
return editor.container.$.offsetHeight;
11+
}
12+
13+
bender.editor = true;
14+
15+
bender.test( {
16+
'test resize event': function() {
17+
var editor = this.editor,
18+
lastResizeData = 0;
19+
20+
editor.on( 'resize', function(e) {
21+
lastResizeData = e.data;
22+
} );
23+
24+
editor.resize( 100, 400 );
25+
assert.areSame( 400, lastResizeData.outerHeight, 'Outer height should be same as passed one in 2nd argument.' );
26+
assert.areSame( 100, lastResizeData.outerWidth, 'Outer width should be same as passed one in 1st argument.' );
27+
assert.areSame( getEditorContentHeight( editor ), lastResizeData.contentsHeight, 'Content height should be same as calculated one.' );
28+
assert.areSame( 400, getEditorOuterHeight( editor ), 'Outer height should be properly set.' );
29+
30+
editor.resize( 100, 400, true );
31+
assert.areSame( getEditorOuterHeight( editor ), lastResizeData.outerHeight, 'Outer height should be same as calculated one.' );
32+
assert.areSame( 100, lastResizeData.outerWidth, 'Outer width should be same as passed one in 1st argument.' );
33+
assert.areSame( 400, lastResizeData.contentsHeight, 'Content height should be same as passed one in 2nd argument.' );
34+
assert.areSame( 400, getEditorContentHeight( editor ), 'Content height should be properly set.' );
35+
}
36+
} )
37+
} )();

tests/plugins/maximize/maximize.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@ bender.test( {
4747
wait();
4848
},
4949

50+
'test maximize fire resize event with proper properties': function() {
51+
var calls = 0,
52+
lastResizeData;
53+
54+
this.editor.on( 'resize', function( e ) {
55+
calls++;
56+
lastResizeData = e.data;
57+
} );
58+
59+
this.editor.resize( 200, 400 );
60+
61+
this.editor.execCommand( 'maximize' );
62+
assert.areEqual( window.innerHeight || document.documentElement.clientHeight, lastResizeData.outerHeight, 'Height should be same as window height.' );
63+
assert.areEqual( window.innerWidth || document.documentElement.clientWidth, lastResizeData.outerWidth, 'Width should be same as window height.' );
64+
65+
this.editor.execCommand( 'maximize' );
66+
assert.areEqual( 200, lastResizeData.outerWidth, 'Width should be restored.' );
67+
assert.areEqual( 400, lastResizeData.outerHeight, 'Height should be restored.' );
68+
},
69+
5070
'test maximize command work when config title is set to empty string': function() {
5171
bender.editorBot.create( {
5272
name: 'editor2',
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<textarea id="editor1">&lt;p&gt;The more a thing tends to be permanent, the more it tends to be lifeless.&lt;/p&gt;</textarea>
2+
<button id="destroy"><span>Destroy editor</span></button>
3+
<button id="create"><span>Create editor</span></button>
4+
<script>
5+
( function() {
6+
var destroyBtn = CKEDITOR.document.getById( 'destroy' ),
7+
createBtn = CKEDITOR.document.getById( 'create' ),
8+
editor1 = null,
9+
storage;
10+
11+
function destroyEditor() {
12+
editor1.destroy();
13+
editor1 = null;
14+
15+
createBtn.on( 'click', createEditor );
16+
destroyBtn.removeListener( 'click', destroyEditor );
17+
}
18+
19+
function createEditor() {
20+
editor1 = CKEDITOR.replace( 'editor1', {
21+
resize_dir: 'both'
22+
} );
23+
24+
editor1.on( 'instanceReady', function() {
25+
editor1.on( 'resize', function( e ) {
26+
storage = e.data;
27+
} );
28+
29+
destroyBtn.on( 'click', destroyEditor );
30+
createBtn.removeListener( 'click', createEditor );
31+
32+
if ( storage ) {
33+
editor1.resize( storage.outerWidth, storage.outerHeight );
34+
}
35+
} );
36+
}
37+
38+
createEditor();
39+
}() );
40+
</script>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@bender-tags: 4.5.0, tc
2+
@bender-ui: collapsed
3+
@bender-ckeditor-plugins: wysiwygarea, toolbar, elementspath, resize
4+
5+
This test checks whether resize event is fired with dimensions as a properties. If so, destroying and creating editor instances should save its size.
6+
7+
1. Resize editor
8+
2. Destroy and create editor.
9+
10+
**Expected result:** After creating new editor instance dimensions should be saved.

tests/plugins/toolbar/basic.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,33 @@ bender.test( {
9292
},
9393
testToolbarExpanded
9494
);
95+
},
96+
97+
'test toolbar collapse/expand fire resize event': function() {
98+
bender.editorBot.create( {
99+
name: 'editor4',
100+
config: {
101+
toolbarCanCollapse: true
102+
}
103+
},
104+
function( bot ) {
105+
var resizeData = [],
106+
editor = bot.editor;
107+
108+
editor.on( 'resize', function( e ) {
109+
resizeData.push( e.data );
110+
} );
111+
112+
editor.resize( 200, 400 );
113+
assert.areEqual( 200, resizeData[ 0 ].outerWidth, 'Width should be set properly.' );
114+
assert.areEqual( 400, resizeData[ 0 ].outerHeight, 'Height should be set properly.' );
115+
116+
editor.execCommand( 'toolbarCollapse' );
117+
assert.isTrue( resizeData[ 1 ].outerHeight < resizeData[ 0 ].outerHeight, 'Height after collapse should be less.' );
118+
119+
editor.execCommand( 'toolbarCollapse' );
120+
assert.areSame( resizeData[ 0 ].outerHeight, resizeData[ 2 ].outerHeight, 'Height should properly restore to same value.' );
121+
}
122+
);
95123
}
96124
} );

0 commit comments

Comments
 (0)