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 langCell = langTable.cell,
\r
10 langCommon = editor.lang.common,
\r
11 validate = CKEDITOR.dialog.validate,
\r
12 widthPattern = /^(\d+(?:\.\d+)?)(px|%)$/,
\r
13 heightPattern = /^(\d+(?:\.\d+)?)px$/,
\r
14 bind = CKEDITOR.tools.bind,
\r
15 spacer = { type : 'html', html : ' ' };
\r
20 * @param callback [ childDialog ]
\r
22 function getDialogValue( dialogName, callback )
\r
24 var onOk = function()
\r
26 releaseHandlers( this );
\r
29 var onCancel = function()
\r
31 releaseHandlers( this );
\r
33 var releaseHandlers = function( dialog )
\r
35 dialog.removeListener( 'ok', onOk );
\r
36 dialog.removeListener( 'cancel', onCancel );
\r
38 var bindToDialog = function( dialog )
\r
40 dialog.on( 'ok', onOk );
\r
41 dialog.on( 'cancel', onCancel );
\r
43 editor.execCommand( dialogName );
\r
44 if ( editor._.storedDialogs.colordialog )
\r
45 bindToDialog( editor._.storedDialogs.colordialog );
\r
48 CKEDITOR.on( 'dialogDefinition', function( e )
\r
50 if ( e.data.name != dialogName )
\r
53 var definition = e.data.definition;
\r
56 definition.onLoad = CKEDITOR.tools.override( definition.onLoad, function( orginal )
\r
60 bindToDialog( this );
\r
61 definition.onLoad = orginal;
\r
62 if ( typeof orginal == 'function' )
\r
63 orginal.call( this );
\r
71 title : langCell.title,
\r
72 minWidth : CKEDITOR.env.ie && CKEDITOR.env.quirks ? 550 : 480,
\r
73 minHeight : CKEDITOR.env.ie ? ( CKEDITOR.env.quirks ? 180 : 150 ) : 140,
\r
77 label : langCell.title,
\r
83 widths : [ '40%', '5%', '40%' ],
\r
93 widths : [ '70%', '30%' ],
\r
99 label : langTable.width,
\r
100 widths : [ '71%', '29%' ],
\r
101 labelLayout : 'horizontal',
\r
102 validate : validate[ 'number' ]( langCell.invalidWidth ),
\r
104 // Extra labelling of width unit type.
\r
105 onLoad : function()
\r
107 var widthType = this.getDialog().getContentElement( 'info', 'widthType' ),
\r
108 labelElement = widthType.getElement(),
\r
109 inputElement = this.getInputElement(),
\r
110 ariaLabelledByAttr = inputElement.getAttribute( 'aria-labelledby' );
\r
112 inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) );
\r
115 setup : function( element )
\r
117 var widthAttr = parseInt( element.getAttribute( 'width' ), 10 ),
\r
118 widthStyle = parseInt( element.getStyle( 'width' ), 10 );
\r
120 !isNaN( widthAttr ) && this.setValue( widthAttr );
\r
121 !isNaN( widthStyle ) && this.setValue( widthStyle );
\r
123 commit : function( element )
\r
125 var value = parseInt( this.getValue(), 10 ),
\r
126 unit = this.getDialog().getValueOf( 'info', 'widthType' );
\r
128 if ( !isNaN( value ) )
\r
129 element.setStyle( 'width', value + unit );
\r
131 element.removeStyle( 'width' );
\r
133 element.removeAttribute( 'width' );
\r
140 labelLayout : 'horizontal',
\r
141 widths : [ '0%', '100%' ],
\r
142 label : editor.lang.table.widthUnit,
\r
143 labelStyle: 'display:none',
\r
147 [ langTable.widthPx, 'px' ],
\r
148 [ langTable.widthPc, '%' ]
\r
150 setup : function( selectedCell )
\r
152 var widthMatch = widthPattern.exec( selectedCell.getStyle( 'width' ) || selectedCell.getAttribute( 'width' ) );
\r
154 this.setValue( widthMatch[2] );
\r
161 widths : [ '70%', '30%' ],
\r
167 label : langTable.height,
\r
169 widths : [ '71%', '29%' ],
\r
170 labelLayout : 'horizontal',
\r
171 validate : validate[ 'number' ]( langCell.invalidHeight ),
\r
173 // Extra labelling of height unit type.
\r
174 onLoad : function()
\r
176 var heightType = this.getDialog().getContentElement( 'info', 'htmlHeightType' ),
\r
177 labelElement = heightType.getElement(),
\r
178 inputElement = this.getInputElement(),
\r
179 ariaLabelledByAttr = inputElement.getAttribute( 'aria-labelledby' );
\r
181 inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) );
\r
184 setup : function( element )
\r
186 var heightAttr = parseInt( element.getAttribute( 'height' ), 10 ),
\r
187 heightStyle = parseInt( element.getStyle( 'height' ), 10 );
\r
189 !isNaN( heightAttr ) && this.setValue( heightAttr );
\r
190 !isNaN( heightStyle ) && this.setValue( heightStyle );
\r
192 commit : function( element )
\r
194 var value = parseInt( this.getValue(), 10 );
\r
196 if ( !isNaN( value ) )
\r
197 element.setStyle( 'height', CKEDITOR.tools.cssLength( value ) );
\r
199 element.removeStyle( 'height' );
\r
201 element.removeAttribute( 'height' );
\r
205 id : 'htmlHeightType',
\r
207 html : langTable.widthPx
\r
215 labelLayout : 'horizontal',
\r
216 label : langCell.wordWrap,
\r
217 widths : [ '50%', '50%' ],
\r
221 [ langCell.yes, 'yes' ],
\r
222 [ langCell.no, 'no' ]
\r
224 setup : function( element )
\r
226 var wordWrapAttr = element.getAttribute( 'noWrap' ),
\r
227 wordWrapStyle = element.getStyle( 'white-space' );
\r
229 if ( wordWrapStyle == 'nowrap' || wordWrapAttr )
\r
230 this.setValue( 'no' );
\r
232 commit : function( element )
\r
234 if ( this.getValue() == 'no' )
\r
235 element.setStyle( 'white-space', 'nowrap' );
\r
237 element.removeStyle( 'white-space' );
\r
239 element.removeAttribute( 'noWrap' );
\r
246 labelLayout : 'horizontal',
\r
247 label : langCell.hAlign,
\r
248 widths : [ '50%', '50%' ],
\r
252 [ langCommon.notSet, '' ],
\r
253 [ langTable.alignLeft, 'left' ],
\r
254 [ langTable.alignCenter, 'center' ],
\r
255 [ langTable.alignRight, 'right' ]
\r
257 setup : function( element )
\r
259 var alignAttr = element.getAttribute( 'align' ),
\r
260 textAlignStyle = element.getStyle( 'text-align');
\r
262 this.setValue( textAlignStyle || alignAttr || '' );
\r
264 commit : function( selectedCell )
\r
266 var value = this.getValue();
\r
269 selectedCell.setStyle( 'text-align', value );
\r
271 selectedCell.removeStyle( 'text-align' );
\r
273 selectedCell.removeAttribute( 'align' );
\r
279 labelLayout : 'horizontal',
\r
280 label : langCell.vAlign,
\r
281 widths : [ '50%', '50%' ],
\r
285 [ langCommon.notSet, '' ],
\r
286 [ langCell.alignTop, 'top' ],
\r
287 [ langCell.alignMiddle, 'middle' ],
\r
288 [ langCell.alignBottom, 'bottom' ],
\r
289 [ langCell.alignBaseline, 'baseline' ]
\r
291 setup : function( element )
\r
293 var vAlignAttr = element.getAttribute( 'vAlign' ),
\r
294 vAlignStyle = element.getStyle( 'vertical-align' );
\r
296 switch( vAlignStyle )
\r
298 // Ignore all other unrelated style values..
\r
308 this.setValue( vAlignStyle || vAlignAttr || '' );
\r
310 commit : function( element )
\r
312 var value = this.getValue();
\r
315 element.setStyle( 'vertical-align', value );
\r
317 element.removeStyle( 'vertical-align' );
\r
319 element.removeAttribute( 'vAlign' );
\r
333 label : langCell.cellType,
\r
334 labelLayout : 'horizontal',
\r
335 widths : [ '50%', '50%' ],
\r
339 [ langCell.data, 'td' ],
\r
340 [ langCell.header, 'th' ]
\r
342 setup : function( selectedCell )
\r
344 this.setValue( selectedCell.getName() );
\r
346 commit : function( selectedCell )
\r
348 selectedCell.renameNode( this.getValue() );
\r
355 label : langCell.rowSpan,
\r
356 labelLayout : 'horizontal',
\r
357 widths : [ '50%', '50%' ],
\r
359 validate : validate.integer( langCell.invalidRowSpan ),
\r
360 setup : function( selectedCell )
\r
362 var attrVal = parseInt( selectedCell.getAttribute( 'rowSpan' ), 10 );
\r
363 if ( attrVal && attrVal != 1 )
\r
364 this.setValue( attrVal );
\r
366 commit : function( selectedCell )
\r
368 var value = parseInt( this.getValue(), 10 );
\r
369 if ( value && value != 1 )
\r
370 selectedCell.setAttribute( 'rowSpan', this.getValue() );
\r
372 selectedCell.removeAttribute( 'rowSpan' );
\r
378 label : langCell.colSpan,
\r
379 labelLayout : 'horizontal',
\r
380 widths : [ '50%', '50%' ],
\r
382 validate : validate.integer( langCell.invalidColSpan ),
\r
383 setup : function( element )
\r
385 var attrVal = parseInt( element.getAttribute( 'colSpan' ), 10 );
\r
386 if ( attrVal && attrVal != 1 )
\r
387 this.setValue( attrVal );
\r
389 commit : function( selectedCell )
\r
391 var value = parseInt( this.getValue(), 10 );
\r
392 if ( value && value != 1 )
\r
393 selectedCell.setAttribute( 'colSpan', this.getValue() );
\r
395 selectedCell.removeAttribute( 'colSpan' );
\r
402 widths : [ '80%', '20%' ],
\r
408 label : langCell.bgColor,
\r
409 labelLayout : 'horizontal',
\r
410 widths : [ '70%', '30%' ],
\r
412 setup : function( element )
\r
414 var bgColorAttr = element.getAttribute( 'bgColor' ),
\r
415 bgColorStyle = element.getStyle( 'background-color' );
\r
417 this.setValue( bgColorStyle || bgColorAttr );
\r
419 commit : function( selectedCell )
\r
421 var value = this.getValue();
\r
424 selectedCell.setStyle( 'background-color', this.getValue() );
\r
426 selectedCell.removeStyle( 'background-color' );
\r
428 selectedCell.removeAttribute( 'bgColor');
\r
433 id : 'bgColorChoose',
\r
434 label : langCell.chooseColor,
\r
435 style : 'margin-left: 10px',
\r
436 onClick : function()
\r
439 getDialogValue( 'colordialog', function( colorDialog )
\r
441 self.getDialog().getContentElement( 'info', 'bgColor' ).setValue(
\r
442 colorDialog.getContentElement( 'picker', 'selectedColor' ).getValue()
\r
453 widths : [ '80%', '20%' ],
\r
458 id : 'borderColor',
\r
459 label : langCell.borderColor,
\r
460 labelLayout : 'horizontal',
\r
461 widths : [ '70%', '30%' ],
\r
463 setup : function( element )
\r
465 var borderColorAttr = element.getAttribute( 'borderColor' ),
\r
466 borderColorStyle = element.getStyle( 'border-color' );
\r
468 this.setValue( borderColorStyle || borderColorAttr );
\r
470 commit : function( selectedCell )
\r
472 var value = this.getValue();
\r
474 selectedCell.setStyle( 'border-color', this.getValue() );
\r
476 selectedCell.removeStyle( 'border-color' );
\r
478 selectedCell.removeAttribute( 'borderColor');
\r
483 id : 'borderColorChoose',
\r
484 label : langCell.chooseColor,
\r
485 style : 'margin-left: 10px',
\r
486 onClick : function()
\r
489 getDialogValue( 'colordialog', function( colorDialog )
\r
491 self.getDialog().getContentElement( 'info', 'borderColor' ).setValue(
\r
492 colorDialog.getContentElement( 'picker', 'selectedColor' ).getValue()
\r
506 onShow : function()
\r
508 this.cells = CKEDITOR.plugins.tabletools.getSelectedCells(
\r
509 this._.editor.getSelection() );
\r
510 this.setupContent( this.cells[ 0 ] );
\r
514 var selection = this._.editor.getSelection(),
\r
515 bookmarks = selection.createBookmarks();
\r
517 var cells = this.cells;
\r
518 for ( var i = 0 ; i < cells.length ; i++ )
\r
519 this.commitContent( cells[ i ] );
\r
521 selection.selectBookmarks( bookmarks );
\r