JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1.1
[ckeditor.git] / _source / plugins / tabletools / dialogs / tableCell.js
index 7390451..d255034 100644 (file)
@@ -104,19 +104,25 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                        widths : [ '71%', '29%' ],\r
                                                                                                        labelLayout : 'horizontal',\r
                                                                                                        validate : validate[ 'number' ]( langCell.invalidWidth ),\r
-                                                                                                       setup : function( selectedCell )\r
+                                                                                                       setup : function( element )\r
                                                                                                        {\r
-                                                                                                               var widthMatch = widthPattern.exec( selectedCell.$.style.width );\r
-                                                                                                               if ( widthMatch )\r
-                                                                                                                       this.setValue( widthMatch[1] );\r
+                                                                                                               var widthAttr = parseInt( element.getAttribute( 'width' ), 10 ),\r
+                                                                                                                               widthStyle = parseInt( element.getStyle( 'width' ), 10 );\r
+\r
+                                                                                                               !isNaN( widthAttr ) && this.setValue( widthAttr );\r
+                                                                                                               !isNaN( widthStyle ) && this.setValue( widthStyle );\r
                                                                                                        },\r
-                                                                                                       commit : function( selectedCell )\r
+                                                                                                       commit : function( element )\r
                                                                                                        {\r
-                                                                                                               var unit = this.getDialog().getValueOf( 'info', 'widthType' );\r
-                                                                                                               if ( this.getValue() !== '' )\r
-                                                                                                                       selectedCell.$.style.width = this.getValue() + unit;\r
+                                                                                                               var value = parseInt( this.getValue(), 10 ),\r
+                                                                                                                               unit = this.getDialog().getValueOf( 'info', 'widthType' );\r
+\r
+                                                                                                               if ( !isNaN( value ) )\r
+                                                                                                                       element.setStyle( 'width', value + unit );\r
                                                                                                                else\r
-                                                                                                                       selectedCell.$.style.width = '';\r
+                                                                                                                       element.removeStyle( 'width' );\r
+\r
+                                                                                                               element.removeAttribute( 'width' );\r
                                                                                                        },\r
                                                                                                        'default' : ''\r
                                                                                                },\r
@@ -154,18 +160,24 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                        widths : [ '71%', '29%' ],\r
                                                                                                        labelLayout : 'horizontal',\r
                                                                                                        validate : validate[ 'number' ]( langCell.invalidHeight ),\r
-                                                                                                       setup : function( selectedCell )\r
+                                                                                                       setup : function( element )\r
                                                                                                        {\r
-                                                                                                               var heightMatch = heightPattern.exec( selectedCell.$.style.height );\r
-                                                                                                               if ( heightMatch )\r
-                                                                                                                       this.setValue( heightMatch[1] );\r
+                                                                                                               var heightAttr = parseInt( element.getAttribute( 'height' ), 10 ),\r
+                                                                                                                               heightStyle = parseInt( element.getStyle( 'height' ), 10 );\r
+\r
+                                                                                                               !isNaN( heightAttr ) && this.setValue( heightAttr );\r
+                                                                                                               !isNaN( heightStyle ) && this.setValue( heightStyle );\r
                                                                                                        },\r
-                                                                                                       commit : function( selectedCell )\r
+                                                                                                       commit : function( element )\r
                                                                                                        {\r
-                                                                                                               if ( this.getValue() !== '' )\r
-                                                                                                                       selectedCell.$.style.height = this.getValue() + 'px';\r
+                                                                                                               var value = parseInt( this.getValue(), 10 );\r
+\r
+                                                                                                               if ( !isNaN( value ) )\r
+                                                                                                                       element.setStyle( 'height', CKEDITOR.tools.cssLength( value ) );\r
                                                                                                                else\r
-                                                                                                                       selectedCell.$.style.height = '';\r
+                                                                                                                       element.removeStyle( 'height' );\r
+\r
+                                                                                                               element.removeAttribute( 'height' );\r
                                                                                                        }\r
                                                                                                },\r
                                                                                                {\r
@@ -187,12 +199,22 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                [ langCell.yes, 'yes' ],\r
                                                                                                [ langCell.no, 'no' ]\r
                                                                                        ],\r
