2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.dialog.add( 'cellProperties', function( editor )
\r
8 var langTable = editor.lang.table;
\r
9 var langCell = langTable.cell;
\r
10 var langCommon = editor.lang.common;
\r
11 var validate = CKEDITOR.dialog.validate;
\r
12 var widthPattern = /^(\d+(?:\.\d+)?)(px|%)$/,
\r
13 heightPattern = /^(\d+(?:\.\d+)?)px$/;
\r
14 var bind = CKEDITOR.tools.bind;
\r
18 return { type : 'html', html : ' ' };
\r
24 * @param callback [ childDialog ]
\r
26 function getDialogValue( dialogName, callback )
\r
28 var onOk = function()
\r
30 releaseHandlers( this );
\r
33 var onCancel = function()
\r
35 releaseHandlers( this );
\r
37 var bindToDialog = function( dialog )
\r
39 dialog.on( 'ok', onOk );
\r
40 dialog.on( 'cancel', onCancel );
\r
42 var releaseHandlers = function( dialog )
\r
44 dialog.removeListener( 'ok', onOk );
\r
45 dialog.removeListener( 'cancel', onCancel );
\r
47 editor.execCommand( dialogName );
\r
48 if ( editor._.storedDialogs.colordialog )
\r
49 bindToDialog( editor._.storedDialogs.colordialog );
\r
52 CKEDITOR.on( 'dialogDefinition', function( e )
\r
54 if ( e.data.name != dialogName )
\r
57 var definition = e.data.definition;
\r
60 definition.onLoad = CKEDITOR.tools.override( definition.onLoad, function( orginal )
\r
64 bindToDialog( this );
\r
65 definition.onLoad = orginal;
\r
66 if ( typeof orginal == 'function' )
\r
67 orginal.call( this );
\r
75 title : langCell.title,
\r
76 minWidth : CKEDITOR.env.ie && CKEDITOR.env.quirks ? 550 : 480,
\r
77 minHeight : CKEDITOR.env.ie ? ( CKEDITOR.env.quirks ? 180 : 150 ) : 140,
\r
81 label : langCell.title,
\r
87 widths : [ '40%', '5%', '40%' ],
\r
97 widths : [ '70%', '30%' ],
\r
103 label : langTable.width,
\r
104 widths : [ '71%', '29%' ],
\r
105 labelLayout : 'horizontal',
\r
106 validate : validate[ 'number' ]( langCell.invalidWidth ),
\r
107 setup : function( element )
\r
109 var widthAttr = parseInt( element.getAttribute( 'width' ), 10 ),
\r
110 widthStyle = parseInt( element.getStyle( 'width' ), 10 );
\r
112 !isNaN( widthAttr ) && this.setValue( widthAttr );
\r
113 !isNaN( widthStyle ) && this.setValue( widthStyle );
\r
115 commit : function( element )
\r
117 var value = parseInt( this.getValue(), 10 ),
\r
118 unit = this.getDialog().getValueOf( 'info', 'widthType' );
\r
120 if ( !isNaN( value ) )
\r
121 element.setStyle( 'width', value + unit );
\r
123 element.removeStyle( 'width' );
\r
125 element.removeAttribute( 'width' );
\r
132 labelLayout : 'horizontal',
\r
133 widths : [ '0%', '100%' ],
\r
138 [ langTable.widthPx, 'px' ],
\r
139 [ langTable.widthPc, '%' ]
\r
141 setup : function( selectedCell )
\r
143 var widthMatch = widthPattern.exec( selectedCell.$.style.width );
\r
145 this.setValue( widthMatch[2] );
\r
152 widths : [ '70%', '30%' ],
\r
158 label : langTable.height,
\r
160 widths : [ '71%', '29%' ],
\r
161 labelLayout : 'horizontal',
\r
162 validate : validate[ 'number' ]( langCell.invalidHeight ),
\r
163 setup : function( element )
\r
165 var heightAttr = parseInt( element.getAttribute( 'height' ), 10 ),
\r
166 heightStyle = parseInt( element.getStyle( 'height' ), 10 );
\r
168 !isNaN( heightAttr ) && this.setValue( heightAttr );
\r
169 !isNaN( heightStyle ) && this.setValue( heightStyle );
\r
171 commit : function( element )
\r
173 var value = parseInt( this.getValue(), 10 );
\r
175 if ( !isNaN( value ) )
\r
176 element.setStyle( 'height', CKEDITOR.tools.cssLength( value ) );
\r
178 element.removeStyle( 'height' );
\r
180 element.removeAttribute( 'height' );
\r
185 html : langTable.widthPx
\r
193 labelLayout : 'horizontal',
\r
194 label : langCell.wordWrap,
\r
195 widths : [ '50%', '50%' ],
\r
199 [ langCell.yes, 'yes' ],
\r
200 [ langCell.no, 'no' ]
\r
202 setup : function( element )
\r
204 var wordWrapAttr = element.getAttribute( 'noWrap' ),
\r
205 wordWrapStyle = element.getStyle( 'white-space' );
\r
207 if ( wordWrapStyle == 'nowrap' || wordWrapAttr )
\r
208 this.setValue( 'no' );
\r
210 commit : function( element )
\r
212 if ( this.getValue() == 'no' )
\r
213 element.setStyle( 'white-space', 'nowrap' );
\r
215 element.removeStyle( 'white-space' );
\r
217 element.removeAttribute( 'noWrap' );
\r
224 labelLayout : 'horizontal',
\r
225 label : langCell.hAlign,
\r
226 widths : [ '50%', '50%' ],
\r
230 [ langCommon.notSet, '' ],
\r
231 [ langTable.alignLeft, 'left' ],
\r
232 [ langTable.alignCenter, 'center' ],
\r
233 [ langTable.alignRight, 'right' ]
\r
235 setup : function( element )
\r
237 var alignAttr = element.getAttribute( 'align' ),
\r
238 textAlignStyle = element.getStyle( 'text-align');
\r
240 this.setValue( textAlignStyle || alignAttr || '' );
\r
242 commit : function( selectedCell )
\r
244 var value = this.getValue();
\r
247 selectedCell.setStyle( 'text-align', value );
\r
249 selectedCell.removeStyle( 'text-align' );
\r
251 selectedCell.removeAttribute( 'align' );
\r
257 labelLayout : 'horizontal',
\r
258 label : langCell.vAlign,
\r
259 widths : [ '50%', '50%' ],
\r
263 [ langCommon.notSet, '' ],
\r
264 [ langCell.alignTop, 'top' ],
\r
265 [ langCell.alignMiddle, 'middle' ],
\r
266 [ langCell.alignBottom, 'bottom' ],
\r
267 [ langCell.alignBaseline, 'baseline' ]
\r
269 setup : function( element )
\r
271 var vAlignAttr = element.getAttribute( 'vAlign' ),
\r
272 vAlignStyle = element.getStyle( 'vertical-align' );
\r
274 switch( vAlignStyle )
\r
276 // Ignore all other unrelated style values..
\r
286 this.setValue( vAlignStyle || vAlignAttr || '' );
\r
288 commit : function( element )
\r
290 var value = this.getValue();
\r
293 element.setStyle( 'vertical-align', value );
\r
295 element.removeStyle( 'vertical-align' );
\r
297 element.removeAttribute( 'vAlign' );
\r
311 label : langCell.cellType,
\r
312 labelLayout : 'horizontal',
\r
313 widths : [ '50%', '50%' ],
\r
317 [ langCell.data, 'td' ],
\r
318 [ langCell.header, 'th' ]
\r
320 setup : function( selectedCell )
\r
322 this.setValue( selectedCell.getName() );
\r
324 commit : function( selectedCell )
\r
326 selectedCell.renameNode( this.getValue() );
\r
333 label : langCell.rowSpan,
\r
334 labelLayout : 'horizontal',
\r
335 widths : [ '50%', '50%' ],
\r
337 validate : validate.integer( langCell.invalidRowSpan ),
\r
338 setup : function( selectedCell )
\r
340 var attrVal = parseInt( selectedCell.getAttribute( 'rowSpan' ), 10 );
\r
341 if ( attrVal && attrVal != 1 )
\r
342 this.setValue( attrVal );
\r
344 commit : function( selectedCell )
\r
346 var value = parseInt( this.getValue(), 10 );
\r
347 if ( value && value != 1 )
\r
348 selectedCell.setAttribute( 'rowSpan', this.getValue() );
\r
350 selectedCell.removeAttribute( 'rowSpan' );
\r
356 label : langCell.colSpan,
\r
357 labelLayout : 'horizontal',
\r
358 widths : [ '50%', '50%' ],
\r
360 validate : validate.integer( langCell.invalidColSpan ),
\r
361 setup : function( element )
\r
363 var attrVal = parseInt( element.getAttribute( 'colSpan' ), 10 );
\r
364 if ( attrVal && attrVal != 1 )
\r
365 this.setValue( attrVal );
\r
367 commit : function( selectedCell )
\r
369 var value = parseInt( this.getValue(), 10 );
\r
370 if ( value && value != 1 )
\r
371 selectedCell.setAttribute( 'colSpan', this.getValue() );
\r
373 selectedCell.removeAttribute( 'colSpan' );
\r
380 widths : [ '80%', '20%' ],
\r
386 label : langCell.bgColor,
\r
387 labelLayout : 'horizontal',
\r
388 widths : [ '70%', '30%' ],
\r
390 setup : function( element )
\r
392 var bgColorAttr = element.getAttribute( 'bgColor' ),
\r
393 bgColorStyle = element.getStyle( 'background-color' );
\r
395 this.setValue( bgColorStyle || bgColorAttr );
\r
397 commit : function( selectedCell )
\r
399 var value = this.getValue();
\r
402 selectedCell.setStyle( 'background-color', this.getValue() );
\r
404 selectedCell.removeStyle( 'background-color' );
\r
406 selectedCell.removeAttribute( 'bgColor');
\r
411 id : 'bgColorChoose',
\r
412 label : langCell.chooseColor,
\r
413 style : 'margin-left: 10px',
\r
414 onClick : function()
\r
417 getDialogValue( 'colordialog', function( colorDialog )
\r
419 self.getDialog().getContentElement( 'info', 'bgColor' ).setValue(
\r
420 colorDialog.getContentElement( 'picker', 'selectedColor' ).getValue()
\r
431 widths : [ '80%', '20%' ],
\r
436 id : 'borderColor',
\r
437 label : langCell.borderColor,
\r
438 labelLayout : 'horizontal',
\r
439 widths : [ '70%', '30%' ],
\r
441 setup : function( element )
\r
443 var borderColorAttr = element.getAttribute( 'borderColor' ),
\r
444 borderColorStyle = element.getStyle( 'border-color' );
\r
446 this.setValue( borderColorStyle || borderColorAttr );
\r
448 commit : function( selectedCell )
\r
450 var value = this.getValue();
\r
452 selectedCell.setStyle( 'border-color', this.getValue() );
\r
454 selectedCell.removeStyle( 'border-color' );
\r
456 selectedCell.removeAttribute( 'borderColor');
\r
461 id : 'borderColorChoose',
\r
462 label : langCell.chooseColor,
\r
463 style : 'margin-left: 10px',
\r
464 onClick : function()
\r
467 getDialogValue( 'colordialog', function( colorDialog )
\r
469 self.getDialog().getContentElement( 'info', 'borderColor' ).setValue(
\r
470 colorDialog.getContentElement( 'picker', 'selectedColor' ).getValue()
\r
484 onShow : function()
\r
486 this.cells = CKEDITOR.plugins.tabletools.getSelectedCells(
\r
487 this._.editor.getSelection() );
\r
488 this.setupContent( this.cells[ 0 ] );
\r
492 var cells = this.cells;
\r
493 for ( var i = 0 ; i < cells.length ; i++ )
\r
494 this.commitContent( cells[ i ] );
\r