Ticket #1865: 1865_1.patch

File 1865_1.patch, 8.7 KB (added by shri, 16 years ago)
  • editor/_source/internals/fcktablehandler.js

     
    299299        this._MarkCells( cells, '_CellSelected' ) ;
    300300
    301301        var tableMap = this._CreateTableMap( cells[0] ) ;
    302         var rowIdx = cells[0].parentNode.rowIndex ;
     302        var rowIdx = this._GetCellLocation( tableMap, cells[0] )[0] ;                   
    303303        var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, cells[0] ) ;
    304304
    305305        var geometry = this._GetMarkerGeometry( tableMap, rowIdx, colIdx, '_CellSelected' ) ;
     
    358358        // Because the checking is already done by FCKTableCommand.
    359359        var refCell = cells[0] ;
    360360        var tableMap = this._CreateTableMap( refCell ) ;
    361         var rowIdx = refCell.parentNode.rowIndex ;
     361        var rowIdx = this._GetCellLocation( tableMap, refCell )[0] ;
    362362        var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, refCell ) ;
    363363
    364364        this._MarkCells( cells, '_SelectedCells' ) ;
     
    450450                return ;
    451451
    452452        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 ;
    454458        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
    456462        var cellSpan = isNaN( refCell.colSpan ) ? 1 : refCell.colSpan ;
     463        var cellRowSpan = isNaN( refCell.rowSpan ) ? 1 : refCell.rowSpan ;
    457464
    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++ )
    459468        {
    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] )
    470470                {
    471                         for ( var i = startIdx ; i < endIdx ; i++ )
    472                                 tableMap[r][i] = newCell ;
     471                        var newCellColIndex = j + 1 ;
     472                        break ;
    473473                }
    474474        }
     475
     476        // Insert a new cell
     477        if ( newCellColIndex > currentRow.cells.length - 1 )
     478                var newCell = currentRow.appendChild( FCK.EditorDocument.createElement( refCell.nodeName ) ) ;
    475479        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 )
    476487        {
    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 ;  )
    481498                {
    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                }               
    505503        }
    506 
    507         this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ;
    508504}
    509505
    510506FCKTableHandler.VerticalSplitCell = function()
     
    514510                return ;
    515511
    516512        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 ) ;
    518517        var currentRowIndex = currentCell.parentNode.rowIndex ;
    519518        var cellIndex = FCKTableHandler._GetCellIndexSpan( tableMap, currentRowIndex, currentCell ) ;
    520         var currentRowSpan = currentCell.rowSpan ;
    521         if ( isNaN( currentRowSpan ) )
    522                 currentRowSpan = 1 ;
    523519
     520        var currentColSpan = isNaN( currentCell.colSpan ) ? 1 : currentCell.colSpan ;
     521        var currentRowSpan = isNaN( currentCell.rowSpan ) ? 1 : currentCell.rowSpan ;   
     522
    524523        if ( currentRowSpan > 1 )
    525524        {
    526525                // 1. Set the current cell's rowSpan to 1.
     
    528527
    529528                // 2. Find the appropriate place to insert a new cell at the next row.
    530529                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] ;
    532532                var insertMarker = null ;
    533533                for ( var i = cellIndex+1 ; i < oRow.length ; i++ )
    534534                {
     
    544544                newCell.rowSpan = Math.floor( currentRowSpan / 2 ) ;
    545545                if ( FCKBrowserInfo.IsGeckoLike )
    546546                        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 ) ;
    548550        }
    549551        else
    550552        {
    551553                // 1. Insert a new row.
    552                 var newCellRowIndex = currentRowIndex + 1 ;
     554                //var newCellRowIndex = currentRowIndex + 1 ;
     555                var newCellRowIndex = tempRowIndex + 1 ;
    553556                var newRow = FCK.EditorDocument.createElement( 'tr' ) ;
    554557                var tBody = currentCell.parentNode.parentNode ;
    555558                if ( tBody.rows.length > newCellRowIndex )
     
    557560                else
    558561                        tBody.appendChild( newRow ) ;
    559562
     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
    560571                // 2. +1 to rowSpan for all cells crossing currentCell's row.
    561572                for ( var i = 0 ; i < tableMap[currentRowIndex].length ; )
    562573                {
     
    574585                        tableMap[currentRowIndex][i].rowSpan = rowSpan + 1 ;
    575586                        i += colSpan ;
    576587                }
    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 ) ;
    583588        }
    584589}
    585590
     
    587592FCKTableHandler._GetCellIndexSpan = function( tableMap, rowIndex, cell )
    588593{
    589594        if ( tableMap.length < rowIndex + 1 )
    590                 return null ;
     595                null ;
     596               
     597        var oRow = tableMap[rowIndex] ;
    591598
    592         var oRow = tableMap[ rowIndex ] ;
    593 
    594599        for ( var c = 0 ; c < oRow.length ; c++ )
    595600        {
    596601                if ( oRow[c] == cell )
     
    824829
    825830        var refCell = cells[0] ;
    826831        var tableMap = this._CreateTableMap( refCell ) ;
    827         var rowIdx = refCell.parentNode.rowIndex ;
     832        var rowIdx = this._GetCellLocation( tableMap, refCell )[0] ;
    828833        var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, refCell ) ;
     834
    829835        var nextColIdx = colIdx + ( isNaN( refCell.colSpan ) ? 1 : refCell.colSpan ) ;
    830836        var nextCell = tableMap[rowIdx][nextColIdx] ;
    831837
     
    852858
    853859        var refCell = cells[0] ;
    854860        var tableMap = this._CreateTableMap( refCell ) ;
    855         var rowIdx = refCell.parentNode.rowIndex ;
     861        var rowIdx = this._GetCellLocation( tableMap, refCell )[0] ;
    856862        var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, refCell ) ;
     863
    857864        var newRowIdx = rowIdx + ( isNaN( refCell.rowSpan ) ? 1 : refCell.rowSpan ) ;
    858865        if ( ! tableMap[newRowIdx] )
    859866                return null ;
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy