Ticket #6568: 6568.patch
File 6568.patch, 4.4 KB (added by , 13 years ago) |
---|
-
_source/plugins/tabletools/plugin.js
140 140 141 141 function insertRow( selection, insertBefore ) 142 142 { 143 // Get the row where the selection is placed in. 144 var row = selection.getStartElement().getAscendant( 'tr' ); 145 if ( !row ) 146 return; 143 var cells = getSelectedCells( selection ), 144 firstCell = cells[ 0 ], 145 table = firstCell.getAscendant( 'table' ), 146 doc = firstCell.getDocument(), 147 startRow = cells[ 0 ].getParent(), 148 startRowIndex = startRow.$.rowIndex, 149 lastCell = cells[ cells.length - 1 ], 150 endRowIndex = lastCell.getParent().$.rowIndex + lastCell.$.rowSpan - 1, 151 endRow = new CKEDITOR.dom.element( table.$.rows[ endRowIndex ] ), 152 rowIndex = insertBefore? startRowIndex : endRowIndex, 153 row = insertBefore? startRow : endRow; 147 154 148 // Create a clone of the row. 149 var newRow = row.clone( 1 ); 155 var map = CKEDITOR.tools.buildTableMap( table ), 156 cloneRow = map[ rowIndex ], 157 nextRow = insertBefore ? map[ rowIndex - 1 ] : map[ rowIndex + 1 ], 158 width = map[0].length; 150 159 160 var newRow = doc.createElement( 'tr' ); 161 for ( var i = 0; i < width; i++ ) 162 { 163 var cell; 164 // Check whether there's a spanning row here, do not break it. 165 if ( cloneRow[ i ].rowSpan > 1 && nextRow && cloneRow[ i ] == nextRow[ i ] ) 166 { 167 cell = cloneRow[ i ]; 168 cell.rowSpan += 1; 169 } 170 else 171 { 172 cell = new CKEDITOR.dom.element( cloneRow[ i ] ).clone(); 173 cell.removeAttribute( 'rowSpan' ); 174 !CKEDITOR.env.ie && cell.appendBogus(); 175 newRow.append( cell ); 176 cell = cell.$; 177 } 178 179 i += cell.colSpan - 1; 180 } 181 151 182 insertBefore ? 152 183 newRow.insertBefore( row ) : 153 184 newRow.insertAfter( row ); 154 155 // Clean the new row.156 clearRow( newRow.$ );157 185 } 158 186 159 187 function deleteRows( selectionOrRow ) … … 214 242 215 243 function insertColumn( selection, insertBefore ) 216 244 { 217 // Get the cell where the selection is placed in. 218 var startElement = selection.getStartElement(); 219 var cell = startElement.getAscendant( 'td', 1 ) || startElement.getAscendant( 'th', 1 ); 245 var cells = getSelectedCells( selection ), 246 firstCell = cells[ 0 ], 247 table = firstCell.getAscendant( 'table' ), 248 lastCell = cells[ cells.length - 1 ], 249 startCol = firstCell.$.cellIndex, 250 lastCol = lastCell.$.cellIndex + lastCell.$.colSpan - 1, 251 colIndex = insertBefore? startCol : lastCol; 220 252 221 if ( !cell )222 return;223 253 224 // Get the cell's table. 225 var table = cell.getAscendant( 'table' ); 226 var cellIndex = cell.$.cellIndex; 254 var map = CKEDITOR.tools.buildTableMap( table ), 255 cloneCol = [], 256 nextCol = [], 257 height = map.length; 227 258 228 // Loop through all rows available in the table. 229 for ( var i = 0 ; i < table.$.rows.length ; i++ ) 259 for ( var i = 0; i < height; i++ ) 230 260 { 231 var $row = table.$.rows[ i ]; 261 cloneCol.push( map[ i ][ colIndex ] ); 262 var nextCell = insertBefore ? map[ i ][ colIndex - 1 ] : map[ i ][ colIndex + 1 ]; 263 nextCell && nextCol.push( nextCell ); 264 } 232 265 233 // If the row doesn't have enough cells, ignore it. 234 if ( $row.cells.length < ( cellIndex + 1 ) ) 235 continue; 236 237 cell = ( new CKEDITOR.dom.element( $row.cells[ cellIndex ] ) ).clone( 0 ); 238 239 if ( !CKEDITOR.env.ie ) 240 cell.appendBogus(); 241 242 // Get back the currently selected cell. 243 var baseCell = new CKEDITOR.dom.element( $row.cells[ cellIndex ] ); 244 if ( insertBefore ) 245 cell.insertBefore( baseCell ); 266 for ( i = 0; i < height; i++ ) 267 { 268 var cell; 269 // Check whether there's a spanning column here, do not break it. 270 if ( cloneCol[ i ].colSpan > 1 271 && nextCol.length 272 && nextCol[ i ] == cloneCol[ i ] ) 273 { 274 cell = cloneCol[ i ]; 275 cell.colSpan += 1; 276 } 246 277 else 247 cell.insertAfter( baseCell ); 248 } 249 } 278 { 279 cell = new CKEDITOR.dom.element( cloneCol[ i ] ).clone(); 280 cell.removeAttribute( 'colSpan' ); 281 !CKEDITOR.env.ie && cell.appendBogus(); 282 cell[ insertBefore? 'insertBefore' : 'insertAfter' ].call( cell, new CKEDITOR.dom.element ( cloneCol[ i ] ) ); 283 cell = cell.$; 284 } 285 286 i += cell.rowSpan - 1; 287 } 288 } 250 289 251 290 function getFocusElementAfterDelCols( cells ) 252 291 {