[2000] | 1 | /*
|
---|
| 2 | Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
---|
| 3 | For licensing, see LICENSE.html or http://ckeditor.com/license
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | CKEDITOR.dialog.add( 'cellProperties', function( editor )
|
---|
| 7 | {
|
---|
| 8 | var langTable = editor.lang.table;
|
---|
| 9 | var langCell = langTable.cell;
|
---|
| 10 | var langCommon = editor.lang.common;
|
---|
| 11 | var validate = CKEDITOR.dialog.validate;
|
---|
| 12 | var widthPattern = /^(\d+(?:\.\d+)?)(px|%)$/,
|
---|
| 13 | heightPattern = /^(\d+(?:\.\d+)?)px$/;
|
---|
| 14 | var bind = CKEDITOR.tools.bind;
|
---|
| 15 |
|
---|
| 16 | function spacer()
|
---|
| 17 | {
|
---|
| 18 | return { type : 'html', html : ' ' };
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | /**
|
---|
| 22 | *
|
---|
| 23 | * @param dialogName
|
---|
| 24 | * @param callback [ childDialog ]
|
---|
| 25 | */
|
---|
| 26 | function getDialogValue( dialogName, callback )
|
---|
| 27 | {
|
---|
| 28 | var onOk = function()
|
---|
| 29 | {
|
---|
| 30 | releaseHandlers( this );
|
---|
| 31 | callback( this );
|
---|
| 32 | };
|
---|
| 33 | var onCancel = function()
|
---|
| 34 | {
|
---|
| 35 | releaseHandlers( this );
|
---|
| 36 | };
|
---|
| 37 | var bindToDialog = function( dialog )
|
---|
| 38 | {
|
---|
| 39 | dialog.on( 'ok', onOk );
|
---|
| 40 | dialog.on( 'cancel', onCancel );
|
---|
| 41 | };
|
---|
| 42 | var releaseHandlers = function( dialog )
|
---|
| 43 | {
|
---|
| 44 | dialog.removeListener( 'ok', onOk );
|
---|
| 45 | dialog.removeListener( 'cancel', onCancel );
|
---|
| 46 | };
|
---|
| 47 | editor.execCommand( dialogName );
|
---|
| 48 | if ( editor._.storedDialogs.colordialog )
|
---|
| 49 | bindToDialog( editor._.storedDialogs.colordialog );
|
---|
| 50 | else
|
---|
| 51 | {
|
---|
| 52 | CKEDITOR.on( 'dialogDefinition', function( e )
|
---|
| 53 | {
|
---|
| 54 | if ( e.data.name != dialogName )
|
---|
| 55 | return;
|
---|
| 56 |
|
---|
| 57 | var definition = e.data.definition;
|
---|
| 58 |
|
---|
| 59 | e.removeListener();
|
---|
| 60 | definition.onLoad = CKEDITOR.tools.override( definition.onLoad, function( orginal )
|
---|
| 61 | {
|
---|
| 62 | return function()
|
---|
| 63 | {
|
---|
| 64 | bindToDialog( this );
|
---|
| 65 | definition.onLoad = orginal;
|
---|
| 66 | if ( typeof orginal == 'function' )
|
---|
| 67 | orginal.call( this );
|
---|
| 68 | };
|
---|
| 69 | } );
|
---|
| 70 | });
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | return {
|
---|
| 75 | title : langCell.title,
|
---|
| 76 | minWidth : CKEDITOR.env.ie && CKEDITOR.env.quirks ? 550 : 480,
|
---|
| 77 | minHeight : CKEDITOR.env.ie ? ( CKEDITOR.env.quirks ? 180 : 150 ) : 140,
|
---|
| 78 | contents : [
|
---|
| 79 | {
|
---|
| 80 | id : 'info',
|
---|
| 81 | label : langCell.title,
|
---|
| 82 | accessKey : 'I',
|
---|
| 83 | elements :
|
---|
| 84 | [
|
---|
| 85 | {
|
---|
| 86 | type : 'hbox',
|
---|
| 87 | widths : [ '40%', '5%', '40%' ],
|
---|
| 88 | children :
|
---|
| 89 | [
|
---|
| 90 | {
|
---|
| 91 | type : 'vbox',
|
---|
| 92 | padding : 0,
|
---|
| 93 | children :
|
---|
| 94 | [
|
---|
| 95 | {
|
---|
| 96 | type : 'hbox',
|
---|
| 97 | widths : [ '70%', '30%' ],
|
---|
| 98 | children :
|
---|
| 99 | [
|
---|
| 100 | {
|
---|
| 101 | type : 'text',
|
---|
| 102 | id : 'width',
|
---|
| 103 | label : langTable.width,
|
---|
| 104 | widths : [ '71%', '29%' ],
|
---|
| 105 | labelLayout : 'horizontal',
|
---|
| 106 | validate : validate[ 'number' ]( langCell.invalidWidth ),
|
---|
| 107 | setup : function( selectedCell )
|
---|
| 108 | {
|
---|
| 109 | var widthMatch = widthPattern.exec( selectedCell.$.style.width );
|
---|
| 110 | if ( widthMatch )
|
---|
| 111 | this.setValue( widthMatch[1] );
|
---|
| 112 | },
|
---|
| 113 | commit : function( selectedCell )
|
---|
| 114 | {
|
---|
| 115 | var unit = this.getDialog().getValueOf( 'info', 'widthType' );
|
---|
| 116 | if ( this.getValue() !== '' )
|
---|
| 117 | selectedCell.$.style.width = this.getValue() + unit;
|
---|
| 118 | else
|
---|
| 119 | selectedCell.$.style.width = '';
|
---|
| 120 | },
|
---|
| 121 | 'default' : ''
|
---|
| 122 | },
|
---|
| 123 | {
|
---|
| 124 | type : 'select',
|
---|
| 125 | id : 'widthType',
|
---|
| 126 | labelLayout : 'horizontal',
|
---|
| 127 | widths : [ '0%', '100%' ],
|
---|
| 128 | label : '',
|
---|
| 129 | 'default' : 'px',
|
---|
| 130 | items :
|
---|
| 131 | [
|
---|
| 132 | [ langTable.widthPx, 'px' ],
|
---|
| 133 | [ langTable.widthPc, '%' ]
|
---|
| 134 | ],
|
---|
| 135 | setup : function( selectedCell )
|
---|
| 136 | {
|
---|
| 137 | var widthMatch = widthPattern.exec( selectedCell.$.style.width );
|
---|
| 138 | if ( widthMatch )
|
---|
| 139 | this.setValue( widthMatch[2] );
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 | ]
|
---|
| 143 | },
|
---|
| 144 | {
|
---|
| 145 | type : 'hbox',
|
---|
| 146 | widths : [ '70%', '30%' ],
|
---|
| 147 | children :
|
---|
| 148 | [
|
---|
| 149 | {
|
---|
| 150 | type : 'text',
|
---|
| 151 | id : 'height',
|
---|
| 152 | label : langTable.height,
|
---|
| 153 | 'default' : '',
|
---|
| 154 | widths : [ '71%', '29%' ],
|
---|
| 155 | labelLayout : 'horizontal',
|
---|
| 156 | validate : validate[ 'number' ]( langCell.invalidHeight ),
|
---|
| 157 | setup : function( selectedCell )
|
---|
| 158 | {
|
---|
| 159 | var heightMatch = heightPattern.exec( selectedCell.$.style.height );
|
---|
| 160 | if ( heightMatch )
|
---|
| 161 | this.setValue( heightMatch[1] );
|
---|
| 162 | },
|
---|
| 163 | commit : function( selectedCell )
|
---|
| 164 | {
|
---|
| 165 | if ( this.getValue() !== '' )
|
---|
| 166 | selectedCell.$.style.height = this.getValue() + 'px';
|
---|
| 167 | else
|
---|
| 168 | selectedCell.$.style.height = '';
|
---|
| 169 | }
|
---|
| 170 | },
|
---|
| 171 | {
|
---|
| 172 | type : 'html',
|
---|
| 173 | html : langTable.widthPx
|
---|
| 174 | }
|
---|
| 175 | ]
|
---|
| 176 | },
|
---|
| 177 | spacer(),
|
---|
| 178 | {
|
---|
| 179 | type : 'select',
|
---|
| 180 | id : 'wordWrap',
|
---|
| 181 | labelLayout : 'horizontal',
|
---|
| 182 | label : langCell.wordWrap,
|
---|
| 183 | widths : [ '50%', '50%' ],
|
---|
| 184 | 'default' : 'yes',
|
---|
| 185 | items :
|
---|
| 186 | [
|
---|
| 187 | [ langCell.yes, 'yes' ],
|
---|
| 188 | [ langCell.no, 'no' ]
|
---|
| 189 | ],
|
---|
| 190 | commit : function( selectedCell )
|
---|
| 191 | {
|
---|
| 192 | if ( this.getValue() == 'no' )
|
---|
| 193 | selectedCell.setAttribute( 'noWrap', 'nowrap' );
|
---|
| 194 | else
|
---|
| 195 | selectedCell.removeAttribute( 'noWrap' );
|
---|
| 196 | }
|
---|
| 197 | },
|
---|
| 198 | spacer(),
|
---|
| 199 | {
|
---|
| 200 | type : 'select',
|
---|
| 201 | id : 'hAlign',
|
---|
| 202 | labelLayout : 'horizontal',
|
---|
| 203 | label : langCell.hAlign,
|
---|
| 204 | widths : [ '50%', '50%' ],
|
---|
| 205 | 'default' : '',
|
---|
| 206 | items :
|
---|
| 207 | [
|
---|
| 208 | [ langCommon.notSet, '' ],
|
---|
| 209 | [ langTable.alignLeft, 'left' ],
|
---|
| 210 | [ langTable.alignCenter, 'center' ],
|
---|
| 211 | [ langTable.alignRight, 'right' ]
|
---|
| 212 | ],
|
---|
| 213 | setup : function( selectedCell )
|
---|
| 214 | {
|
---|
| 215 | this.setValue( selectedCell.getAttribute( 'align' ) || '' );
|
---|
| 216 | },
|
---|
| 217 | commit : function( selectedCell )
|
---|
| 218 | {
|
---|
| 219 | if ( this.getValue() )
|
---|
| 220 | selectedCell.setAttribute( 'align', this.getValue() );
|
---|
| 221 | else
|
---|
| 222 | selectedCell.removeAttribute( 'align' );
|
---|
| 223 | }
|
---|
| 224 | },
|
---|
| 225 | {
|
---|
| 226 | type : 'select',
|
---|
| 227 | id : 'vAlign',
|
---|
| 228 | labelLayout : 'horizontal',
|
---|
| 229 | label : langCell.vAlign,
|
---|
| 230 | widths : [ '50%', '50%' ],
|
---|
| 231 | 'default' : '',
|
---|
| 232 | items :
|
---|
| 233 | [
|
---|
| 234 | [ langCommon.notSet, '' ],
|
---|
| 235 | [ langCell.alignTop, 'top' ],
|
---|
| 236 | [ langCell.alignMiddle, 'middle' ],
|
---|
| 237 | [ langCell.alignBottom, 'bottom' ],
|
---|
| 238 | [ langCell.alignBaseline, 'baseline' ]
|
---|
| 239 | ],
|
---|
| 240 | setup : function( selectedCell )
|
---|
| 241 | {
|
---|
| 242 | this.setValue( selectedCell.getAttribute( 'vAlign' ) || '' );
|
---|
| 243 | },
|
---|
| 244 | commit : function( selectedCell )
|
---|
| 245 | {
|
---|
| 246 | if ( this.getValue() )
|
---|
| 247 | selectedCell.setAttribute( 'vAlign', this.getValue() );
|
---|
| 248 | else
|
---|
| 249 | selectedCell.removeAttribute( 'vAlign' );
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
| 252 | ]
|
---|
| 253 | },
|
---|
| 254 | spacer(),
|
---|
| 255 | {
|
---|
| 256 | type : 'vbox',
|
---|
| 257 | padding : 0,
|
---|
| 258 | children :
|
---|
| 259 | [
|
---|
| 260 | {
|
---|
| 261 | type : 'select',
|
---|
| 262 | id : 'cellType',
|
---|
| 263 | label : langCell.cellType,
|
---|
| 264 | labelLayout : 'horizontal',
|
---|
| 265 | widths : [ '50%', '50%' ],
|
---|
| 266 | 'default' : 'td',
|
---|
| 267 | items :
|
---|
| 268 | [
|
---|
| 269 | [ langCell.data, 'td' ],
|
---|
| 270 | [ langCell.header, 'th' ]
|
---|
| 271 | ],
|
---|
| 272 | setup : function( selectedCell )
|
---|
| 273 | {
|
---|
| 274 | this.setValue( selectedCell.getName() );
|
---|
| 275 | },
|
---|
| 276 | commit : function( selectedCell )
|
---|
| 277 | {
|
---|
| 278 | selectedCell.renameNode( this.getValue() );
|
---|
| 279 | }
|
---|
| 280 | },
|
---|
| 281 | spacer(),
|
---|
| 282 | {
|
---|
| 283 | type : 'text',
|
---|
| 284 | id : 'rowSpan',
|
---|
| 285 | label : langCell.rowSpan,
|
---|
| 286 | labelLayout : 'horizontal',
|
---|
| 287 | widths : [ '50%', '50%' ],
|
---|
| 288 | 'default' : '',
|
---|
| 289 | validate : validate.integer( langCell.invalidRowSpan ),
|
---|
| 290 | setup : function( selectedCell )
|
---|
| 291 | {
|
---|
| 292 | this.setValue( selectedCell.getAttribute( 'rowSpan' ) || '' );
|
---|
| 293 | },
|
---|
| 294 | commit : function( selectedCell )
|
---|
| 295 | {
|
---|
| 296 | if ( this.getValue() )
|
---|
| 297 | selectedCell.setAttribute( 'rowSpan', this.getValue() );
|
---|
| 298 | else
|
---|
| 299 | selectedCell.removeAttribute( 'rowSpan' );
|
---|
| 300 | }
|
---|
| 301 | },
|
---|
| 302 | {
|
---|
| 303 | type : 'text',
|
---|
| 304 | id : 'colSpan',
|
---|
| 305 | label : langCell.colSpan,
|
---|
| 306 | labelLayout : 'horizontal',
|
---|
| 307 | widths : [ '50%', '50%' ],
|
---|
| 308 | 'default' : '',
|
---|
| 309 | validate : validate.integer( langCell.invalidColSpan ),
|
---|
| 310 | setup : function( selectedCell )
|
---|
| 311 | {
|
---|
| 312 | this.setValue( selectedCell.getAttribute( 'colSpan' ) || '' );
|
---|
| 313 | },
|
---|
| 314 | commit : function( selectedCell )
|
---|
| 315 | {
|
---|
| 316 | if ( this.getValue() )
|
---|
| 317 | selectedCell.setAttribute( 'colSpan', this.getValue() );
|
---|
| 318 | else
|
---|
| 319 | selectedCell.removeAttribute( 'colSpan' );
|
---|
| 320 | }
|
---|
| 321 | },
|
---|
| 322 | spacer(),
|
---|
| 323 | {
|
---|
| 324 | type : 'hbox',
|
---|
| 325 | padding : 0,
|
---|
| 326 | widths : [ '80%', '20%' ],
|
---|
| 327 | children :
|
---|
| 328 | [
|
---|
| 329 | {
|
---|
| 330 | type : 'text',
|
---|
| 331 | id : 'bgColor',
|
---|
| 332 | label : langCell.bgColor,
|
---|
| 333 | labelLayout : 'horizontal',
|
---|
| 334 | widths : [ '70%', '30%' ],
|
---|
| 335 | 'default' : '',
|
---|
| 336 | setup : function( selectedCell )
|
---|
| 337 | {
|
---|
| 338 | this.setValue( selectedCell.getAttribute( 'bgColor' ) || '' );
|
---|
| 339 | },
|
---|
| 340 | commit : function( selectedCell )
|
---|
| 341 | {
|
---|
| 342 | if ( this.getValue() )
|
---|
| 343 | selectedCell.setAttribute( 'bgColor', this.getValue() );
|
---|
| 344 | else
|
---|
| 345 | selectedCell.removeAttribute( 'bgColor' );
|
---|
| 346 | }
|
---|
| 347 | },
|
---|
| 348 | {
|
---|
| 349 | type : 'button',
|
---|
| 350 | id : 'bgColorChoose',
|
---|
| 351 | label : langCell.chooseColor,
|
---|
| 352 | style : 'margin-left: 10px',
|
---|
| 353 | onClick : function()
|
---|
| 354 | {
|
---|
| 355 | var self = this;
|
---|
| 356 | getDialogValue( 'colordialog', function( colorDialog )
|
---|
| 357 | {
|
---|
| 358 | self.getDialog().getContentElement( 'info', 'bgColor' ).setValue(
|
---|
| 359 | colorDialog.getContentElement( 'picker', 'selectedColor' ).getValue()
|
---|
| 360 | );
|
---|
| 361 | } );
|
---|
| 362 | }
|
---|
| 363 | }
|
---|
| 364 | ]
|
---|
| 365 | },
|
---|
| 366 | spacer(),
|
---|
| 367 | {
|
---|
| 368 | type : 'hbox',
|
---|
| 369 | padding : 0,
|
---|
| 370 | widths : [ '80%', '20%' ],
|
---|
| 371 | children :
|
---|
| 372 | [
|
---|
| 373 | {
|
---|
| 374 | type : 'text',
|
---|
| 375 | id : 'borderColor',
|
---|
| 376 | label : langCell.borderColor,
|
---|
| 377 | labelLayout : 'horizontal',
|
---|
| 378 | widths : [ '70%', '30%' ],
|
---|
| 379 | 'default' : '',
|
---|
| 380 | setup : function( selectedCell )
|
---|
| 381 | {
|
---|
| 382 | this.setValue( selectedCell.getStyle( 'border-color' ) || '' );
|
---|
| 383 | },
|
---|
| 384 | commit : function( selectedCell )
|
---|
| 385 | {
|
---|
| 386 | if ( this.getValue() )
|
---|
| 387 | selectedCell.setStyle( 'border-color', this.getValue() );
|
---|
| 388 | else
|
---|
| 389 | selectedCell.removeStyle( 'border-color' );
|
---|
| 390 | }
|
---|
| 391 | },
|
---|
| 392 | {
|
---|
| 393 | type : 'button',
|
---|
| 394 | id : 'borderColorChoose',
|
---|
| 395 | label : langCell.chooseColor,
|
---|
| 396 | style : 'margin-left: 10px',
|
---|
| 397 | onClick : function()
|
---|
| 398 | {
|
---|
| 399 | var self = this;
|
---|
| 400 | getDialogValue( 'colordialog', function( colorDialog )
|
---|
| 401 | {
|
---|
| 402 | self.getDialog().getContentElement( 'info', 'borderColor' ).setValue(
|
---|
| 403 | colorDialog.getContentElement( 'picker', 'selectedColor' ).getValue()
|
---|
| 404 | );
|
---|
| 405 | } );
|
---|
| 406 | }
|
---|
| 407 | }
|
---|
| 408 | ]
|
---|
| 409 | }
|
---|
| 410 | ]
|
---|
| 411 | }
|
---|
| 412 | ]
|
---|
| 413 | }
|
---|
| 414 | ]
|
---|
| 415 | }
|
---|
| 416 | ],
|
---|
| 417 | onShow : function()
|
---|
| 418 | {
|
---|
| 419 | this.cells = CKEDITOR.plugins.tabletools.getSelectedCells(
|
---|
| 420 | this._.editor.getSelection() );
|
---|
| 421 | this.setupContent( this.cells[ 0 ] );
|
---|
| 422 | },
|
---|
| 423 | onOk : function()
|
---|
| 424 | {
|
---|
| 425 | var cells = this.cells;
|
---|
| 426 | for ( var i = 0 ; i < cells.length ; i++ )
|
---|
| 427 | this.commitContent( cells[ i ] );
|
---|
| 428 | }
|
---|
| 429 | };
|
---|
| 430 | } );
|
---|