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