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
27 callback( this, this._.parentDialog );
\r
28 this._.parentDialog.changeFocus( true );
\r
30 var onCancel = function()
\r
32 releaseHandlers( this );
\r
33 this._.parentDialog.changeFocus();
\r
35 var releaseHandlers = function( dialog )
\r
37 dialog.removeListener( 'ok', onOk );
\r
38 dialog.removeListener( 'cancel', onCancel );
\r
40 var bindToDialog = function( dialog )
\r
42 dialog.on( 'ok', onOk );
\r
43 dialog.on( 'cancel', onCancel );
\r
45 editor.execCommand( dialogName );
\r
46 if ( editor._.storedDialogs.colordialog )
\r
47 bindToDialog( editor._.storedDialogs.colordialog );
\r
50 CKEDITOR.on( 'dialogDefinition', function( e )
\r
52 if ( e.data.name != dialogName )
\r
55 var definition = e.data.definition;
\r
58 definition.onLoad = CKEDITOR.tools.override( definition.onLoad, function( orginal )
\r
62 bindToDialog( this );
\r
63 definition.onLoad = orginal;
\r
64 if ( typeof orginal == 'function' )
\r
65 orginal.call( this );
\r
73 title : langCell.title,
\r
74 minWidth : CKEDITOR.env.ie && CKEDITOR.env.quirks ? 550 : 480,
\r
75 minHeight : CKEDITOR.env.ie ? ( CKEDITOR.env.quirks ? 180 : 150 ) : 140,
\r
79 label : langCell.title,
\r
85 widths : [ '40%', '5%', '40%' ],
\r
95 widths : [ '70%', '30%' ],
\r
101 label : langTable.width,
\r
102 widths : [ '71%', '29%' ],
\r
103 labelLayout : 'horizontal',
\r
104 validate : validate[ 'number' ]( langCell.invalidWidth ),
\r
106 // Extra labelling of width unit type.
\r
107 onLoad : function()
\r
109 var widthType = this.getDialog().getContentElement( 'info', 'widthType' ),
\r
110 labelElement = widthType.getElement(),
\r
111 inputElement = this.getInputElement(),
\r
112 ariaLabelledByAttr = inputElement.getAttribute( 'aria-labelledby' );
\r
114 inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) );
\r
117 setup : function( element )
\r
119 var widthAttr = parseInt( element.getAttribute( 'width' ), 10 ),
\r
120 widthStyle = parseInt( element.getStyle( 'width' ), 10 );
\r
122 !isNaN( widthAttr ) && this.setValue( widthAttr );
\r
123 !isNaN( widthStyle ) && this.setValue( widthStyle );
\r
125 commit : function( element )
\r
127 var value = parseInt( this.getValue(), 10 ),
\r
128 unit = this.getDialog().getValueOf( 'info', 'widthType' );
\r
130 if ( !isNaN( value ) )
\r
131 element.setStyle( 'width', value + unit );
\r
133 element.removeStyle( 'width' );
\r
135 element.removeAttribute( 'width' );
\r
142 labelLayout : 'horizontal',
\r
143 widths : [ '0%', '100%' ],
\r
144 label : editor.lang.table.widthUnit,
\r
145 labelStyle: 'display:none',
\r
149 [ langTable.widthPx, 'px' ],
\r
150 [ langTable.widthPc, '%' ]
\r
152 setup : function( selectedCell )
\r
154 var widthMatch = widthPattern.exec( selectedCell.getStyle( 'width' ) || selectedCell.getAttribute( 'width' ) );
\r
156 this.setValue( widthMatch[2] );
\r
163 widths : [ '70%', '30%' ],
\r
169 label : langTable.height,
\r
171 widths : [ '71%', '29%' ],
\r
172 labelLayout : 'horizontal',
\r
173 validate : validate[ 'number' ]( langCell.invalidHeight ),
\r
175 // Extra labelling of height unit type.
\r
176 onLoad : function()
\r
178 var heightType = this.getDialog().getContentElement( 'info', 'htmlHeightType' ),
\r
179 labelElement = heightType.getElement(),
\r
180 inputElement = this.getInputElement(),
\r
181 ariaLabelledByAttr = inputElement.getAttribute( 'aria-labelledby' );
\r
183 inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) );
\r
186 setup : function( element )
\r
188 var heightAttr = parseInt( element.getAttribute( 'height' ), 10 ),
\r
189 heightStyle = parseInt( element.getStyle( 'height' ), 10 );
\r
191 !isNaN( heightAttr ) && this.setValue( heightAttr );
\r
192 !isNaN( heightStyle ) && this.setValue( heightStyle );
\r
194 commit : function( element )
\r
196 var value = parseInt( this.getValue(), 10 );
\r
198 if ( !isNaN( value ) )
\r
199 element.setStyle( 'height', CKEDITOR.tools.cssLength( value ) );
\r
201 element.removeStyle( 'height' );
\r
203 element.removeAttribute( 'height' );
\r
207 id : 'htmlHeightType',
\r
209 html : langTable.widthPx
\r
217 labelLayout : 'horizontal',
\r
218 label : langCell.wordWrap,
\r
219 widths : [ '50%', '50%' ],
\r
223 [ langCell.yes, 'yes' ],
\r
224 [ langCell.no, 'no' ]
\r
226 setup : function( element )
\r
228 var wordWrapAttr = element.getAttribute( 'noWrap' ),
\r
229 wordWrapStyle = element.getStyle( 'white-space' );
\r
231 if ( wordWrapStyle == 'nowrap' || wordWrapAttr )
\r
232 this.setValue( 'no' );
\r
234 commit : function( element )
\r
236 if ( this.getValue() == 'no' )
\r
237 element.setStyle( 'white-space', 'nowrap' );
\r
239 element.removeStyle( 'white-space' );
\r
241 element.removeAttribute( 'noWrap' );
\r
248 labelLayout : 'horizontal',
\r
249 label : langCell.hAlign,
\r
250 widths : [ '50%', '50%' ],
\r
254 [ langCommon.notSet, '' ],
\r
255 [ langTable.alignLeft, 'left' ],
\r
256 [ langTable.alignCenter, 'center' ],
\r
257 [ langTable.alignRight, 'right' ]
\r
259 setup : function( element )
\r
261 var alignAttr = element.getAttribute( 'align' ),
\r
262 textAlignStyle = element.getStyle( 'text-align');
\r
264 this.setValue( textAlignStyle || alignAttr || '' );
\r
266 commit : function( selectedCell )
\r
268 var value = this.getValue();
\r
271 selectedCell.setStyle( 'text-align', value );
\r
273 selectedCell.removeStyle( 'text-align' );
\r
275 selectedCell.removeAttribute( 'align' );
\r
281 labelLayout : 'horizontal',
\r
282 label : langCell.vAlign,
\r
283 widths : [ '50%', '50%' ],
\r
287 [ langCommon.notSet, '' ],
\r
288 [ langCell.alignTop, 'top' ],
\r
289 [ langCell.alignMiddle, 'middle' ],
\r
290 [ langCell.alignBottom, 'bottom' ],
\r
291 [ langCell.alignBaseline, 'baseline' ]
\r
293 setup : function( element )
\r
295 var vAlignAttr = element.getAttribute( 'vAlign' ),
\r
296 vAlignStyle = element.getStyle( 'vertical-align' );
\r
298 switch( vAlignStyle )
\r
300 // Ignore all other unrelated style values..
\r
310 this.setValue( vAlignStyle || vAlignAttr || '' );
\r
312 commit : function( element )
\r
314 var value = this.getValue();
\r
317 element.setStyle( 'vertical-align', value );
\r
319 element.removeStyle( 'vertical-align' );
\r
321 element.removeAttribute( 'vAlign' );
\r
335 label : langCell.cellType,
\r
336 labelLayout : 'horizontal',
\r
337 widths : [ '50%', '50%' ],
\r
341 [ langCell.data, 'td' ],
\r
342 [ langCell.header, 'th' ]
\r
344 setup : function( selectedCell )
\r
346 this.setValue( selectedCell.getName() );
\r
348 commit : function( selectedCell )
\r
350 selectedCell.renameNode( this.getValue() );
\r
357 label : langCell.rowSpan,
\r
358 labelLayout : 'horizontal',
\r
359 widths : [ '50%', '50%' ],
\r
361 validate : validate.integer( langCell.invalidRowSpan ),
\r
362 setup : function( selectedCell )
\r
364 var attrVal = parseInt( selectedCell.getAttribute( 'rowSpan' ), 10 );
\r
365 if ( attrVal && attrVal != 1 )
\r
366 this.setValue( attrVal );
\r
368 commit : function( selectedCell )
\r
370 var value = parseInt( this.getValue(), 10 );
\r
371 if ( value && value != 1 )
\r
372 selectedCell.setAttribute( 'rowSpan', this.getValue() );
\r
374 selectedCell.removeAttribute( 'rowSpan' );
\r
380 label : langCell.colSpan,
\r
381 labelLayout : 'horizontal',
\r
382 widths : [ '50%', '50%' ],
\r
384 validate : validate.integer( langCell.invalidColSpan ),
\r
385 setup : function( element )
\r
387 var attrVal = parseInt( element.getAttribute( 'colSpan' ), 10 );
\r
388 if ( attrVal && attrVal != 1 )
\r
389 this.setValue( attrVal );
\r
391 commit : function( selectedCell )
\r
393 var value = parseInt( this.getValue(), 10 );
\r
394 if ( value && value != 1 )
\r
395 selectedCell.setAttribute( 'colSpan', this.getValue() );
\r
397 selectedCell.removeAttribute( 'colSpan' );
\r
404 widths : [ '80%', '20%' ],
\r
410 label : langCell.bgColor,
\r
411 labelLayout : 'horizontal',
\r
412 widths : [ '70%', '30%' ],
\r
414 setup : function( element )
\r
416 var bgColorAttr = element.getAttribute( 'bgColor' ),
\r
417 bgColorStyle = element.getStyle( 'background-color' );
\r
419 this.setValue( bgColorStyle || bgColorAttr );
\r
421 commit : function( selectedCell )
\r
423 var value = this.getValue();
\r
426 selectedCell.setStyle( 'background-color', this.getValue() );
\r
428 selectedCell.removeStyle( 'background-color' );
\r
430 selectedCell.removeAttribute( 'bgColor');
\r
435 id : 'bgColorChoose',
\r
436 label : langCell.chooseColor,
\r
437 style : 'margin-left: 10px',
\r
438 onClick : function()
\r
441 getDialogValue( 'colordialog', function( colorDialog )
\r
443 self.getDialog().getContentElement( 'info', 'bgColor' ).setValue(
\r
444 colorDialog.getContentElement( 'picker', 'selectedColor' ).getValue()
\r
455 widths : [ '80%', '20%' ],
\r
460 id : 'borderColor',
\r
461 label : langCell.borderColor,
\r
462 labelLayout : 'horizontal',
\r
463 widths : [ '70%', '30%' ],
\r
465 setup : function( element )
\r
467 var borderColorAttr = element.getAttribute( 'borderColor' ),
\r
468 borderColorStyle = element.getStyle( 'border-color' );
\r
470 this.setValue( borderColorStyle || borderColorAttr );
\r
472 commit : function( selectedCell )
\r
474 var value = this.getValue();
\r
476 selectedCell.setStyle( 'border-color', this.getValue() );
\r
478 selectedCell.removeStyle( 'border-color' );
\r
480 selectedCell.removeAttribute( 'borderColor');
\r
485 id : 'borderColorChoose',
\r
486 label : langCell.chooseColor,
\r
487 style : 'margin-left: 10px',
\r
488 onClick : function()
\r
491 getDialogValue( 'colordialog', function( colorDialog )
\r
493 self.getDialog().getContentElement( 'info', 'borderColor' ).setValue(
\r
494 colorDialog.getContentElement( 'picker', 'selectedColor' ).getValue()
\r
508 onShow : function()
\r
510 this.cells = CKEDITOR.plugins.tabletools.getSelectedCells(
\r
511 this._.editor.getSelection() );
\r
512 this.setupContent( this.cells[ 0 ] );
\r
516 var selection = this._.editor.getSelection(),
\r
517 bookmarks = selection.createBookmarks();
\r
519 var cells = this.cells;
\r
520 for ( var i = 0 ; i < cells.length ; i++ )
\r
521 this.commitContent( cells[ i ] );
\r
523 selection.selectBookmarks( bookmarks );
\r
525 // Force selectionChange event because of alignment style.
\r
526 var firstElement = selection.getStartElement();
\r
527 var currentPath = new CKEDITOR.dom.elementPath( firstElement );
\r
529 this._.editor._.selectionPreviousPath = currentPath;
\r
530 this._.editor.fire( 'selectionChange', { selection : selection, path : currentPath, element : firstElement } );
\r