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