-                                                                                       commit : function( selectedCell )\r
+                                                                                       setup : function( element )\r
+                                                                                       {\r
+                                                                                               var wordWrapAttr = element.getAttribute( 'noWrap' ),\r
+                                                                                                               wordWrapStyle = element.getStyle( 'white-space' );\r
+\r
+                                                                                               if ( wordWrapStyle == 'nowrap' || wordWrapAttr )\r
+                                                                                                       this.setValue( 'no' );\r
+                                                                                       },\r
+                                                                                       commit : function( element )\r
                                                                                        {\r
                                                                                                if ( this.getValue() == 'no' )\r
-                                                                                                       selectedCell.setAttribute( 'noWrap', 'nowrap' );\r
+                                                                                                       element.setStyle( 'white-space', 'nowrap' );\r
                                                                                                else\r
-                                                                                                       selectedCell.removeAttribute( 'noWrap' );\r
+                                                                                                       element.removeStyle( 'white-space' );\r
+\r
+                                                                                               element.removeAttribute( 'noWrap' );\r
                                                                                        }\r
                                                                                },\r
                                                                                spacer(),\r
@@ -210,16 +232,23 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                [ langTable.alignCenter, 'center' ],\r
                                                                                                [ langTable.alignRight, 'right' ]\r
                                                                                        ],\r
-                                                                                       setup : function( selectedCell )\r
+                                                                                       setup : function( element )\r
                                                                                        {\r
-                                                                                               this.setValue( selectedCell.getAttribute( 'align' ) || '' );\r
+                                                                                               var alignAttr = element.getAttribute( 'align' ),\r
+                                                                                                               textAlignStyle = element.getStyle( 'text-align');\r
+\r
+                                                                                               this.setValue(  textAlignStyle || alignAttr || '' );\r
                                                                                        },\r
                                                                                        commit : function( selectedCell )\r
                                                                                        {\r
-                                                                                               if ( this.getValue() )\r
-                                                                                                       selectedCell.setAttribute( 'align', this.getValue() );\r
+                                                                                               var value = this.getValue();\r
+\r
+                                                                                               if ( value )\r
+                                                                                                       selectedCell.setStyle( 'text-align', value );\r
                                                                                                else\r
-                                                                                                       selectedCell.removeAttribute( 'align' );\r
+                                                                                                       selectedCell.removeStyle( 'text-align' );\r
+\r
+                                                                                               selectedCell.removeAttribute( 'align' );\r
                                                                                        }\r
                                                                                },\r
                                                                                {\r
@@ -237,16 +266,35 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                [ langCell.alignBottom, 'bottom' ],\r
                                                                                                [ langCell.alignBaseline, 'baseline' ]\r
                                                                                        ],\r
-                                                                                       setup : function( selectedCell )\r
+                                                                                       setup : function( element )\r
                                                                                        {\r
-                                                                                               this.setValue( selectedCell.getAttribute( 'vAlign' ) || '' );\r
+                                                                                               var vAlignAttr = element.getAttribute( 'vAlign' ),\r
+                                                                                                               vAlignStyle = element.getStyle( 'vertical-align' );\r
+\r
+                                                                                               switch( vAlignStyle )\r
+                                                                                               {\r
+                                                                                                       // Ignore all other unrelated style values..\r
+                                                                                                       case 'top':\r
+                                                                                                       case 'middle':\r
+                                                                                                       case 'bottom':\r
+                                                                                                       case 'baseline':\r
+                                                                                                               break;\r
+                                                                                                       default:\r
+                                                                                                               vAlignStyle = '';\r
+                                                                                               }\r
+\r
+                                                                                               this.setValue( vAlignStyle || vAlignAttr || '' );\r
                                                                                        },\r
-                                                                                       commit : function( selectedCell )\r
+                                                                                       commit : function( element )\r
                                                                                        {\r
-                                                                                               if ( this.getValue() )\r
-                                                                                                       selectedCell.setAttribute( 'vAlign', this.getValue() );\r
+                                                                                               var value = this.getValue();\r
+\r
+                                                                                               if ( value )\r
+                                                                                                       element.setStyle( 'vertical-align', value );\r
                                                                                                else\r
-                                                                                                       selectedCell.removeAttribute( 'vAlign' );\r
+                                                                                                       element.removeStyle( 'vertical-align' );\r
+\r
+                                                                                               element.removeAttribute( 'vAlign' );\r
                                                                                        }\r
                                                                                }\r
                                                                        ]\r
