Ticket #1865: 1865_1.patch
File 1865_1.patch, 8.7 KB (added by , 15 years ago) |
---|
-
editor/_source/internals/fcktablehandler.js
299 299 this._MarkCells( cells, '_CellSelected' ) ; 300 300 301 301 var tableMap = this._CreateTableMap( cells[0] ) ; 302 var rowIdx = cells[0].parentNode.rowIndex ;302 var rowIdx = this._GetCellLocation( tableMap, cells[0] )[0] ; 303 303 var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, cells[0] ) ; 304 304 305 305 var geometry = this._GetMarkerGeometry( tableMap, rowIdx, colIdx, '_CellSelected' ) ; … … 358 358 // Because the checking is already done by FCKTableCommand. 359 359 var refCell = cells[0] ; 360 360 var tableMap = this._CreateTableMap( refCell ) ; 361 var rowIdx = refCell.parentNode.rowIndex;361 var rowIdx = this._GetCellLocation( tableMap, refCell )[0] ; 362 362 var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, refCell ) ; 363 363 364 364 this._MarkCells( cells, '_SelectedCells' ) ; … … 450 450 return ; 451 451 452 452 var refCell = cells[0] ; 453 var tableMap = this._CreateTableMap( refCell ) ; 453 454 var tableMap = this._CreateTableMap( refCell.offsetParent ) ; 455 var colIdx = FCKTableHandler._GetCellLocation( tableMap, refCell )[1] ; 456 457 var refTable = refCell.offsetParent ; 454 458 var rowIdx = refCell.parentNode.rowIndex ; 455 var colIdx = FCKTableHandler._GetCellIndexSpan( tableMap, rowIdx, refCell ) ; 459 var currentRow = refTable.rows[rowIdx] ; 460 var actualColIdx = refCell.cellIndex ; 461 456 462 var cellSpan = isNaN( refCell.colSpan ) ? 1 : refCell.colSpan ; 463 var cellRowSpan = isNaN( refCell.rowSpan ) ? 1 : refCell.rowSpan ; 457 464 458 if ( cellSpan > 1 ) 465 // Given the [x,y] position of the current cell in the tableMap find the respective 466 // 'y' position (actualColIdx) of the current cell in the refTable DOM object. 467 for ( var j = 0 ; j < currentRow.cells.length ; j++ ) 459 468 { 460 // Splitting a multi-column cell - original cell gets ceil(colSpan/2) columns, 461 // new cell gets floor(colSpan/2). 462 var newCellSpan = Math.ceil( cellSpan / 2 ) ; 463 var newCell = FCK.EditorDocument.createElement( refCell.nodeName ) ; 464 if ( FCKBrowserInfo.IsGeckoLike ) 465 FCKTools.AppendBogusBr( newCell ) ; 466 var startIdx = colIdx + newCellSpan ; 467 var endIdx = colIdx + cellSpan ; 468 var rowSpan = isNaN( refCell.rowSpan ) ? 1 : refCell.rowSpan ; 469 for ( var r = rowIdx ; r < rowIdx + rowSpan ; r++ ) 469 if ( tableMap[rowIdx][colIdx] == currentRow.cells[j] ) 470 470 { 471 for ( var i = startIdx ; i < endIdx ; i++ )472 tableMap[r][i] = newCell;471 var newCellColIndex = j + 1 ; 472 break ; 473 473 } 474 474 } 475 476 // Insert a new cell 477 if ( newCellColIndex > currentRow.cells.length - 1 ) 478 var newCell = currentRow.appendChild( FCK.EditorDocument.createElement( refCell.nodeName ) ) ; 475 479 else 480 var newCell = currentRow.insertBefore( FCK.EditorDocument.createElement( refCell.nodeName ), currentRow.cells[newCellColIndex] ) 481 if ( FCKBrowserInfo.IsGeckoLike ) 482 FCKTools.AppendBogusBr( newCell ) ; 483 if ( cellRowSpan > 1 ) 484 newCell.rowSpan = cellRowSpan ; 485 486 if ( cellSpan > 1 ) 476 487 { 477 // Splitting a single-column cell - add a new cell, and expand 478 // cells crossing the same column. 479 var newTableMap = [] ; 480 for ( var i = 0 ; i < tableMap.length ; i++ ) 488 // Splitting a multi-column cell - original cell gets floor(colSpan/2) columns, 489 // new cell gets ceil(colSpan/2) 490 //currentRow.cells[actualColIdx].colSpan = Math.floor( cellSpan / 2 ) ; 491 refCell.colSpan = Math.floor( cellSpan / 2 ) ; 492 newCell.colSpan = Math.ceil( cellSpan / 2 ) ; 493 } 494 else 495 { 496 // Splitting a single-column cell - expand cells crossing the same column. 497 for ( var i = 0 ; i < tableMap.length ; ) 481 498 { 482 var newRow = tableMap[i].slice( 0, colIdx ) ; 483 if ( tableMap[i].length <= colIdx ) 484 { 485 newTableMap.push( newRow ) ; 486 continue ; 487 } 488 if ( tableMap[i][colIdx] == refCell ) 489 { 490 newRow.push( refCell ) ; 491 newRow.push( FCK.EditorDocument.createElement( refCell.nodeName ) ) ; 492 if ( FCKBrowserInfo.IsGeckoLike ) 493 FCKTools.AppendBogusBr( newRow[newRow.length - 1] ) ; 494 } 495 else 496 { 497 newRow.push( tableMap[i][colIdx] ) ; 498 newRow.push( tableMap[i][colIdx] ) ; 499 } 500 for ( var j = colIdx + 1 ; j < tableMap[i].length ; j++ ) 501 newRow.push( tableMap[i][j] ) ; 502 newTableMap.push( newRow ) ; 503 } 504 tableMap = newTableMap ; 499 if ( i != rowIdx ) 500 tableMap[i][colIdx].colSpan += 1 ; 501 i += tableMap[i][colIdx].rowSpan ; 502 } 505 503 } 506 507 this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ;508 504 } 509 505 510 506 FCKTableHandler.VerticalSplitCell = function() … … 514 510 return ; 515 511 516 512 var currentCell = cells[0] ; 517 var tableMap = this._CreateTableMap( currentCell ) ; 513 var tempTableMap = this._CreateTableMap( currentCell ) ; 514 var tempRowIndex = FCKTableHandler._GetCellLocation( tempTableMap, currentCell )[0] ; 515 516 var tableMap = this._CreateTableMap( currentCell.offsetParent ) ; 518 517 var currentRowIndex = currentCell.parentNode.rowIndex ; 519 518 var cellIndex = FCKTableHandler._GetCellIndexSpan( tableMap, currentRowIndex, currentCell ) ; 520 var currentRowSpan = currentCell.rowSpan ;521 if ( isNaN( currentRowSpan ) )522 currentRowSpan = 1 ;523 519 520 var currentColSpan = isNaN( currentCell.colSpan ) ? 1 : currentCell.colSpan ; 521 var currentRowSpan = isNaN( currentCell.rowSpan ) ? 1 : currentCell.rowSpan ; 522 524 523 if ( currentRowSpan > 1 ) 525 524 { 526 525 // 1. Set the current cell's rowSpan to 1. … … 528 527 529 528 // 2. Find the appropriate place to insert a new cell at the next row. 530 529 var newCellRowIndex = currentRowIndex + Math.ceil( currentRowSpan / 2 ) ; 531 var oRow = tableMap[newCellRowIndex] ; 530 var tempCellRowIndex = tempRowIndex + Math.ceil( currentRowSpan / 2 ) ; 531 var oRow = tempTableMap[tempCellRowIndex] ; 532 532 var insertMarker = null ; 533 533 for ( var i = cellIndex+1 ; i < oRow.length ; i++ ) 534 534 { … … 544 544 newCell.rowSpan = Math.floor( currentRowSpan / 2 ) ; 545 545 if ( FCKBrowserInfo.IsGeckoLike ) 546 546 FCKTools.AppendBogusBr( newCell ) ; 547 currentCell.parentNode.parentNode.rows[newCellRowIndex].insertBefore( newCell, insertMarker ) ; 547 if ( currentColSpan > 1 ) 548 newCell.colSpan = currentColSpan ; 549 currentCell.parentNode.parentNode.rows[tempCellRowIndex].insertBefore( newCell, insertMarker ) ; 548 550 } 549 551 else 550 552 { 551 553 // 1. Insert a new row. 552 var newCellRowIndex = currentRowIndex + 1 ; 554 //var newCellRowIndex = currentRowIndex + 1 ; 555 var newCellRowIndex = tempRowIndex + 1 ; 553 556 var newRow = FCK.EditorDocument.createElement( 'tr' ) ; 554 557 var tBody = currentCell.parentNode.parentNode ; 555 558 if ( tBody.rows.length > newCellRowIndex ) … … 557 560 else 558 561 tBody.appendChild( newRow ) ; 559 562 563 // 3. Insert a new cell to new row. 564 var newCell = FCK.EditorDocument.createElement( currentCell.nodeName ) ; 565 if ( FCKBrowserInfo.IsGeckoLike ) 566 FCKTools.AppendBogusBr( newCell ) ; 567 if ( currentColSpan > 1 ) 568 newCell.colSpan = currentColSpan ; 569 newRow.appendChild( newCell ) ; 570 560 571 // 2. +1 to rowSpan for all cells crossing currentCell's row. 561 572 for ( var i = 0 ; i < tableMap[currentRowIndex].length ; ) 562 573 { … … 574 585 tableMap[currentRowIndex][i].rowSpan = rowSpan + 1 ; 575 586 i += colSpan ; 576 587 } 577 578 // 3. Insert a new cell to new row.579 var newCell = FCK.EditorDocument.createElement( currentCell.nodeName ) ;580 if ( FCKBrowserInfo.IsGeckoLike )581 FCKTools.AppendBogusBr( newCell ) ;582 newRow.appendChild( newCell ) ;583 588 } 584 589 } 585 590 … … 587 592 FCKTableHandler._GetCellIndexSpan = function( tableMap, rowIndex, cell ) 588 593 { 589 594 if ( tableMap.length < rowIndex + 1 ) 590 return null ; 595 null ; 596 597 var oRow = tableMap[rowIndex] ; 591 598 592 var oRow = tableMap[ rowIndex ] ;593 594 599 for ( var c = 0 ; c < oRow.length ; c++ ) 595 600 { 596 601 if ( oRow[c] == cell ) … … 824 829 825 830 var refCell = cells[0] ; 826 831 var tableMap = this._CreateTableMap( refCell ) ; 827 var rowIdx = refCell.parentNode.rowIndex;832 var rowIdx = this._GetCellLocation( tableMap, refCell )[0] ; 828 833 var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, refCell ) ; 834 829 835 var nextColIdx = colIdx + ( isNaN( refCell.colSpan ) ? 1 : refCell.colSpan ) ; 830 836 var nextCell = tableMap[rowIdx][nextColIdx] ; 831 837 … … 852 858 853 859 var refCell = cells[0] ; 854 860 var tableMap = this._CreateTableMap( refCell ) ; 855 var rowIdx = refCell.parentNode.rowIndex;861 var rowIdx = this._GetCellLocation( tableMap, refCell )[0] ; 856 862 var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, refCell ) ; 863 857 864 var newRowIdx = rowIdx + ( isNaN( refCell.rowSpan ) ? 1 : refCell.rowSpan ) ; 858 865 if ( ! tableMap[newRowIdx] ) 859 866 return null ;