| 358 | | var aCells = FCKTableHandler.GetSelectedCells() ; |
| 359 | | |
| 360 | | // TODO: Reimplement MergeCells() with this._InstallTableMap(). |
| 361 | | |
| | 354 | var cells = this.GetSelectedCells() ; |
| | 355 | if ( cells.length < 2 ) |
| | 356 | return ; |
| | 357 | |
| | 358 | // Assume the selected cells are already in a rectangular geometry. |
| | 359 | // Because the checking is already done by FCKTableCommand. |
| | 360 | var refCell = cells[0] ; |
| | 361 | var tableMap = this._CreateTableMap( refCell.parentNode.parentNode ) ; |
| | 362 | var rowIdx = refCell.parentNode.rowIndex ; |
| | 363 | var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, refCell ) ; |
| | 364 | |
| | 365 | this._MarkCells( cells, '_SelectedCells' ) ; |
| | 366 | var selectionGeometry = this._GetMarkerGeometry( tableMap, rowIdx, colIdx, '_SelectedCells' ) ; |
| | 367 | |
| | 368 | var baseColIdx = colIdx - selectionGeometry.x ; |
| | 369 | var baseRowIdx = rowIdx - selectionGeometry.y ; |
| | 370 | var cellContents = refCell.ownerDocument.createDocumentFragment() ; |
| | 371 | for ( var i = 0 ; i < selectionGeometry.height ; i++ ) |
| | 372 | { |
| | 373 | var rowChildNodesCount = 0 ; |
| | 374 | for ( var j = 0 ; j < selectionGeometry.width ; j++ ) |
| | 375 | { |
| | 376 | var currentCell = tableMap[baseRowIdx + i][baseColIdx + j] ; |
| | 377 | while ( currentCell.childNodes.length > 0 ) |
| | 378 | { |
| | 379 | var node = currentCell.removeChild( currentCell.firstChild ) ; |
| | 380 | if ( node.nodeType != 1 |
| | 381 | || ( node.getAttribute( 'type', 2 ) != '_moz' && node.getAttribute( '_moz_dirty' ) != null ) ) |
| | 382 | { |
| | 383 | cellContents.appendChild( node ) ; |
| | 384 | rowChildNodesCount++ ; |
| | 385 | } |
| | 386 | } |
| | 387 | } |
| | 388 | if ( rowChildNodesCount > 0 ) |
| | 389 | cellContents.appendChild( refCell.ownerDocument.createElement( 'br' ) ) ; |
| | 390 | } |
| | 391 | |
| | 392 | this._ReplaceCellsByMarker( tableMap, '_SelectedCells', refCell ) ; |
| | 393 | this._UnmarkCells( cells, '_SelectedCells' ) ; |
| | 394 | this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ; |
| | 395 | refCell.appendChild( cellContents ) ; |
| | 396 | |
| | 397 | if ( FCKBrowserInfo.IsGecko && ( ! refCell.firstChild ) ) |
| | 398 | FCKTools.AppendBogusBr( refCell ) ; |
| | 399 | |
| | 400 | this._MoveCaretToCell( refCell, false ) ; |
| 417 | | var aMap = this._CreateTableMap( aCells[0].parentNode.parentNode ) ; |
| 418 | | var iCellIndex = FCKTableHandler._GetCellIndexSpan( aMap, aCells[0].parentNode.rowIndex , aCells[0] ) ; |
| 419 | | |
| 420 | | var aCollCells = this._GetColumnCells( aMap, iCellIndex ) ; |
| 421 | | |
| 422 | | for ( var i = 0 ; i < aCollCells.length ; i++ ) |
| 423 | | { |
| 424 | | if ( aCollCells[i] == aCells[0] ) |
| 425 | | { |
| 426 | | var oNewCell = this.InsertCell( aCells[0], false ) ; |
| 427 | | if ( !isNaN( aCells[0].rowSpan ) && aCells[0].rowSpan > 1 ) |
| 428 | | oNewCell.rowSpan = aCells[0].rowSpan ; |
| 429 | | } |
| 430 | | else |
| 431 | | { |
| 432 | | if ( isNaN( aCollCells[i].colSpan ) ) |
| 433 | | aCollCells[i].colSpan = 2 ; |
| | 453 | var refCell = cells[0] ; |
| | 454 | var tableMap = this._CreateTableMap( refCell.parentNode.parentNode ) ; |
| | 455 | var rowIdx = refCell.parentNode.rowIndex ; |
| | 456 | var colIdx = FCKTableHandler._GetCellIndexSpan( tableMap, rowIdx, refCell ) ; |
| | 457 | var cellSpan = isNaN( refCell.colSpan ) ? 1 : refCell.colSpan ; |
| | 458 | |
| | 459 | if ( cellSpan > 1 ) |
| | 460 | { |
| | 461 | // Splittng a multi-column cell - original cell gets ceil(colSpan/2) columns, |
| | 462 | // new cell gets floor(colSpan/2). |
| | 463 | var newCellSpan = Math.ceil( cellSpan / 2 ) ; |
| | 464 | var newCell = refCell.ownerDocument.createElement( 'td' ) ; |
| | 465 | if ( FCKBrowserInfo.IsGecko ) |
| | 466 | FCKTools.AppendBogusBr( newCell ) ; |
| | 467 | var startIdx = colIdx + newCellSpan ; |
| | 468 | var endIdx = colIdx + cellSpan ; |
| | 469 | var rowSpan = isNaN( refCell.rowSpan ) ? 1 : refCell.rowSpan ; |
| | 470 | for ( var r = rowIdx ; r < rowIdx + rowSpan ; r++ ) |
| | 471 | for ( var i = startIdx ; i < endIdx ; i++ ) |
| | 472 | tableMap[r][i] = newCell ; |
| | 473 | } |
| | 474 | else |
| | 475 | { |
| | 476 | // Splitting a single-column cell - add a new cell, and expand |
| | 477 | // cells crossing the same column. |
| | 478 | var newTableMap = [] ; |
| | 479 | for ( var i = 0 ; i < tableMap.length ; i++ ) |
| | 480 | { |
| | 481 | var newRow = tableMap[i].slice( 0, colIdx ) ; |
| | 482 | if ( tableMap[i].length <= colIdx ) |
| | 483 | { |
| | 484 | newTableMap.push( newRow ) ; |
| | 485 | continue ; |
| | 486 | } |
| | 487 | if ( tableMap[i][colIdx] == refCell ) |
| | 488 | { |
| | 489 | newRow.push( refCell ) ; |
| | 490 | newRow.push( refCell.ownerDocument.createElement( 'td' ) ) ; |
| | 491 | if ( FCKBrowserInfo.IsGecko ) |
| | 492 | FCKTools.AppendBogusBr( newRow[newRow.length - 1] ) ; |
| | 493 | } |