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
16 rtl = editor.lang.dir == 'rtl';
\r
21 * @param callback [ childDialog ]
\r
23 function getDialogValue( dialogName, callback )
\r
25 var onOk = function()
\r
27 releaseHandlers( this );
\r
28 callback( this, this._.parentDialog );
\r
29 this._.parentDialog.changeFocus( true );
\r
31 var onCancel = function()
\r
33 releaseHandlers( this );
\r
34 this._.parentDialog.changeFocus();
\r
36 var releaseHandlers = function( dialog )
\r
38 dialog.removeListener( 'ok', onOk );
\r
39 dialog.removeListener( 'cancel', onCancel );
\r
41 var bindToDialog = function( dialog )
\r
43 dialog.on( 'ok', onOk );
\r
44 dialog.on( 'cancel', onCancel );
\r
46 editor.execCommand( dialogName );
\r
47 if ( editor._.storedDialogs.colordialog )
\r
48 bindToDialog( editor._.storedDialogs.colordialog );
\r
51 CKEDITOR.on( 'dialogDefinition', function( e )
\r
53 if ( e.data.name != dialogName )
\r
56 var definition = e.data.definition;
\r
59 definition.onLoad = CKEDITOR.tools.override( definition.onLoad, function( orginal )
\r
63 bindToDialog( this );
\r
64 definition.onLoad = orginal;
\r
65 if ( typeof orginal == 'function' )
\r
66 orginal.call( this );
\r
74 title : langCell.title,
\r
75 minWidth : CKEDITOR.env.ie && CKEDITOR.env.quirks? 450 : 410,
\r
76 minHeight : CKEDITOR.env.ie && CKEDITOR.env.quirks? 230 : 200,
\r
80 label : langCell.title,
\r
86 widths : [ '40%', '5%', '40%' ],
\r
96 widths : [ '70%', '30%' ],
\r
103 label : langCommon.width,
\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 label : editor.lang.table.widthUnit,
\r
143 labelStyle: 'visibility:hidden',
\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 : langCommon.height,
\r
170 validate : validate[ 'number' ]( langCell.invalidHeight ),
\r
172 // Extra labelling of height unit type.
\r
173 onLoad : function()
\r
175 var heightType = this.getDialog().getContentElement( 'info', 'htmlHeightType' ),
\r
176 labelElement = heightType.getElement(),
\r
177 inputElement = this.getInputElement(),
\r
178 ariaLabelledByAttr = inputElement.getAttribute( 'aria-labelledby' );
\r
180 inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) );
\r
183 setup : function( element )
\r
185 var heightAttr = parseInt( element.getAttribute( 'height' ), 10 ),
\r
186 heightStyle = parseInt( element.getStyle( 'height' ), 10 );
\r
188 !isNaN( heightAttr ) && this.setValue( heightAttr );
\r
189 !isNaN( heightStyle ) && this.setValue( heightStyle );
\r
191 commit : function( element )
\r
193 var value = parseInt( this.getValue(), 10 );
\r
195 if ( !isNaN( value ) )
\r
196 element.setStyle( 'height', CKEDITOR.tools.cssLength( value ) );
\r
198 element.removeStyle( 'height' );
\r
200 element.removeAttribute( 'height' );
\r
204 id : 'htmlHeightType',
\r
206 html : '<br />'+ langTable.widthPx
\r
214 label : langCell.wordWrap,
\r
218 [ langCell.yes, 'yes' ],
\r
219 [ langCell.no, 'no' ]
\r
221 setup : function( element )
\r
223 var wordWrapAttr = element.getAttribute( 'noWrap' ),
\r
224 wordWrapStyle = element.getStyle( 'white-space' );
\r
226 if ( wordWrapStyle == 'nowrap' || wordWrapAttr )
\r
227 this.setValue( 'no' );
\r
229 commit : function( element )
\r
231 if ( this.getValue() == 'no' )
\r
232 element.setStyle( 'white-space', 'nowrap' );
\r
234 element.removeStyle( 'white-space' );
\r
236 element.removeAttribute( 'noWrap' );
\r
243 label : langCell.hAlign,
\r
247 [ langCommon.notSet, '' ],
\r
248 [ langCommon.alignLeft, 'left' ],
\r
249 [ langCommon.alignCenter, 'center' ],
\r
250 [ langCommon.alignRight, 'right' ]
\r
252 setup : function( element )
\r
254 var alignAttr = element.getAttribute( 'align' ),
\r
255 textAlignStyle = element.getStyle( 'text-align');
\r
257 this.setValue( textAlignStyle || alignAttr || '' );
\r
259 commit : function( selectedCell )
\r
261 var value = this.getValue();
\r
264 selectedCell.setStyle( 'text-align', value );
\r
266 selectedCell.removeStyle( 'text-align' );
\r
268 selectedCell.removeAttribute( 'align' );
\r
274 label : langCell.vAlign,
\r
278 [ langCommon.notSet, '' ],
\r
279 [ langCommon.alignTop, 'top' ],
\r
280 [ langCommon.alignMiddle, 'middle' ],
\r
281 [ langCommon.alignBottom, 'bottom' ],
\r
282 [ langCell.alignBaseline, 'baseline' ]
\r
284 setup : function( element )
\r
286 var vAlignAttr = element.getAttribute( 'vAlign' ),
\r
287 vAlignStyle = element.getStyle( 'vertical-align' );
\r
289 switch( vAlignStyle )
\r
291 // Ignore all other unrelated style values..
\r
301 this.setValue( vAlignStyle || vAlignAttr || '' );
\r
303 commit : function( element )
\r
305 var value = this.getValue();
\r
308 element.setStyle( 'vertical-align', value );
\r
310 element.removeStyle( 'vertical-align' );
\r
312 element.removeAttribute( 'vAlign' );
\r
326 label : langCell.cellType,
\r
330 [ langCell.data, 'td' ],
\r
331 [ langCell.header, 'th' ]
\r
333 setup : function( selectedCell )
\r
335 this.setValue( selectedCell.getName() );
\r
337 commit : function( selectedCell )
\r
339 selectedCell.renameNode( this.getValue() );
\r
346 label : langCell.rowSpan,
\r
348 validate : validate.integer( langCell.invalidRowSpan ),
\r
349 setup : function( selectedCell )
\r
351 var attrVal = parseInt( selectedCell.getAttribute( 'rowSpan' ), 10 );
\r
352 if ( attrVal && attrVal != 1 )
\r
353 this.setValue( attrVal );
\r
355 commit : function( selectedCell )
\r
357 var value = parseInt( this.getValue(), 10 );
\r
358 if ( value && value != 1 )
\r
359 selectedCell.setAttribute( 'rowSpan', this.getValue() );
\r
361 selectedCell.removeAttribute( 'rowSpan' );
\r
367 label : langCell.colSpan,
\r
369 validate : validate.integer( langCell.invalidColSpan ),
\r
370 setup : function( element )
\r
372 var attrVal = parseInt( element.getAttribute( 'colSpan' ), 10 );
\r
373 if ( attrVal && attrVal != 1 )
\r
374 this.setValue( attrVal );
\r
376 commit : function( selectedCell )
\r
378 var value = parseInt( this.getValue(), 10 );
\r
379 if ( value && value != 1 )
\r
380 selectedCell.setAttribute( 'colSpan', this.getValue() );
\r
382 selectedCell.removeAttribute( 'colSpan' );
\r
389 widths : [ '60%', '40%' ],
\r
395 label : langCell.bgColor,
\r
397 setup : function( element )
\r
399 var bgColorAttr = element.getAttribute( 'bgColor' ),
\r
400 bgColorStyle = element.getStyle( 'background-color' );
\r
402 this.setValue( bgColorStyle || bgColorAttr );
\r
404 commit : function( selectedCell )
\r
406 var value = this.getValue();
\r
409 selectedCell.setStyle( 'background-color', this.getValue() );
\r
411 selectedCell.removeStyle( 'background-color' );
\r
413 selectedCell.removeAttribute( 'bgColor');
\r
418 id : 'bgColorChoose',
\r
419 "class" : 'colorChooser',
\r
420 label : langCell.chooseColor,
\r
421 onLoad : function()
\r
423 // Stick the element to the bottom (#5587)
\r
424 this.getElement().getParent().setStyle( 'vertical-align', 'bottom' );
\r
426 onClick : function()
\r
429 getDialogValue( 'colordialog', function( colorDialog )
\r
431 self.getDialog().getContentElement( 'info', 'bgColor' ).setValue(
\r
432 colorDialog.getContentElement( 'picker', 'selectedColor' ).getValue()
\r
443 widths : [ '60%', '40%' ],
\r
448 id : 'borderColor',
\r
449 label : langCell.borderColor,
\r
451 setup : function( element )
\r
453 var borderColorAttr = element.getAttribute( 'borderColor' ),
\r
454 borderColorStyle = element.getStyle( 'border-color' );
\r
456 this.setValue( borderColorStyle || borderColorAttr );
\r
458 commit : function( selectedCell )
\r
460 var value = this.getValue();
\r
462 selectedCell.setStyle( 'border-color', this.getValue() );
\r
464 selectedCell.removeStyle( 'border-color' );
\r
466 selectedCell.removeAttribute( 'borderColor');
\r
471 id : 'borderColorChoose',
\r
472 "class" : 'colorChooser',
\r
473 label : langCell.chooseColor,
\r
474 style : ( rtl ? 'margin-right' : 'margin-left' ) + ': 10px',
\r
475 onLoad : function()
\r
477 // Stick the element to the bottom (#5587)
\r
478 this.getElement().getParent().setStyle( 'vertical-align', 'bottom' );
\r
480 onClick : function()
\r
483 getDialogValue( 'colordialog', function( colorDialog )
\r
485 self.getDialog().getContentElement( 'info', 'borderColor' ).setValue(
\r
486 colorDialog.getContentElement( 'picker', 'selectedColor' ).getValue()
\r
500 onShow : function()
\r
502 this.cells = CKEDITOR.plugins.tabletools.getSelectedCells(
\r
503 this._.editor.getSelection() );
\r
504 this.setupContent( this.cells[ 0 ] );
\r
508 var selection = this._.editor.getSelection(),
\r
509 bookmarks = selection.createBookmarks();
\r
511 var cells = this.cells;
\r
512 for ( var i = 0 ; i < cells.length ; i++ )
\r
513 this.commitContent( cells[ i ] );
\r
515 selection.selectBookmarks( bookmarks );
\r
517 // Force selectionChange event because of alignment style.
\r
518 var firstElement = selection.getStartElement();
\r
519 var currentPath = new CKEDITOR.dom.elementPath( firstElement );
\r
521 this._.editor._.selectionPreviousPath = currentPath;
\r
522 this._.editor.fire( 'selectionChange', { selection : selection, path : currentPath, element : firstElement } );
\r