JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.3.2
[ckeditor.git] / _source / plugins / tabletools / dialogs / tableCell.js
index d255034..7518ab1 100644 (file)
@@ -5,18 +5,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
 CKEDITOR.dialog.add( 'cellProperties', function( editor )\r
        {\r
-               var langTable = editor.lang.table;\r
-               var langCell = langTable.cell;\r
-               var langCommon = editor.lang.common;\r
-               var validate = CKEDITOR.dialog.validate;\r
-               var widthPattern = /^(\d+(?:\.\d+)?)(px|%)$/,\r
-                       heightPattern = /^(\d+(?:\.\d+)?)px$/;\r
-               var bind = CKEDITOR.tools.bind;\r
-\r
-               function spacer()\r
-               {\r
-                       return { type : 'html', html : ' ' };\r
-               }\r
+               var langTable = editor.lang.table,\r
+                       langCell = langTable.cell,\r
+                       langCommon = editor.lang.common,\r
+                       validate = CKEDITOR.dialog.validate,\r
+                       widthPattern = /^(\d+(?:\.\d+)?)(px|%)$/,\r
+                       heightPattern = /^(\d+(?:\.\d+)?)px$/,\r
+                       bind = CKEDITOR.tools.bind,\r
+                       spacer = { type : 'html', html : ' ' };\r
 \r
                /**\r
                 *\r
@@ -34,16 +30,16 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                        {\r
                                releaseHandlers( this );\r
                        };\r
-                       var bindToDialog = function( dialog )\r
-                       {\r
-                               dialog.on( 'ok', onOk );\r
-                               dialog.on( 'cancel', onCancel );\r
-                       };\r
                        var releaseHandlers = function( dialog )\r
                        {\r
                                dialog.removeListener( 'ok', onOk );\r
                                dialog.removeListener( 'cancel', onCancel );\r
                        };\r
+                       var bindToDialog = function( dialog )\r
+                       {\r
+                               dialog.on( 'ok', onOk );\r
+                               dialog.on( 'cancel', onCancel );\r
+                       };\r
                        editor.execCommand( dialogName );\r
                        if ( editor._.storedDialogs.colordialog )\r
                                bindToDialog( editor._.storedDialogs.colordialog );\r
@@ -104,6 +100,18 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                        widths : [ '71%', '29%' ],\r
                                                                                                        labelLayout : 'horizontal',\r
                                                                                                        validate : validate[ 'number' ]( langCell.invalidWidth ),\r
+\r
+                                                                                                       // Extra labelling of width unit type.\r
+                                                                                                       onLoad : function()\r
+                                                                                                       {\r
+                                                                                                               var widthType = this.getDialog().getContentElement( 'info', 'widthType' ),\r
+                                                                                                                       labelElement = widthType.getElement(),\r
+                                                                                                                       inputElement = this.getInputElement(),\r
+                                                                                                                       ariaLabelledByAttr = inputElement.getAttribute( 'aria-labelledby' );\r
+\r
+                                                                                                               inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) );\r
+                                                                                                       },\r
+\r
                                                                                                        setup : function( element )\r
                                                                                                        {\r
                                                                                                                var widthAttr = parseInt( element.getAttribute( 'width' ), 10 ),\r
@@ -131,7 +139,8 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                        id : 'widthType',\r
                                                                                                        labelLayout : 'horizontal',\r
                                                                                                        widths : [ '0%', '100%' ],\r
-                                                                                                       label : '',\r
+                                                                                                       label : editor.lang.table.widthUnit,\r
+                                                                                                       labelStyle: 'display:none',\r
                                                                                                        'default' : 'px',\r
                                                                                                        items :\r
                                                                                                        [\r
@@ -140,7 +149,7 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                        ],\r
                                                                                                        setup : function( selectedCell )\r
                                                                                                        {\r
-                                                                                                               var widthMatch = widthPattern.exec( selectedCell.$.style.width );\r
+                                                                                                               var widthMatch = widthPattern.exec( selectedCell.getStyle( 'width' ) || selectedCell.getAttribute( 'width' ) );\r
                                                                                                                if ( widthMatch )\r
                                                                                                                        this.setValue( widthMatch[2] );\r
                                                                                                        }\r
@@ -160,6 +169,18 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                        widths : [ '71%', '29%' ],\r
                                                                                                        labelLayout : 'horizontal',\r
                                                                                                        validate : validate[ 'number' ]( langCell.invalidHeight ),\r
+\r
+                                                                                                       // Extra labelling of height unit type.\r
+                                                                                                       onLoad : function()\r
+                                                                                                       {\r
+                                                                                                               var heightType = this.getDialog().getContentElement( 'info', 'htmlHeightType' ),\r
+                                                                                                                       labelElement = heightType.getElement(),\r
+                                                                                                                       inputElement = this.getInputElement(),\r
+                                                                                                                       ariaLabelledByAttr = inputElement.getAttribute( 'aria-labelledby' );\r
+\r
+                                                                                                               inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) );\r
+                                                                                                       },\r
+\r
                                                                                                        setup : function( element )\r
                                                                                                        {\r
                                                                                                                var heightAttr = parseInt( element.getAttribute( 'height' ), 10 ),\r
@@ -181,12 +202,13 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                        }\r
                                                                                                },\r
                                                                                                {\r
+                                                                                                       id : 'htmlHeightType',\r
                                                                                                        type : 'html',\r
                                                                                                        html : langTable.widthPx\r
                                                                                                }\r
                                                                                        ]\r
                                                                                },\r
-                                                                               spacer(),\r
+                                                                               spacer,\r
                                                                                {\r
                                                                                        type : 'select',\r
                                                                                        id : 'wordWrap',\r
@@ -217,7 +239,7 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                element.removeAttribute( 'noWrap' );\r
                                                                                        }\r
                                                                                },\r
-                                                                               spacer(),\r
+                                                                               spacer,\r
                                                                                {\r
                                                                                        type : 'select',\r
                                                                                        id : 'hAlign',\r
@@ -299,7 +321,7 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                }\r
                                                                        ]\r
                                                                },\r
-                                                               spacer(),\r
+                                                               spacer,\r
                                                                {\r
                                                                        type : 'vbox',\r
                                                                        padding : 0,\r
@@ -326,7 +348,7 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                selectedCell.renameNode( this.getValue() );\r
                                                                                        }\r
                                                                                },\r
-                                                                               spacer(),\r
+                                                                               spacer,\r
                                                                                {\r
                                                                                        type : 'text',\r
                                                                                        id : 'rowSpan',\r
@@ -373,7 +395,7 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                        selectedCell.removeAttribute( 'colSpan' );\r
                                                                                        }\r
                                                                                },\r
-                                                                               spacer(),\r
+                                                                               spacer,\r
                                                                                {\r
                                                                                        type : 'hbox',\r
                                                                                        padding : 0,\r
@@ -424,7 +446,7 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                                                                                                }\r
                                                                                        ]\r
                                                                                },\r
-                                                                               spacer(),\r
+                                                                               spacer,\r
                                                                                {\r
                                                                                        type : 'hbox',\r
                                                                                        padding : 0,\r
@@ -489,9 +511,14 @@ CKEDITOR.dialog.add( 'cellProperties', function( editor )
                        },\r
                        onOk : function()\r
                        {\r
+                               var selection = this._.editor.getSelection(),\r
+                                       bookmarks = selection.createBookmarks();\r
+\r
                                var cells = this.cells;\r
                                for ( var i = 0 ; i < cells.length ; i++ )\r
                                        this.commitContent( cells[ i ] );\r
+\r
+                               selection.selectBookmarks( bookmarks );\r
                        }\r
                };\r
        } );\r