Ticket #1865: 1865_Koen.patch
File 1865_Koen.patch, 7.1 KB (added by , 15 years ago) |
---|
-
editor/_source/internals/fcktablehandler.js
298 298 299 299 this._MarkCells( cells, '_CellSelected' ) ; 300 300 301 var tableMap = this._CreateTableMap( cells[0] .parentNode.parentNode) ;301 var tableMap = this._CreateTableMap( cells[0] ) ; 302 302 var rowIdx = cells[0].parentNode.rowIndex ; 303 303 var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, cells[0] ) ; 304 304 … … 357 357 // Assume the selected cells are already in a rectangular geometry. 358 358 // Because the checking is already done by FCKTableCommand. 359 359 var refCell = cells[0] ; 360 var tableMap = this._CreateTableMap( refCell .parentNode.parentNode) ;360 var tableMap = this._CreateTableMap( refCell ) ; 361 361 var rowIdx = refCell.parentNode.rowIndex ; 362 362 var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, refCell ) ; 363 363 … … 390 390 391 391 this._ReplaceCellsByMarker( tableMap, '_SelectedCells', refCell ) ; 392 392 this._UnmarkCells( cells, '_SelectedCells' ) ; 393 this._InstallTableMap( tableMap, refCell .parentNode.parentNode) ;393 this._InstallTableMap( tableMap, refCell ) ; 394 394 refCell.appendChild( cellContents ) ; 395 395 396 396 if ( FCKBrowserInfo.IsGeckoLike && ( ! refCell.firstChild ) ) … … 416 416 refCell.appendChild( cellContents ) ; 417 417 this._MarkCells( [nextCell], '_Replace' ) ; 418 418 this._ReplaceCellsByMarker( tableMap, '_Replace', refCell ) ; 419 this._InstallTableMap( tableMap, refCell .parentNode.parentNode) ;419 this._InstallTableMap( tableMap, refCell ) ; 420 420 421 421 this._MoveCaretToCell( refCell, false ) ; 422 422 } … … 438 438 refCell.appendChild( cellContents ) ; 439 439 this._MarkCells( [nextCell], '_Replace' ) ; 440 440 this._ReplaceCellsByMarker( tableMap, '_Replace', refCell ) ; 441 this._InstallTableMap( tableMap, refCell .parentNode.parentNode) ;441 this._InstallTableMap( tableMap, refCell ) ; 442 442 443 443 this._MoveCaretToCell( refCell, false ) ; 444 444 } … … 450 450 return ; 451 451 452 452 var refCell = cells[0] ; 453 var tableMap = this._CreateTableMap( refCell .parentNode.parentNode) ;453 var tableMap = this._CreateTableMap( refCell ) ; 454 454 var rowIdx = refCell.parentNode.rowIndex ; 455 455 var colIdx = FCKTableHandler._GetCellIndexSpan( tableMap, rowIdx, refCell ) ; 456 456 var cellSpan = isNaN( refCell.colSpan ) ? 1 : refCell.colSpan ; … … 504 504 tableMap = newTableMap ; 505 505 } 506 506 507 this._InstallTableMap( tableMap, refCell .parentNode.parentNode) ;507 this._InstallTableMap( tableMap, refCell ) ; 508 508 } 509 509 510 510 FCKTableHandler.VerticalSplitCell = function() … … 514 514 return ; 515 515 516 516 var currentCell = cells[0] ; 517 var tableMap = this._CreateTableMap( currentCell .parentNode.parentNode) ;517 var tableMap = this._CreateTableMap( currentCell ) ; 518 518 var cellIndex = FCKTableHandler._GetCellIndexSpan( tableMap, currentCell.parentNode.rowIndex, currentCell ) ; 519 519 var currentRowSpan = currentCell.rowSpan ; 520 520 var currentRowIndex = currentCell.parentNode.rowIndex ; … … 543 543 newCell.rowSpan = Math.floor( currentRowSpan / 2 ) ; 544 544 if ( FCKBrowserInfo.IsGeckoLike ) 545 545 FCKTools.AppendBogusBr( newCell ) ; 546 currentCell.parentNode.parentNode. rows[newCellRowIndex].insertBefore( newCell, insertMarker ) ;546 currentCell.parentNode.parentNode.parentNode.rows[newCellRowIndex].insertBefore( newCell, insertMarker ) ; 547 547 } 548 548 else 549 549 { 550 550 // 1. Insert a new row. 551 551 var newCellRowIndex = currentRowIndex + 1 ; 552 552 var newRow = FCK.EditorDocument.createElement( 'tr' ) ; 553 currentCell.parentNode.parentNode.insertBefore( newRow, currentCell.parentNode.parentNode.rows[newCellRowIndex] ) ;554 553 554 var theadRows = currentCell.parentNode.parentNode.parentNode.firstChild.rows.length ; 555 556 // Does the table contains a thead? 557 if(currentCell.parentNode.parentNode.parentNode.tHead) { 558 if ( currentCell.parentNode.parentNode.tagName == 'TBODY' && currentCell.parentNode.parentNode.rows.length <= newCellRowIndex - theadRows ) { 559 currentCell.parentNode.parentNode.appendChild(newRow); 560 } 561 else if ( currentCell.parentNode.parentNode.tagName == 'THEAD' && currentCell.parentNode.parentNode.rows.length <= newCellRowIndex ) { 562 currentCell.parentNode.parentNode.appendChild(newRow); 563 } 564 else if(currentCell.parentNode.parentNode.tagName == 'TBODY' ) { 565 currentCell.parentNode.parentNode.insertBefore( newRow, currentCell.parentNode.parentNode.rows[newCellRowIndex - theadRows] ) ; 566 } 567 else { 568 currentCell.parentNode.parentNode.insertBefore( newRow, currentCell.parentNode.parentNode.rows[newCellRowIndex] ) ; 569 } 570 } 571 else { 572 if(currentCell.parentNode.parentNode.rows.length <= newCellRowIndex) { 573 currentCell.parentNode.parentNode.appendChild(newRow); 574 } 575 else { 576 currentCell.parentNode.parentNode.insertBefore( newRow, currentCell.parentNode.parentNode.rows[newCellRowIndex] ) ; 577 } 578 } 579 555 580 // 2. +1 to rowSpan for all cells crossing currentCell's row. 556 581 for ( var i = 0 ; i < tableMap[currentRowIndex].length ; ) 557 582 { … … 629 654 // will produce a bi-dimensional matrix with the following values (representing the cells): 630 655 // Cell1, Cell2, Cell2, Cell 3 631 656 // Cell4, Cell2, Cell2, Cell 5 632 FCKTableHandler._CreateTableMap = function( table)657 FCKTableHandler._CreateTableMap = function( refCell ) 633 658 { 659 var table = refCell.parentNode.parentNode.parentNode ; 634 660 var aRows = table.rows ; 635 661 636 662 // Row and Column counters. … … 675 701 } 676 702 677 703 // This function is the inverse of _CreateTableMap - it takes in a table map and converts it to an HTML table. 678 FCKTableHandler._InstallTableMap = function( tableMap, table)704 FCKTableHandler._InstallTableMap = function( tableMap, refCell ) 679 705 { 706 var table = refCell.parentNode.parentNode.parentNode ; 680 707 // Clear the table of all rows first. 681 708 while ( table.rows.length > 0 ) 682 709 { … … 771 798 if ( cell.rowSpan == 1 ) 772 799 cell.removeAttribute( 'rowspan' ) ; 773 800 } 774 table.appendChild( rowObj ) ; 801 // If the table has a thead and we want to insert the second row or higher, 802 // insert it in tbody 803 if ( table.tHead && i != 0 ) 804 { 805 table.firstChild.nextSibling.appendChild( rowObj ) 806 } 807 // otherwise insert the row in thead (if there is one) or tbody 808 else 809 { 810 table.firstChild.appendChild( rowObj ) ; 811 } 775 812 } 776 813 } 777 814 … … 805 842 return null ; 806 843 807 844 var refCell = cells[0] ; 808 var tableMap = this._CreateTableMap( refCell .parentNode.parentNode) ;845 var tableMap = this._CreateTableMap( refCell ) ; 809 846 var rowIdx = refCell.parentNode.rowIndex ; 810 847 var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, refCell ) ; 811 848 var nextColIdx = colIdx + ( isNaN( refCell.colSpan ) ? 1 : refCell.colSpan ) ; … … 833 870 return null ; 834 871 835 872 var refCell = cells[0] ; 836 var tableMap = this._CreateTableMap( refCell .parentNode.parentNode) ;873 var tableMap = this._CreateTableMap( refCell ) ; 837 874 var rowIdx = refCell.parentNode.rowIndex ; 838 875 var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, refCell ) ; 839 876 var newRowIdx = rowIdx + ( isNaN( refCell.rowSpan ) ? 1 : refCell.rowSpan ) ;