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