Skip to content

Commit 6ec5dd5

Browse files
committed
Merge branch 't/12707'
2 parents 60d4691 + 96cb62c commit 6ec5dd5

File tree

5 files changed

+95
-5
lines changed

5 files changed

+95
-5
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ CKEditor 4 Changelog
33

44
## CKEditor 4.5.8
55

6+
Other Changes:
7+
8+
* [#12707](http://dev.ckeditor.com/ticket/12707): Fixed: Table elements order to meet HTML specification.
9+
610
## CKEditor 4.5.7
711

812
New Features:

plugins/table/dialogs/table.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,15 @@
157157
// Should we make a <thead>?
158158
var headers = info.selHeaders;
159159
if ( !table.$.tHead && ( headers == 'row' || headers == 'both' ) ) {
160-
var thead = new CKEDITOR.dom.element( table.$.createTHead() );
160+
var thead = table.findOne( 'thead' );
161161
tbody = table.getElementsByTag( 'tbody' ).getItem( 0 );
162162
var theRow = tbody.getElementsByTag( 'tr' ).getItem( 0 );
163163

164+
if ( !thead ) {
165+
thead = new CKEDITOR.dom.element( 'thead' );
166+
thead.insertBefore( tbody );
167+
}
168+
164169
// Change TD to TH:
165170
for ( i = 0; i < theRow.getChildCount(); i++ ) {
166171
var th = theRow.getChild( i );
@@ -498,10 +503,7 @@
498503
captionElement.setHtml( '' );
499504
} else {
500505
captionElement = new CKEDITOR.dom.element( 'caption', editor.document );
501-
if ( table.getChildCount() )
502-
captionElement.insertBefore( table.getFirst() );
503-
else
504-
captionElement.appendTo( table );
506+
table.append( captionElement, true );
505507
}
506508
captionElement.append( new CKEDITOR.dom.text( caption, editor.document ) );
507509
} else if ( captionElement.count() > 0 ) {

tests/plugins/table/caption.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* bender-tags: editor,unit,table */
2+
/* bender-ckeditor-plugins: toolbar,dialog,table */
3+
4+
( function() {
5+
'use strict';
6+
7+
bender.editor = true;
8+
9+
bender.test( {
10+
11+
'test caption index in table without headers': function() {
12+
var bot = this.editorBot;
13+
14+
bot.dialog( 'tableProperties', function( dialog ) {
15+
dialog.setValueOf( 'info', 'txtCaption', 'Caption1' );
16+
dialog.getButton( 'ok' ).click();
17+
18+
var table = bot.editor.document.find( 'table' );
19+
assert.areSame( table.count(), 1, 'Table inserted.' );
20+
assert.areSame( table.getItem( 0 ).getChild( 0 ).getName(), 'caption', 'Caption element is first child of table.' );
21+
} );
22+
},
23+
24+
'test caption index in table with headers row': function() {
25+
var bot = this.editorBot;
26+
27+
bot.dialog( 'tableProperties', function( dialog ) {
28+
dialog.setValueOf( 'info', 'txtCaption', 'Caption2' );
29+
dialog.setValueOf( 'info', 'selHeaders', 'row' );
30+
dialog.getButton( 'ok' ).click();
31+
32+
var table = bot.editor.document.find( 'table' );
33+
assert.areSame( table.count(), 1, 'Table inserted.' );
34+
assert.areSame( table.getItem( 0 ).getChild( 0 ).getName(), 'caption', 'Caption element is first child of table.' );
35+
} );
36+
},
37+
38+
'test caption index in table with headers col': function() {
39+
var bot = this.editorBot;
40+
41+
bot.dialog( 'tableProperties', function( dialog ) {
42+
dialog.setValueOf( 'info', 'txtCaption', 'Caption3' );
43+
dialog.setValueOf( 'info', 'selHeaders', 'col' );
44+
dialog.getButton( 'ok' ).click();
45+
46+
var table = bot.editor.document.find( 'table' );
47+
assert.areSame( table.count(), 1, 'Table inserted.' );
48+
assert.areSame( table.getItem( 0 ).getChild( 0 ).getName(), 'caption', 'Caption element is first child of table.' );
49+
} );
50+
},
51+
52+
'test caption index in table with both headers': function() {
53+
var bot = this.editorBot;
54+
55+
bot.dialog( 'tableProperties', function( dialog ) {
56+
dialog.setValueOf( 'info', 'txtCaption', 'Caption4' );
57+
dialog.setValueOf( 'info', 'selHeaders', 'both' );
58+
dialog.getButton( 'ok' ).click();
59+
60+
var table = bot.editor.document.find( 'table' );
61+
assert.areSame( table.count(), 1, 'Table inserted.' );
62+
assert.areSame( table.getItem( 0 ).getChild( 0 ).getName(), 'caption', 'Caption element is first child of table.' );
63+
} );
64+
}
65+
} );
66+
} )();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<textarea id="editor1"></textarea>
2+
3+
<script>
4+
CKEDITOR.replace( 'editor1' );
5+
</script>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@bender-tags: 4.5.8, tc, 12707
2+
@bender-ui: collapsed
3+
@bender-ckeditor-plugins: wysiwygarea,toolbar,table,sourcearea
4+
5+
1. Click on the Table button.
6+
1. Select Headers: **Both**.
7+
1. Type **foo** in Caption field.
8+
1. Click Ok.
9+
* The table with 3 row and 2 columns was created.
10+
1. Click the Source toolbar button and view the generated HTML.
11+
* The `caption` element is the first, direct child of `table` element,
12+
* The `caption` element contains text "foo",
13+
* `thead` is a second child of the `table` element.

0 commit comments

Comments
 (0)