+ function deleteColumns( selectionOrCell )\r
+ {\r
+ var cells = getSelectedCells( selectionOrCell ),\r
+ firstCell = cells[ 0 ],\r
+ lastCell = cells[ cells.length - 1 ],\r
+ table = firstCell.getAscendant( 'table' ),\r
+ map = CKEDITOR.tools.buildTableMap( table ),\r
+ startColIndex,\r
+ endColIndex,\r
+ rowsToDelete = [];\r
+\r
+ // Figure out selected cells' column indices.\r
+ for ( var i = 0, rows = map.length; i < rows; i++ )\r
+ {\r
+ for ( var j = 0, cols = map[ i ].length; j < cols; j++ )\r
+ {\r
+ if ( map[ i ][ j ] == firstCell.$ )\r
+ startColIndex = j;\r
+ if ( map[ i ][ j ] == lastCell.$ )\r
+ endColIndex = j;\r
+ }\r
+ }\r
+\r
+ // Delete cell or reduce cell spans by checking through the table map.\r
+ for ( i = startColIndex; i <= endColIndex; i++ )\r
+ {\r
+ for ( j = 0; j < map.length; j++ )\r
+ {\r
+ var mapRow = map[ j ],\r
+ row = new CKEDITOR.dom.element( table.$.rows[ j ] ),\r
+ cell = new CKEDITOR.dom.element( mapRow[ i ] );\r
+\r
+ if ( cell.$.colSpan == 1 )\r
+ cell.remove();\r
+ // Reduce the col spans.\r
+ else\r
+ cell.$.colSpan -= 1;\r
+\r
+ j += cell.$.rowSpan - 1;\r
+\r
+ if ( !row.$.cells.length )\r
+ rowsToDelete.push( row );\r
+ }\r
+ }\r
+\r
+ var firstRowCells = table.$.rows[ 0 ] && table.$.rows[ 0 ].cells;\r
+\r
+ // Where to put the cursor after columns been deleted?\r
+ // 1. Into next cell of the first row if any;\r
+ // 2. Into previous cell of the first row if any;\r
+ // 3. Into table's parent element;\r
+ var cursorPosition = new CKEDITOR.dom.element( firstRowCells[ startColIndex ] || ( startColIndex ? firstRowCells[ startColIndex - 1 ] : table.$.parentNode ) );\r
+\r
+ // Delete table rows only if all columns are gone (do not remove empty row).\r
+ if ( rowsToDelete.length == rows )\r
+ table.remove();\r
+\r
+ return cursorPosition;\r
+ }\r
+\r