X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Ftable%2Fdialogs%2Ftable.js;h=2ceebdc131b821bdffdd1a1e6c9326a22b6b51d9;hp=b6e7405bded80187e53732f20388c9dbdeab1db4;hb=f0610347140239143439a511ee2bd48cb784f470;hpb=4e70ea24db840898be8cc21c950363a52a2a6aba diff --git a/_source/plugins/table/dialogs/table.js b/_source/plugins/table/dialogs/table.js index b6e7405..2ceebdc 100644 --- a/_source/plugins/table/dialogs/table.js +++ b/_source/plugins/table/dialogs/table.js @@ -5,8 +5,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license (function() { - var widthPattern = /^(\d+(?:\.\d+)?)(px|%)$/, - heightPattern = /^(\d+(?:\.\d+)?)px$/; + var defaultToPixel = CKEDITOR.tools.cssLength; var commitValue = function( data ) { @@ -42,24 +41,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { // 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 = dialog.getContentElement( 'info', 'txtWidth' ); 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 ); }); } @@ -116,11 +105,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }, onOk : function() { - if ( this._.selectedElement ) - { - var selection = editor.getSelection(), - bms = selection.createBookmarks(); - } + var selection = editor.getSelection(), + bms = this._.selectedElement && selection.createBookmarks(); var table = this._.selectedElement || makeElement( 'table' ), me = this, @@ -227,19 +213,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } // Set the width and height. - var styles = []; - if ( info.txtHeight ) - table.setStyle( 'height', CKEDITOR.tools.cssLength( info.txtHeight ) ); - else - table.removeStyle( 'height' ); - - if ( info.txtWidth ) - { - var type = info.cmbWidthType || 'pixels'; - table.setStyle( 'width', info.txtWidth + ( type == 'pixels' ? 'px' : '%' ) ); - } - else - table.removeStyle( 'width' ); + info.txtHeight ? table.setStyle( 'height', info.txtHeight ) : table.removeStyle( 'height' ); + info.txtWidth ? table.setStyle( 'width', info.txtWidth ) : table.removeStyle( 'width' ); if ( !table.getAttribute( 'style' ) ) table.removeAttribute( 'style' ); @@ -247,12 +222,22 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Insert the table element if we're creating one. if ( !this._.selectedElement ) + { editor.insertElement( table ); - // Properly restore the selection inside table. (#4822) + // Override the default cursor position after insertElement to place + // cursor inside the first cell (#7959), IE needs a while. + setTimeout( function() + { + var firstCell = new CKEDITOR.dom.element( table.$.rows[ 0 ].cells[ 0 ] ); + var range = new CKEDITOR.dom.range( editor.document ); + range.moveToPosition( firstCell, CKEDITOR.POSITION_AFTER_START ); + range.select( 1 ); + }, 0 ); + } + // Properly restore the selection, (#4822) but don't break + // because of this, e.g. updated table caption. else - selection.selectBookmarks( bms ); - - return true; + try { selection.selectBookmarks( bms ); } catch( er ){} }, contents : [ { @@ -277,7 +262,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license 'default' : 3, label : editor.lang.table.rows, required : true, - style : 'width:5em', + controlStyle : 'width:5em', validate : function() { var pass = true, @@ -303,7 +288,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license 'default' : 2, label : editor.lang.table.columns, required : true, - style : 'width:5em', + controlStyle : 'width:5em', validate : function() { var pass = true, @@ -369,7 +354,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license id : 'txtBorder', 'default' : 1, label : editor.lang.table.border, - style : 'width:3em', + controlStyle : 'width:3em', validate : CKEDITOR.dialog.validate['number']( editor.lang.table.invalidBorder ), setup : function( selectedTable ) { @@ -422,67 +407,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { type : 'text', id : 'txtWidth', - style : 'width:5em', + controlStyle : 'width:5em', label : editor.lang.common.width, 'default' : 500, - validate : CKEDITOR.dialog.validate['number']( editor.lang.table.invalidWidth ), - - // Extra labelling of width unit type. - onLoad : function() - { - var widthType = this.getDialog().getContentElement( 'info', 'cmbWidthType' ), - labelElement = widthType.getElement(), - inputElement = this.getInputElement(), - ariaLabelledByAttr = inputElement.getAttribute( 'aria-labelledby' ); - - inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) ); - }, - + getValue : defaultToPixel, + validate : CKEDITOR.dialog.validate.cssLength( editor.lang.common.invalidCssLength.replace( '%1', editor.lang.common.width ) ), 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 ); - } + styles && styles.updateStyle( 'width', this.getValue() ); }, - setup : function( selectedTable ) { - var widthMatch = widthPattern.exec( selectedTable.$.style.width ); - if ( widthMatch ) - this.setValue( widthMatch[1] ); - else - this.setValue( '' ); - }, - commit : commitValue - }, - { - id : 'cmbWidthType', - type : 'select', - label : editor.lang.table.widthUnit, - labelStyle: 'visibility:hidden', - 'default' : 'pixels', - items : - [ - [ editor.lang.table.widthPx , 'pixels'], - [ editor.lang.table.widthPc , 'percents'] - ], - setup : function( selectedTable ) - { - var widthMatch = widthPattern.exec( selectedTable.$.style.width ); - if ( widthMatch ) - this.setValue( widthMatch[2] == 'px' ? 'pixels' : 'percents' ); - }, - onChange : function() - { - this.getDialog().getContentElement( 'info', 'txtWidth' ).onChange(); + var val = selectedTable.getStyle( 'width' ); + val && this.setValue( val ); }, commit : commitValue } @@ -496,45 +434,23 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { type : 'text', id : 'txtHeight', - style : 'width:5em', + controlStyle : 'width:5em', label : editor.lang.common.height, 'default' : '', - validate : CKEDITOR.dialog.validate['number']( editor.lang.table.invalidHeight ), - - // Extra labelling of height unit type. - onLoad : function() - { - var heightType = this.getDialog().getContentElement( 'info', 'htmlHeightType' ), - labelElement = heightType.getElement(), - inputElement = this.getInputElement(), - ariaLabelledByAttr = inputElement.getAttribute( 'aria-labelledby' ); - - inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) ); - }, - + getValue : defaultToPixel, + validate : CKEDITOR.dialog.validate.cssLength( editor.lang.common.invalidCssLength.replace( '%1', editor.lang.common.height ) ), onChange : function() { var styles = this.getDialog().getContentElement( 'advanced', 'advStyles' ); - - if ( styles ) - { - var value = this.getValue(); - styles.updateStyle( 'height', value && ( value + 'px' ) ); - } + styles && styles.updateStyle( 'height', this.getValue() ); }, setup : function( selectedTable ) { - var heightMatch = heightPattern.exec( selectedTable.$.style.height ); - if ( heightMatch ) - this.setValue( heightMatch[1] ); + var val = selectedTable.getStyle( 'width' ); + val && this.setValue( val ); }, commit : commitValue - }, - { - id : 'htmlHeightType', - type : 'html', - html : '

' + editor.lang.table.widthPx + '
' } ] }, @@ -545,10 +461,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { type : 'text', id : 'txtCellSpace', - style : 'width:3em', + controlStyle : 'width:3em', label : editor.lang.table.cellSpace, 'default' : 1, - validate : CKEDITOR.dialog.validate['number']( editor.lang.table.invalidCellSpacing ), + validate : CKEDITOR.dialog.validate.number( editor.lang.table.invalidCellSpacing ), setup : function( selectedTable ) { this.setValue( selectedTable.getAttribute( 'cellSpacing' ) || '' ); @@ -564,10 +480,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { type : 'text', id : 'txtCellPad', - style : 'width:3em', + controlStyle : 'width:3em', label : editor.lang.table.cellPad, 'default' : 1, - validate : CKEDITOR.dialog.validate['number']( editor.lang.table.invalidCellPadding ), + validate : CKEDITOR.dialog.validate.number( editor.lang.table.invalidCellPadding ), setup : function( selectedTable ) { this.setValue( selectedTable.getAttribute( 'cellPadding' ) || '' ); @@ -600,16 +516,30 @@ For licensing, see LICENSE.html or http://ckeditor.com/license label : editor.lang.table.caption, setup : function( selectedTable ) { + this.enable(); + var nodeList = selectedTable.getElementsByTag( 'caption' ); if ( nodeList.count() > 0 ) { var caption = nodeList.getItem( 0 ); + var firstElementChild = caption.getFirst( CKEDITOR.dom.walker.nodeType( CKEDITOR.NODE_ELEMENT ) ); + + if ( firstElementChild && !firstElementChild.equals( caption.getBogus() ) ) + { + this.disable(); + this.setValue( caption.getText() ); + return; + } + caption = CKEDITOR.tools.trim( caption.getText() ); this.setValue( caption ); } }, commit : function( data, table ) { + if ( !this.isEnabled() ) + return; + var caption = this.getValue(), captionElement = table.getElementsByTag( 'caption' ); if ( caption )