@@ -289,11 +337,14 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                        validate : validate.integer( langCell.invalidRowSpan ),\r
                                                                                        setup : function( selectedCell )\r
                                                                                        {\r
-                                                                                               this.setValue( selectedCell.getAttribute( 'rowSpan' ) || '' );\r
+                                                                                               var attrVal = parseInt( selectedCell.getAttribute( 'rowSpan' ), 10 );\r
+                                                                                               if ( attrVal && attrVal  != 1 )\r
+                                                                                                       this.setValue(  attrVal );\r
                                                                                        },\r
                                                                                        commit : function( selectedCell )\r
                                                                                        {\r
-                                                                                               if ( this.getValue() )\r
+                                                                                               var value = parseInt( this.getValue(), 10 );\r
+                                                                                               if ( value && value != 1 )\r
                                                                                                        selectedCell.setAttribute( 'rowSpan', this.getValue() );\r
                                                                                                else\r
                                                                                                        selectedCell.removeAttribute( 'rowSpan' );\r
@@ -307,13 +358,16 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                        widths : [ '50%', '50%' ],\r
                                                                                        'default' : '',\r
                                                                                        validate : validate.integer( langCell.invalidColSpan ),\r
-                                                                                       setup : function( selectedCell )\r
+                                                                                       setup : function( element )\r
                                                                                        {\r
-                                                                                               this.setValue( selectedCell.getAttribute( 'colSpan' ) || '' );\r
+                                                                                               var attrVal = parseInt( element.getAttribute( 'colSpan' ), 10 );\r
+                                                                                               if ( attrVal && attrVal  != 1 )\r
+                                                                                                       this.setValue(  attrVal );\r
                                                                                        },\r
                                                                                        commit : function( selectedCell )\r
                                                                                        {\r
-                                                                                               if ( this.getValue() )\r
+                                                                                               var value = parseInt( this.getValue(), 10 );\r
+                                                                                               if ( value && value != 1 )\r
                                                                                                        selectedCell.setAttribute( 'colSpan', this.getValue() );\r
                                                                                                else\r
                                                                                                        selectedCell.removeAttribute( 'colSpan' );\r
@@ -333,16 +387,23 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                        labelLayout : 'horizontal',\r
                                                                                                        widths : [ '70%', '30%' ],\r
                                                                                                        'default' : '',\r
-                                                                                                       setup : function( selectedCell )\r
+                                                                                                       setup : function( element )\r
                                                                                                        {\r
-                                                                                                               this.setValue( selectedCell.getAttribute( 'bgColor' ) || '' );\r
+                                                                                                               var bgColorAttr = element.getAttribute( 'bgColor' ),\r
+                                                                                                                               bgColorStyle = element.getStyle( 'background-color' );\r
+\r
+                                                                                                               this.setValue( bgColorStyle || bgColorAttr );\r
                                                                                                        },\r
                                                                                                        commit : function( selectedCell )\r
                                                                                                        {\r
-                                                                                                               if ( this.getValue() )\r
-                                                                                                                       selectedCell.setAttribute( 'bgColor', this.getValue() );\r
+                                                                                                               var value = this.getValue();\r
+\r
+                                                                                                               if ( value )\r
+                                                                                                                       selectedCell.setStyle( 'background-color', this.getValue() );\r
                                                                                                                else\r
-                                                                                                                       selectedCell.removeAttribute( 'bgColor' );\r
+                                                                                                                       selectedCell.removeStyle( 'background-color' );\r
+\r
+                                                                                                               selectedCell.removeAttribute( 'bgColor');\r
                                                                                                        }\r
                                                                                                },\r
                                                                                                {\r
@@ -377,16 +438,22 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                        labelLayout : 'horizontal',\r
                                                                                                        widths : [ '70%', '30%' ],\r
                                                                                                        'default' : '',\r
-                                                                                                       setup : function( selectedCell )\r
+                                                                                                       setup : function( element )\r
                                                                                                        {\r
-                                                                                                               this.setValue( selectedCell.getStyle( 'border-color' ) || '' );\r
+                                                                                                               var borderColorAttr = element.getAttribute( 'borderColor' ),\r
+                                                                                                                               borderColorStyle = element.getStyle( 'border-color' );\r
+\r
+                                                                                                               this.setValue( borderColorStyle || borderColorAttr );\r
                                                                                                        },\r
                                                                                                        commit : function( selectedCell )\r
                                                                                                        {\r
-                                                                                                               if ( this.getValue() )\r
+                                                                                                               var value = this.getValue();\r
+                                                                                                               if ( value )\r
                                                                                                                        selectedCell.setStyle( 'border-color', this.getValue() );\r
                                                                                                                else\r
                                                                                                                        selectedCell.removeStyle( 'border-color' );\r
+\r
+                                                                                                               selectedCell.removeAttribute( 'borderColor');\r
                                                                                                        }\r
                                                                                                },\r
                                                                                                {\r