X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Ftable%2Fdialogs%2Ftable.js;h=7cb2708b85ddac79667bfde6da8b3f35141621ee;hb=039a051ccf3901311661022a30afd60fc38130c9;hp=ddd47f5f4256b25049a1c304fc86b9d9d6fb8317;hpb=055b6b0792ce7dc53d47af606b367c04b927c2ab;p=ckeditor.git diff --git a/_source/plugins/table/dialogs/table.js b/_source/plugins/table/dialogs/table.js index ddd47f5..7cb2708 100644 --- a/_source/plugins/table/dialogs/table.js +++ b/_source/plugins/table/dialogs/table.js @@ -18,12 +18,53 @@ For licensing, see LICENSE.html or http://ckeditor.com/license function tableDialog( editor, command ) { - var makeElement = function( name ){ return new CKEDITOR.dom.element( name, editor.document ); }; + var makeElement = function( name ) + { + return new CKEDITOR.dom.element( name, editor.document ); + }; + + var dialogadvtab = editor.plugins.dialogadvtab; return { title : editor.lang.table.title, minWidth : 310, minHeight : CKEDITOR.env.ie ? 310 : 280, + + onLoad : function() + { + var dialog = this; + + var styles = dialog.getContentElement( 'advanced', 'advStyles' ); + + if ( styles ) + { + styles.on( 'change', function( evt ) + { + // Synchronize width value. + var width = this.getStyle( 'width', '' ), + txtWidth = dialog.getContentElement( 'info', 'txtWidth' ), + cmbWidthType = dialog.getContentElement( 'info', 'cmbWidthType' ), + isPx = 1; + + if ( width ) + { + isPx = ( width.length < 3 || width.substr( width.length - 1 ) != '%' ); + width = parseInt( width, 10 ); + } + + txtWidth && txtWidth.setValue( width, true ); + cmbWidthType && cmbWidthType.setValue( isPx ? 'pixels' : 'percents', true ); + + // Synchronize height value. + var height = this.getStyle( 'height', '' ), + txtHeight = dialog.getContentElement( 'info', 'txtHeight' ); + + height && ( height = parseInt( height, 10 ) ); + txtHeight && txtHeight.setValue( height, true ); + }); + } + }, + onShow : function() { // Detect if there's a selected table. @@ -33,14 +74,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var rowsInput = this.getContentElement( 'info', 'txtRows' ), colsInput = this.getContentElement( 'info', 'txtCols' ), - widthInput = this.getContentElement( 'info', 'txtWidth' ); + widthInput = this.getContentElement( 'info', 'txtWidth' ), + heightInput = this.getContentElement( 'info', 'txtHeight' ); + if ( command == 'tableProperties' ) { - if ( ( selectedTable = editor.getSelection().getSelectedElement() ) ) - { - if ( selectedTable.getName() != 'table' ) - selectedTable = null; - } + if ( ( selectedTable = selection.getSelectedElement() ) ) + selectedTable = selectedTable.getAscendant( 'table', true ); else if ( ranges.length > 0 ) { // Webkit could report the following range on cell selection (#4948): @@ -56,27 +96,30 @@ For licensing, see LICENSE.html or http://ckeditor.com/license this._.selectedElement = selectedTable; } - // Enable, disable and select the row, cols, width fields. + // Enable or disable the row, cols, width fields. if ( selectedTable ) { this.setupContent( selectedTable ); rowsInput && rowsInput.disable(); colsInput && colsInput.disable(); - widthInput && widthInput.select(); } else { rowsInput && rowsInput.enable(); colsInput && colsInput.enable(); - rowsInput && rowsInput.select(); } + + // Call the onChange method for the widht and height fields so + // they get reflected into the Advanced tab. + widthInput && widthInput.onChange(); + heightInput && heightInput.onChange(); }, onOk : function() { if ( this._.selectedElement ) { var selection = editor.getSelection(), - bms = editor.getSelection().createBookmarks(); + bms = selection.createBookmarks(); } var table = this._.selectedElement || makeElement( 'table' ), @@ -123,7 +166,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license for ( i = 0 ; i < theRow.getChildCount() ; i++ ) { var th = theRow.getChild( i ); - if ( th.type == CKEDITOR.NODE_ELEMENT ) + // Skip bookmark nodes. (#6155) + if ( th.type == CKEDITOR.NODE_ELEMENT && !th.hasAttribute( '_cke_bookmark' ) ) { th.renameNode( 'th' ); th.setAttribute( 'scope', 'col' ); @@ -380,7 +424,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license id : 'txtWidth', style : 'width:5em', label : editor.lang.table.width, - 'default' : 200, + 'default' : 500, validate : CKEDITOR.dialog.validate['number']( editor.lang.table.invalidWidth ), // Extra labelling of width unit type. @@ -394,6 +438,21 @@ For licensing, see LICENSE.html or http://ckeditor.com/license inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) ); }, + onChange : function() + { + var styles = this.getDialog().getContentElement( 'advanced', 'advStyles' ); + + if ( styles ) + { + var value = this.getValue(); + + if ( value ) + value += this.getDialog().getContentElement( 'info', 'cmbWidthType' ).getValue() == 'percents' ? '%' : 'px'; + + styles.updateStyle( 'width', value ); + } + }, + setup : function( selectedTable ) { var widthMatch = widthPattern.exec( selectedTable.$.style.width ); @@ -421,6 +480,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( widthMatch ) this.setValue( widthMatch[2] == 'px' ? 'pixels' : 'percents' ); }, + onChange : function() + { + this.getDialog().getContentElement( 'info', 'txtWidth' ).onChange(); + }, commit : commitValue } ] @@ -449,6 +512,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) ); }, + onChange : function() + { + var styles = this.getDialog().getContentElement( 'advanced', 'advStyles' ); + + if ( styles ) + { + var value = this.getValue(); + styles.updateStyle( 'height', value && ( value + 'px' ) ); + } + }, + setup : function( selectedTable ) { var heightMatch = heightPattern.exec( selectedTable.$.style.height ); @@ -530,8 +604,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( nodeList.count() > 0 ) { var caption = nodeList.getItem( 0 ); - caption = ( caption.getChild( 0 ) && caption.getChild( 0 ).getText() ) || ''; - caption = CKEDITOR.tools.trim( caption ); + caption = CKEDITOR.tools.trim( caption.getText() ); this.setValue( caption ); } }, @@ -582,7 +655,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license ] } ] - } + }, + dialogadvtab && dialogadvtab.createAdvancedTab( editor ) ] }; }