JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / plugins / table / dialogs / table.js
1 /*\r
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 (function()\r
7 {\r
8         var defaultToPixel = CKEDITOR.tools.cssLength;\r
9 \r
10         var commitValue = function( data )\r
11         {\r
12                 var id = this.id;\r
13                 if ( !data.info )\r
14                         data.info = {};\r
15                 data.info[id] = this.getValue();\r
16         };\r
17 \r
18         function tableDialog( editor, command )\r
19         {\r
20                 var makeElement = function( name )\r
21                         {\r
22                                 return new CKEDITOR.dom.element( name, editor.document );\r
23                         };\r
24 \r
25                 var dialogadvtab = editor.plugins.dialogadvtab;\r
26 \r
27                 return {\r
28                         title : editor.lang.table.title,\r
29                         minWidth : 310,\r
30                         minHeight : CKEDITOR.env.ie ? 310 : 280,\r
31 \r
32                         onLoad : function()\r
33                         {\r
34                                 var dialog = this;\r
35 \r
36                                 var styles = dialog.getContentElement( 'advanced', 'advStyles' );\r
37 \r
38                                 if ( styles )\r
39                                 {\r
40                                         styles.on( 'change', function( evt )\r
41                                                 {\r
42                                                         // Synchronize width value.\r
43                                                         var width = this.getStyle( 'width', '' ),\r
44                                                                 txtWidth = dialog.getContentElement( 'info', 'txtWidth' );\r
45 \r
46                                                         txtWidth && txtWidth.setValue( width, true );\r
47 \r
48                                                         // Synchronize height value.\r
49                                                         var height = this.getStyle( 'height', '' ),\r
50                                                                 txtHeight = dialog.getContentElement( 'info', 'txtHeight' );\r
51 \r
52                                                         txtHeight && txtHeight.setValue( height, true );\r
53                                                 });\r
54                                 }\r
55                         },\r
56 \r
57                         onShow : function()\r
58                         {\r
59                                 // Detect if there's a selected table.\r
60                                 var selection = editor.getSelection(),\r
61                                         ranges = selection.getRanges(),\r
62                                         selectedTable = null;\r
63 \r
64                                 var rowsInput = this.getContentElement( 'info', 'txtRows' ),\r
65                                         colsInput = this.getContentElement( 'info', 'txtCols' ),\r
66                                         widthInput = this.getContentElement( 'info', 'txtWidth' ),\r
67                                         heightInput = this.getContentElement( 'info', 'txtHeight' );\r
68 \r
69                                 if ( command == 'tableProperties' )\r
70                                 {\r
71                                         if ( ( selectedTable = selection.getSelectedElement() ) )\r
72                                                 selectedTable = selectedTable.getAscendant( 'table', true );\r
73                                         else if ( ranges.length > 0 )\r
74                                         {\r
75                                                 // Webkit could report the following range on cell selection (#4948):\r
76                                                 // <table><tr><td>[&nbsp;</td></tr></table>]\r
77                                                 if ( CKEDITOR.env.webkit )\r
78                                                         ranges[ 0 ].shrink( CKEDITOR.NODE_ELEMENT );\r
79 \r
80                                                 var rangeRoot = ranges[0].getCommonAncestor( true );\r
81                                                 selectedTable = rangeRoot.getAscendant( 'table', true );\r
82                                         }\r
83 \r
84                                         // Save a reference to the selected table, and push a new set of default values.\r
85                                         this._.selectedElement = selectedTable;\r
86                                 }\r
87 \r
88                                 // Enable or disable the row, cols, width fields.\r
89                                 if ( selectedTable )\r
90                                 {\r
91                                         this.setupContent( selectedTable );\r
92                                         rowsInput && rowsInput.disable();\r
93                                         colsInput && colsInput.disable();\r
94                                 }\r
95                                 else\r
96                                 {\r
97                                         rowsInput && rowsInput.enable();\r
98                                         colsInput && colsInput.enable();\r
99                                 }\r
100 \r
101                                 // Call the onChange method for the widht and height fields so\r
102                                 // they get reflected into the Advanced tab.\r
103                                 widthInput && widthInput.onChange();\r
104                                 heightInput && heightInput.onChange();\r
105                         },\r
106                         onOk : function()\r
107                         {\r
108                                 var selection = editor.getSelection(),\r
109                                         bms = this._.selectedElement && selection.createBookmarks();\r
110 \r
111                                 var table = this._.selectedElement || makeElement( 'table' ),\r
112                                         me = this,\r
113                                         data = {};\r
114 \r
115                                 this.commitContent( data, table );\r
116 \r
117                                 if ( data.info )\r
118                                 {\r
119                                         var info = data.info;\r
120 \r
121                                         // Generate the rows and cols.\r
122                                         if ( !this._.selectedElement )\r
123                                         {\r
124                                                 var tbody = table.append( makeElement( 'tbody' ) ),\r
125                                                         rows = parseInt( info.txtRows, 10 ) || 0,\r
126                                                         cols = parseInt( info.txtCols, 10 ) || 0;\r
127 \r
128                                                 for ( var i = 0 ; i < rows ; i++ )\r
129                                                 {\r
130                                                         var row = tbody.append( makeElement( 'tr' ) );\r
131                                                         for ( var j = 0 ; j < cols ; j++ )\r
132                                                         {\r
133                                                                 var cell = row.append( makeElement( 'td' ) );\r
134                                                                 if ( !CKEDITOR.env.ie )\r
135                                                                         cell.append( makeElement( 'br' ) );\r
136                                                         }\r
137                                                 }\r
138                                         }\r
139 \r
140                                         // Modify the table headers. Depends on having rows and cols generated\r
141                                         // correctly so it can't be done in commit functions.\r
142 \r
143                                         // Should we make a <thead>?\r
144                                         var headers = info.selHeaders;\r
145                                         if ( !table.$.tHead && ( headers == 'row' || headers == 'both' ) )\r
146                                         {\r
147                                                 var thead = new CKEDITOR.dom.element( table.$.createTHead() );\r
148                                                 tbody = table.getElementsByTag( 'tbody' ).getItem( 0 );\r
149                                                 var theRow = tbody.getElementsByTag( 'tr' ).getItem( 0 );\r
150 \r
151                                                 // Change TD to TH:\r
152                                                 for ( i = 0 ; i < theRow.getChildCount() ; i++ )\r
153                                                 {\r
154                                                         var th = theRow.getChild( i );\r
155                                                         // Skip bookmark nodes. (#6155)\r
156                                                         if ( th.type == CKEDITOR.NODE_ELEMENT && !th.data( 'cke-bookmark' ) )\r
157                                                         {\r
158                                                                 th.renameNode( 'th' );\r
159                                                                 th.setAttribute( 'scope', 'col' );\r
160                                                         }\r
161                                                 }\r
162                                                 thead.append( theRow.remove() );\r
163                                         }\r
164 \r
165                                         if ( table.$.tHead !== null && !( headers == 'row' || headers == 'both' ) )\r
166                                         {\r
167                                                 // Move the row out of the THead and put it in the TBody:\r
168                                                 thead = new CKEDITOR.dom.element( table.$.tHead );\r
169                                                 tbody = table.getElementsByTag( 'tbody' ).getItem( 0 );\r
170 \r
171                                                 var previousFirstRow = tbody.getFirst();\r
172                                                 while ( thead.getChildCount() > 0 )\r
173                                                 {\r
174                                                         theRow = thead.getFirst();\r
175                                                         for ( i = 0; i < theRow.getChildCount() ; i++ )\r
176                                                         {\r
177                                                                 var newCell = theRow.getChild( i );\r
178                                                                 if ( newCell.type == CKEDITOR.NODE_ELEMENT )\r
179                                                                 {\r
180                                                                         newCell.renameNode( 'td' );\r
181                                                                         newCell.removeAttribute( 'scope' );\r
182                                                                 }\r
183                                                         }\r
184                                                         theRow.insertBefore( previousFirstRow );\r
185                                                 }\r
186                                                 thead.remove();\r
187                                         }\r
188 \r
189                                         // Should we make all first cells in a row TH?\r
190                                         if ( !this.hasColumnHeaders && ( headers == 'col' || headers == 'both' ) )\r
191                                         {\r
192                                                 for ( row = 0 ; row < table.$.rows.length ; row++ )\r
193                                                 {\r
194                                                         newCell = new CKEDITOR.dom.element( table.$.rows[ row ].cells[ 0 ] );\r
195                                                         newCell.renameNode( 'th' );\r
196                                                         newCell.setAttribute( 'scope', 'row' );\r
197                                                 }\r
198                                         }\r
199 \r
200                                         // Should we make all first TH-cells in a row make TD? If 'yes' we do it the other way round :-)\r
201                                         if ( ( this.hasColumnHeaders ) && !( headers == 'col' || headers == 'both' ) )\r
202                                         {\r
203                                                 for ( i = 0 ; i < table.$.rows.length ; i++ )\r
204                                                 {\r
205                                                         row = new CKEDITOR.dom.element( table.$.rows[i] );\r
206                                                         if ( row.getParent().getName() == 'tbody' )\r
207                                                         {\r
208                                                                 newCell = new CKEDITOR.dom.element( row.$.cells[0] );\r
209                                                                 newCell.renameNode( 'td' );\r
210                                                                 newCell.removeAttribute( 'scope' );\r
211                                                         }\r
212                                                 }\r
213                                         }\r
214 \r
215                                         // Set the width and height.\r
216                                         info.txtHeight ? table.setStyle( 'height', info.txtHeight ) : table.removeStyle( 'height' );\r
217                                         info.txtWidth ? table.setStyle( 'width', info.txtWidth ) : table.removeStyle( 'width' );\r
218 \r
219                                         if ( !table.getAttribute( 'style' ) )\r
220                                                 table.removeAttribute( 'style' );\r
221                                 }\r
222 \r
223                                 // Insert the table element if we're creating one.\r
224                                 if ( !this._.selectedElement )\r
225                                 {\r
226                                         editor.insertElement( table );\r
227                                         // Override the default cursor position after insertElement to place\r
228                                         // cursor inside the first cell (#7959), IE needs a while.\r
229                                         setTimeout( function()\r
230                                                 {\r
231                                                         var firstCell = new CKEDITOR.dom.element( table.$.rows[ 0 ].cells[ 0 ] );\r
232                                                         var range = new CKEDITOR.dom.range( editor.document );\r
233                                                         range.moveToPosition( firstCell, CKEDITOR.POSITION_AFTER_START );\r
234                                                         range.select( 1 );\r
235                                                 }, 0 );\r
236                                 }\r
237                                 // Properly restore the selection, (#4822) but don't break\r
238                                 // because of this, e.g. updated table caption.\r
239                                 else\r
240                                         try { selection.selectBookmarks( bms ); } catch( er ){}\r
241                         },\r
242                         contents : [\r
243                                 {\r
244                                         id : 'info',\r
245                                         label : editor.lang.table.title,\r
246                                         elements :\r
247                                         [\r
248                                                 {\r
249                                                         type : 'hbox',\r
250                                                         widths : [ null, null ],\r
251                                                         styles : [ 'vertical-align:top' ],\r
252                                                         children :\r
253                                                         [\r
254                                                                 {\r
255                                                                         type : 'vbox',\r
256                                                                         padding : 0,\r
257                                                                         children :\r
258                                                                         [\r
259                                                                                 {\r
260                                                                                         type : 'text',\r
261                                                                                         id : 'txtRows',\r
262                                                                                         'default' : 3,\r
263                                                                                         label : editor.lang.table.rows,\r
264                                                                                         required : true,\r
265                                                                                         controlStyle : 'width:5em',\r
266                                                                                         validate : function()\r
267                                                                                         {\r
268                                                                                                 var pass = true,\r
269                                                                                                         value = this.getValue();\r
270                                                                                                 pass = pass && CKEDITOR.dialog.validate.integer()( value )\r
271                                                                                                         && value > 0;\r
272                                                                                                 if ( !pass )\r
273                                                                                                 {\r
274                                                                                                         alert( editor.lang.table.invalidRows );\r
275                                                                                                         this.select();\r
276                                                                                                 }\r
277                                                                                                 return pass;\r
278                                                                                         },\r
279                                                                                         setup : function( selectedElement )\r
280                                                                                         {\r
281                                                                                                 this.setValue( selectedElement.$.rows.length );\r
282                                                                                         },\r
283                                                                                         commit : commitValue\r
284                                                                                 },\r
285                                                                                 {\r
286                                                                                         type : 'text',\r
287                                                                                         id : 'txtCols',\r
288                                                                                         'default' : 2,\r
289                                                                                         label : editor.lang.table.columns,\r
290                                                                                         required : true,\r
291                                                                                         controlStyle : 'width:5em',\r
292                                                                                         validate : function()\r
293                                                                                         {\r
294                                                                                                 var pass = true,\r
295                                                                                                         value = this.getValue();\r
296                                                                                                 pass = pass && CKEDITOR.dialog.validate.integer()( value )\r
297                                                                                                         && value > 0;\r
298                                                                                                 if ( !pass )\r
299                                                                                                 {\r
300                                                                                                         alert( editor.lang.table.invalidCols );\r
301                                                                                                         this.select();\r
302                                                                                                 }\r
303                                                                                                 return pass;\r
304                                                                                         },\r
305                                                                                         setup : function( selectedTable )\r
306                                                                                         {\r
307                                                                                                 this.setValue( selectedTable.$.rows[0].cells.length);\r
308                                                                                         },\r
309                                                                                         commit : commitValue\r
310                                                                                 },\r
311                                                                                 {\r
312                                                                                         type : 'html',\r
313                                                                                         html : '&nbsp;'\r
314                                                                                 },\r
315                                                                                 {\r
316                                                                                         type : 'select',\r
317                                                                                         id : 'selHeaders',\r
318                                                                                         'default' : '',\r
319                                                                                         label : editor.lang.table.headers,\r
320                                                                                         items :\r
321                                                                                         [\r
322                                                                                                 [ editor.lang.table.headersNone, '' ],\r
323                                                                                                 [ editor.lang.table.headersRow, 'row' ],\r
324                                                                                                 [ editor.lang.table.headersColumn, 'col' ],\r
325                                                                                                 [ editor.lang.table.headersBoth, 'both' ]\r
326                                                                                         ],\r
327                                                                                         setup : function( selectedTable )\r
328                                                                                         {\r
329                                                                                                 // Fill in the headers field.\r
330                                                                                                 var dialog = this.getDialog();\r
331                                                                                                 dialog.hasColumnHeaders = true;\r
332 \r
333                                                                                                 // Check if all the first cells in every row are TH\r
334                                                                                                 for ( var row = 0 ; row < selectedTable.$.rows.length ; row++ )\r
335                                                                                                 {\r
336                                                                                                         // If just one cell isn't a TH then it isn't a header column\r
337                                                                                                         if ( selectedTable.$.rows[row].cells[0].nodeName.toLowerCase() != 'th' )\r
338                                                                                                         {\r
339                                                                                                                 dialog.hasColumnHeaders = false;\r
340                                                                                                                 break;\r
341                                                                                                         }\r
342                                                                                                 }\r
343 \r
344                                                                                                 // Check if the table contains <thead>.\r
345                                                                                                 if ( ( selectedTable.$.tHead !== null) )\r
346                                                                                                         this.setValue( dialog.hasColumnHeaders ? 'both' : 'row' );\r
347                                                                                                 else\r
348                                                                                                         this.setValue( dialog.hasColumnHeaders ? 'col' : '' );\r
349                                                                                         },\r
350                                                                                         commit : commitValue\r
351                                                                                 },\r
352                                                                                 {\r
353                                                                                         type : 'text',\r
354                                                                                         id : 'txtBorder',\r
355                                                                                         'default' : 1,\r
356                                                                                         label : editor.lang.table.border,\r
357                                                                                         controlStyle : 'width:3em',\r
358                                                                                         validate : CKEDITOR.dialog.validate['number']( editor.lang.table.invalidBorder ),\r
359                                                                                         setup : function( selectedTable )\r
360                                                                                         {\r
361                                                                                                 this.setValue( selectedTable.getAttribute( 'border' ) || '' );\r
362                                                                                         },\r
363                                                                                         commit : function( data, selectedTable )\r
364                                                                                         {\r
365                                                                                                 if ( this.getValue() )\r
366                                                                                                         selectedTable.setAttribute( 'border', this.getValue() );\r
367                                                                                                 else\r
368                                                                                                         selectedTable.removeAttribute( 'border' );\r
369                                                                                         }\r
370                                                                                 },\r
371                                                                                 {\r
372                                                                                         id : 'cmbAlign',\r
373                                                                                         type : 'select',\r
374                                                                                         'default' : '',\r
375                                                                                         label : editor.lang.common.align,\r
376                                                                                         items :\r
377                                                                                         [\r
378                                                                                                 [ editor.lang.common.notSet , ''],\r
379                                                                                                 [ editor.lang.common.alignLeft , 'left'],\r
380                                                                                                 [ editor.lang.common.alignCenter , 'center'],\r
381                                                                                                 [ editor.lang.common.alignRight , 'right']\r
382                                                                                         ],\r
383                                                                                         setup : function( selectedTable )\r
384                                                                                         {\r
385                                                                                                 this.setValue( selectedTable.getAttribute( 'align' ) || '' );\r
386                                                                                         },\r
387                                                                                         commit : function( data, selectedTable )\r
388                                                                                         {\r
389                                                                                                 if ( this.getValue() )\r
390                                                                                                         selectedTable.setAttribute( 'align', this.getValue() );\r
391                                                                                                 else\r
392                                                                                                         selectedTable.removeAttribute( 'align' );\r
393                                                                                         }\r
394                                                                                 }\r
395                                                                         ]\r
396                                                                 },\r
397                                                                 {\r
398                                                                         type : 'vbox',\r
399                                                                         padding : 0,\r
400                                                                         children :\r
401                                                                         [\r
402                                                                                 {\r
403                                                                                         type : 'hbox',\r
404                                                                                         widths : [ '5em' ],\r
405                                                                                         children :\r
406                                                                                         [\r
407                                                                                                 {\r
408                                                                                                         type : 'text',\r
409                                                                                                         id : 'txtWidth',\r
410                                                                                                         controlStyle : 'width:5em',\r
411                                                                                                         label : editor.lang.common.width,\r
412                                                                                                         'default' : 500,\r
413                                                                                                         getValue : defaultToPixel,\r
414                                                                                                         validate : CKEDITOR.dialog.validate.cssLength( editor.lang.common.invalidCssLength.replace( '%1', editor.lang.common.width ) ),\r
415                                                                                                         onChange : function()\r
416                                                                                                         {\r
417                                                                                                                 var styles = this.getDialog().getContentElement( 'advanced', 'advStyles' );\r
418                                                                                                                 styles && styles.updateStyle( 'width', this.getValue() );\r
419                                                                                                         },\r
420                                                                                                         setup : function( selectedTable )\r
421                                                                                                         {\r
422                                                                                                                 var val = selectedTable.getStyle( 'width' );\r
423                                                                                                                 val && this.setValue( val );\r
424                                                                                                         },\r
425                                                                                                         commit : commitValue\r
426                                                                                                 }\r
427                                                                                         ]\r
428                                                                                 },\r
429                                                                                 {\r
430                                                                                         type : 'hbox',\r
431                                                                                         widths : [ '5em' ],\r
432                                                                                         children :\r
433                                                                                         [\r
434                                                                                                 {\r
435                                                                                                         type : 'text',\r
436                                                                                                         id : 'txtHeight',\r
437                                                                                                         controlStyle : 'width:5em',\r
438                                                                                                         label : editor.lang.common.height,\r
439                                                                                                         'default' : '',\r
440                                                                                                         getValue : defaultToPixel,\r
441                                                                                                         validate : CKEDITOR.dialog.validate.cssLength( editor.lang.common.invalidCssLength.replace( '%1', editor.lang.common.height ) ),\r
442                                                                                                         onChange : function()\r
443                                                                                                         {\r
444                                                                                                                 var styles = this.getDialog().getContentElement( 'advanced', 'advStyles' );\r
445                                                                                                                 styles && styles.updateStyle( 'height', this.getValue() );\r
446                                                                                                         },\r
447 \r
448                                                                                                         setup : function( selectedTable )\r
449                                                                                                         {\r
450                                                                                                                 var val = selectedTable.getStyle( 'width' );\r
451                                                                                                                 val && this.setValue( val );\r
452                                                                                                         },\r
453                                                                                                         commit : commitValue\r
454                                                                                                 }\r
455                                                                                         ]\r
456                                                                                 },\r
457                                                                                 {\r
458                                                                                         type : 'html',\r
459                                                                                         html : '&nbsp;'\r
460                                                                                 },\r
461                                                                                 {\r
462                                                                                         type : 'text',\r
463                                                                                         id : 'txtCellSpace',\r
464                                                                                         controlStyle : 'width:3em',\r
465                                                                                         label : editor.lang.table.cellSpace,\r
466                                                                                         'default' : 1,\r
467                                                                                         validate : CKEDITOR.dialog.validate.number( editor.lang.table.invalidCellSpacing ),\r
468                                                                                         setup : function( selectedTable )\r
469                                                                                         {\r
470                                                                                                 this.setValue( selectedTable.getAttribute( 'cellSpacing' ) || '' );\r
471                                                                                         },\r
472                                                                                         commit : function( data, selectedTable )\r
473                                                                                         {\r
474                                                                                                 if ( this.getValue() )\r
475                                                                                                         selectedTable.setAttribute( 'cellSpacing', this.getValue() );\r
476                                                                                                 else\r
477                                                                                                         selectedTable.removeAttribute( 'cellSpacing' );\r
478                                                                                         }\r
479                                                                                 },\r
480                                                                                 {\r
481                                                                                         type : 'text',\r
482                                                                                         id : 'txtCellPad',\r
483                                                                                         controlStyle : 'width:3em',\r
484                                                                                         label : editor.lang.table.cellPad,\r
485                                                                                         'default' : 1,\r
486                                                                                         validate : CKEDITOR.dialog.validate.number( editor.lang.table.invalidCellPadding ),\r
487                                                                                         setup : function( selectedTable )\r
488                                                                                         {\r
489                                                                                                 this.setValue( selectedTable.getAttribute( 'cellPadding' ) || '' );\r
490                                                                                         },\r
491                                                                                         commit : function( data, selectedTable )\r
492                                                                                         {\r
493                                                                                                 if ( this.getValue() )\r
494                                                                                                         selectedTable.setAttribute( 'cellPadding', this.getValue() );\r
495                                                                                                 else\r
496                                                                                                         selectedTable.removeAttribute( 'cellPadding' );\r
497                                                                                         }\r
498                                                                                 }\r
499                                                                         ]\r
500                                                                 }\r
501                                                         ]\r
502                                                 },\r
503                                                 {\r
504                                                         type : 'html',\r
505                                                         align : 'right',\r
506                                                         html : ''\r
507                                                 },\r
508                                                 {\r
509                                                         type : 'vbox',\r
510                                                         padding : 0,\r
511                                                         children :\r
512                                                         [\r
513                                                                 {\r
514                                                                         type : 'text',\r
515                                                                         id : 'txtCaption',\r
516                                                                         label : editor.lang.table.caption,\r
517                                                                         setup : function( selectedTable )\r
518                                                                         {\r
519                                                                                 this.enable();\r
520 \r
521                                                                                 var nodeList = selectedTable.getElementsByTag( 'caption' );\r
522                                                                                 if ( nodeList.count() > 0 )\r
523                                                                                 {\r
524                                                                                         var caption = nodeList.getItem( 0 );\r
525                                                                                         var firstElementChild = caption.getFirst( CKEDITOR.dom.walker.nodeType( CKEDITOR.NODE_ELEMENT ) );\r
526 \r
527                                                                                         if ( firstElementChild && !firstElementChild.equals( caption.getBogus() ) )\r
528                                                                                         {\r
529                                                                                                 this.disable();\r
530                                                                                                 this.setValue( caption.getText() );\r
531                                                                                                 return;\r
532                                                                                         }\r
533 \r
534                                                                                         caption = CKEDITOR.tools.trim( caption.getText() );\r
535                                                                                         this.setValue( caption );\r
536                                                                                 }\r
537                                                                         },\r
538                                                                         commit : function( data, table )\r
539                                                                         {\r
540                                                                                 if ( !this.isEnabled() )\r
541                                                                                         return;\r
542 \r
543                                                                                 var caption = this.getValue(),\r
544                                                                                         captionElement = table.getElementsByTag( 'caption' );\r
545                                                                                 if ( caption )\r
546                                                                                 {\r
547                                                                                         if ( captionElement.count() > 0 )\r
548                                                                                         {\r
549                                                                                                 captionElement = captionElement.getItem( 0 );\r
550                                                                                                 captionElement.setHtml( '' );\r
551                                                                                         }\r
552                                                                                         else\r
553                                                                                         {\r
554                                                                                                 captionElement = new CKEDITOR.dom.element( 'caption', editor.document );\r
555                                                                                                 if ( table.getChildCount() )\r
556                                                                                                         captionElement.insertBefore( table.getFirst() );\r
557                                                                                                 else\r
558                                                                                                         captionElement.appendTo( table );\r
559                                                                                         }\r
560                                                                                         captionElement.append( new CKEDITOR.dom.text( caption, editor.document ) );\r
561                                                                                 }\r
562                                                                                 else if ( captionElement.count() > 0 )\r
563                                                                                 {\r
564                                                                                         for ( var i = captionElement.count() - 1 ; i >= 0 ; i-- )\r
565                                                                                                 captionElement.getItem( i ).remove();\r
566                                                                                 }\r
567                                                                         }\r
568                                                                 },\r
569                                                                 {\r
570                                                                         type : 'text',\r
571                                                                         id : 'txtSummary',\r
572                                                                         label : editor.lang.table.summary,\r
573                                                                         setup : function( selectedTable )\r
574                                                                         {\r
575                                                                                 this.setValue( selectedTable.getAttribute( 'summary' ) || '' );\r
576                                                                         },\r
577                                                                         commit : function( data, selectedTable )\r
578                                                                         {\r
579                                                                                 if ( this.getValue() )\r
580                                                                                         selectedTable.setAttribute( 'summary', this.getValue() );\r
581                                                                                 else\r
582                                                                                         selectedTable.removeAttribute( 'summary' );\r
583                                                                         }\r
584                                                                 }\r
585                                                         ]\r
586                                                 }\r
587                                         ]\r
588                                 },\r
589                                 dialogadvtab && dialogadvtab.createAdvancedTab( editor )\r
590                         ]\r
591                 };\r
592         }\r
593 \r
594         CKEDITOR.dialog.add( 'table', function( editor )\r
595                 {\r
596                         return tableDialog( editor, 'table' );\r
597                 } );\r
598         CKEDITOR.dialog.add( 'tableProperties', function( editor )\r
599                 {\r
600                         return tableDialog( editor, 'tableProperties' );\r
601                 } );\r
602 })();\r