JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4b
[ckeditor.git] / _source / plugins / table / dialogs / table.js
index ddd47f5..55a45e1 100644 (file)
@@ -18,12 +18,62 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
        function tableDialog( editor, command )\r
        {\r
-               var makeElement = function( name ){ return new CKEDITOR.dom.element( name, editor.document ); };\r
+               var makeElement = function( name )\r
+                       {\r
+                               return new CKEDITOR.dom.element( name, editor.document );\r
+                       };\r
+\r
+               var dialogadvtab = editor.plugins.dialogadvtab;\r
 \r
                return {\r
                        title : editor.lang.table.title,\r
                        minWidth : 310,\r
                        minHeight : CKEDITOR.env.ie ? 310 : 280,\r
+\r
+                       onLoad : function()\r
+                       {\r
+                               var dialog = this,\r
+                                       isUpdating;\r
+\r
+                               var styles = dialog.getContentElement( 'advanced', 'advStyles' );\r
+\r
+                               if ( styles )\r
+                               {\r
+                                       styles.on( 'change', function( evt )\r
+                                               {\r
+                                                       if ( isUpdating )\r
+                                                               return;\r
+\r
+                                                       // Flag to avoid recursion.\r
+                                                       isUpdating = 1;\r
+\r
+                                                       // Synchronize width value.\r
+                                                       var width = this.getStyle( 'width', '' ),\r
+                                                               txtWidth = dialog.getContentElement( 'info', 'txtWidth' ),\r
+                                                               cmbWidthType = dialog.getContentElement( 'info', 'cmbWidthType' ),\r
+                                                               isPx = 1;\r
+\r
+                                                       if ( width )\r
+                                                       {\r
+                                                               isPx = ( width.length < 3 || width.substr( width.length - 1 ) != '%' );\r
+                                                               width = parseInt( width, 10 );\r
+                                                       }\r
+\r
+                                                       txtWidth && txtWidth.setValue( width );\r
+                                                       cmbWidthType && cmbWidthType.setValue( isPx ? 'pixels' : 'percents' );\r
+\r
+                                                       // Synchronize height value.\r
+                                                       var height = this.getStyle( 'height', '' ),\r
+                                                               txtHeight = dialog.getContentElement( 'info', 'txtHeight' );\r
+\r
+                                                       height && ( height = parseInt( height, 10 ) );\r
+                                                       txtHeight && txtHeight.setValue( height );\r
+\r
+                                                       isUpdating = 0;\r
+                                               });\r
+                               }\r
+                       },\r
+\r
                        onShow : function()\r
                        {\r
                                // Detect if there's a selected table.\r
@@ -33,7 +83,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                var rowsInput = this.getContentElement( 'info', 'txtRows' ),\r
                                        colsInput = this.getContentElement( 'info', 'txtCols' ),\r
-                                       widthInput = this.getContentElement( 'info', 'txtWidth' );\r
+                                       widthInput = this.getContentElement( 'info', 'txtWidth' ),\r
+                                       heightInput = this.getContentElement( 'info', 'txtHeight' );\r
+\r
                                if ( command == 'tableProperties' )\r
                                {\r
                                        if ( ( selectedTable = editor.getSelection().getSelectedElement() ) )\r
@@ -70,6 +122,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        colsInput && colsInput.enable();\r
                                        rowsInput && rowsInput.select();\r
                                }\r
+\r
+                               // Call the onChange method for the widht and height fields so\r
+                               // they get reflected into the Advanced tab.\r
+                               widthInput && widthInput.onChange();\r
+                               heightInput && heightInput.onChange();\r
                        },\r
                        onOk : function()\r
                        {\r
@@ -380,7 +437,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                                        id : 'txtWidth',\r
                                                                                                        style : 'width:5em',\r
                                                                                                        label : editor.lang.table.width,\r
-                                                                                                       'default' : 200,\r
+                                                                                                       'default' : 500,\r
                                                                                                        validate : CKEDITOR.dialog.validate['number']( editor.lang.table.invalidWidth ),\r
 \r
                                                                                                        // Extra labelling of width unit type.\r
@@ -394,6 +451,21 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                                                inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) );\r
                                                                                                        },\r
 \r
+                                                                                                       onChange : function()\r
+                                                                                                       {\r
+                                                                                                               var styles = this.getDialog().getContentElement( 'advanced', 'advStyles' );\r
+\r
+                                                                                                               if ( styles )\r
+                                                                                                               {\r
+                                                                                                                       var value = this.getValue();\r
+\r
+                                                                                                                       if ( value )\r
+                                                                                                                               value += this.getDialog().getContentElement( 'info', 'cmbWidthType' ).getValue() == 'percents' ? '%' : 'px';\r
+\r
+                                                                                                                       styles.updateStyle( 'width', value );\r
+                                                                                                               }\r
+                                                                                                       },\r
+\r
                                                                                                        setup : function( selectedTable )\r
                                                                                                        {\r
                                                                                                                var widthMatch = widthPattern.exec( selectedTable.$.style.width );\r
@@ -421,6 +493,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                                                if ( widthMatch )\r
                                                                                                                        this.setValue( widthMatch[2] == 'px' ? 'pixels' : 'percents' );\r
                                                                                                        },\r
+                                                                                                       onChange : function()\r
+                                                                                                       {\r
+                                                                                                               this.getDialog().getContentElement( 'info', 'txtWidth' ).onChange();\r
+                                                                                                       },\r
                                                                                                        commit : commitValue\r
                                                                                                }\r
                                                                                        ]\r
@@ -449,6 +525,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                                                inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) );\r
                                                                                                        },\r
 \r
+                                                                                                       onChange : function()\r
+                                                                                                       {\r
+                                                                                                               var styles = this.getDialog().getContentElement( 'advanced', 'advStyles' );\r
+\r
+                                                                                                               if ( styles )\r
+                                                                                                               {\r
+                                                                                                                       var value = this.getValue();\r
+                                                                                                                       styles.updateStyle( 'height', value && ( value + 'px' ) );\r
+                                                                                                               }\r
+                                                                                                       },\r
+\r
                                                                                                        setup : function( selectedTable )\r
                                                                                                        {\r
                                                                                                                var heightMatch = heightPattern.exec( selectedTable.$.style.height );\r
@@ -582,7 +669,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        ]\r
                                                }\r
                                        ]\r
-                               }\r
+                               },\r
+                               dialogadvtab && dialogadvtab.createAdvancedTab( editor )\r
                        ]\r
                };\r
        }\r