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