Ticket #1865: 1865_4.patch

File 1865_4.patch, 5.2 KB (added by Koen Willems, 15 years ago)
  • fcktablehandler.js

     
    382382
    383383        this._ReplaceCellsByMarker( tableMap, '_SelectedCells', refCell ) ;
    384384        this._UnmarkCells( cells, '_SelectedCells' ) ;
    385         this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ;
     385        this._InstallTableMap( tableMap, refCell.parentNode.parentNode.parentNode ) ;
    386386        refCell.appendChild( cellContents ) ;
    387387
    388388        if ( FCKBrowserInfo.IsGeckoLike && ( ! refCell.firstChild ) )
     
    408408        refCell.appendChild( cellContents ) ;
    409409        this._MarkCells( [nextCell], '_Replace' ) ;
    410410        this._ReplaceCellsByMarker( tableMap, '_Replace', refCell ) ;
    411         this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ;
     411        this._InstallTableMap( tableMap, refCell.parentNode.parentNode.parentNode ) ;
    412412
    413413        this._MoveCaretToCell( refCell, false ) ;
    414414}
     
    430430        refCell.appendChild( cellContents ) ;
    431431        this._MarkCells( [nextCell], '_Replace' ) ;
    432432        this._ReplaceCellsByMarker( tableMap, '_Replace', refCell ) ;
    433         this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ;
     433        this._InstallTableMap( tableMap, refCell.parentNode.parentNode.parentNode ) ;
    434434
    435435        this._MoveCaretToCell( refCell, false ) ;
    436436}
     
    496496                tableMap = newTableMap ;
    497497        }
    498498
    499         this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ;
     499        this._InstallTableMap( tableMap, refCell.parentNode.parentNode.parentNode ) ;
    500500}
    501501
    502502FCKTableHandler.VerticalSplitCell = function()
     
    540540                        newCell.colSpan = currentColSpan ;
    541541                if ( FCKBrowserInfo.IsGeckoLike )
    542542                        FCKTools.AppendBogusBr( newCell ) ;
    543                 currentCell.parentNode.parentNode.rows[newCellRowIndex].insertBefore( newCell, insertMarker ) ;
     543                currentCell.parentNode.parentNode.parentNode.rows[newCellRowIndex].insertBefore( newCell, insertMarker ) ;
    544544        }
    545545        else
    546546        {
    547547                // 1. Insert a new row.
    548548                var newCellRowIndex = currentRowIndex + 1 ;
    549549                var newRow = FCK.EditorDocument.createElement( 'tr' ) ;
    550                 var tBody = currentCell.parentNode.parentNode ;
    551                 if ( tBody.rows.length > newCellRowIndex )
    552                         tBody.insertBefore( newRow, tBody.rows[newCellRowIndex] ) ;
     550                var oTable = FCKTools.GetElementAscensor( currentCell, 'TABLE' ) ;
     551
     552                if( oTable.tHead )
     553                {
     554                        var theadRows = oTable.tHead.rows.length ;
     555
     556                        if ( currentCell.parentNode.parentNode.tagName == 'TBODY' && currentCell.parentNode.parentNode.rows.length  <= newCellRowIndex - theadRows )
     557                                currentCell.parentNode.parentNode.appendChild(newRow) ;
     558                        else if ( currentCell.parentNode.parentNode.tagName == 'THEAD' && currentCell.parentNode.parentNode.rows.length  <= newCellRowIndex )
     559                                currentCell.parentNode.parentNode.appendChild(newRow) ;
     560                        else if( currentCell.parentNode.parentNode.tagName == 'TBODY' )
     561                                currentCell.parentNode.parentNode.insertBefore( newRow, currentCell.parentNode.parentNode.rows[newCellRowIndex - theadRows] ) ;
     562                        else
     563                                currentCell.parentNode.parentNode.insertBefore( newRow, currentCell.parentNode.parentNode.rows[newCellRowIndex] ) ;
     564                }
    553565                else
    554                         tBody.appendChild( newRow ) ;
     566                {
     567                        if( currentCell.parentNode.parentNode.rows.length  <= newCellRowIndex)
     568                                currentCell.parentNode.parentNode.appendChild(newRow) ;
     569                        else
     570                                currentCell.parentNode.parentNode.insertBefore( newRow, currentCell.parentNode.parentNode.rows[newCellRowIndex] ) ;
     571                }
    555572
    556573                // 2. +1 to rowSpan for all cells crossing currentCell's row.
    557574                for ( var i = 0 ; i < tableMap[currentRowIndex].length ; )
     
    615632// The difference here is that the "spanned" cells (colSpan and rowSpan) are duplicated on the matrix
    616633// cells that are "spanned". For example, a row with 3 cells where the second cell has colSpan=2 and rowSpan=3
    617634// will produce a bi-dimensional matrix with the following values (representing the cells):
    618 //              Cell1, Cell2, Cell2, Cell2, Cell 3
    619 //              Cell4, Cell2, Cell2, Cell2, Cell 5
     635//              Cell1, Cell2, Cell2, Cell3
     636//              Cell4, Cell2, Cell2, Cell5
     637//              Cell6, Cell2, Cell2, Cell7
    620638FCKTableHandler._CreateTableMap = function( refCell )
    621639{
    622         // It's really a tbody, thead or tfoot. This is only temporary.
    623         var table = (refCell.nodeName == 'TABLE' ? refCell : refCell.parentNode.parentNode ) ;
     640        var table = (refCell.nodeName == 'TABLE' ? refCell : refCell.parentNode.parentNode.parentNode ) ;
    624641
    625642        var aRows = table.rows ;
    626643
     
    673690        // for storing the calculated rowSpan in IE.
    674691        var rowSpanAttr = FCKBrowserInfo.IsIE ? "_fckrowspan" : "rowSpan" ;
    675692
    676         // Clear the table of all rows first.
    677         while ( table.rows.length > 0 )
    678         {
    679                 var row = table.rows[0] ;
    680                 row.parentNode.removeChild( row ) ;
    681         }
    682 
    683693        // Disconnect all the cells in tableMap from their parents, set all colSpan and rowSpan attributes to 1.
    684694        for ( var i = 0 ; i < tableMap.length ; i++ )
    685695        {
     
    764774                        if ( cell.rowSpan == 1 )
    765775                                cell.removeAttribute( 'rowspan' ) ;
    766776                }
    767                 table.appendChild( rowObj ) ;
     777                if ( FCKBrowserInfo.IsIE )
     778                {
     779                        table.rows[i].replaceNode( rowObj ) ;
     780                }
     781                else
     782                {
     783                        table.rows[i].innerHTML = '' ;
     784                        FCKDomTools.MoveChildren( rowObj, table.rows[i] ) ;
     785                }
    768786        }
    769787}
    770788
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy