Ticket #1865: 1865_Koen.patch

File 1865_Koen.patch, 7.1 KB (added by Koen Willems, 16 years ago)

patch for ticket #1865

  • editor/_source/internals/fcktablehandler.js

     
    298298
    299299        this._MarkCells( cells, '_CellSelected' ) ;
    300300
    301         var tableMap = this._CreateTableMap( cells[0].parentNode.parentNode ) ;
     301        var tableMap = this._CreateTableMap( cells[0] ) ;
    302302        var rowIdx = cells[0].parentNode.rowIndex ;
    303303        var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, cells[0] ) ;
    304304
     
    357357        // Assume the selected cells are already in a rectangular geometry.
    358358        // Because the checking is already done by FCKTableCommand.
    359359        var refCell = cells[0] ;
    360         var tableMap = this._CreateTableMap( refCell.parentNode.parentNode ) ;
     360        var tableMap = this._CreateTableMap( refCell ) ;
    361361        var rowIdx = refCell.parentNode.rowIndex ;
    362362        var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, refCell ) ;
    363363
     
    390390
    391391        this._ReplaceCellsByMarker( tableMap, '_SelectedCells', refCell ) ;
    392392        this._UnmarkCells( cells, '_SelectedCells' ) ;
    393         this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ;
     393        this._InstallTableMap( tableMap, refCell ) ;
    394394        refCell.appendChild( cellContents ) ;
    395395
    396396        if ( FCKBrowserInfo.IsGeckoLike && ( ! refCell.firstChild ) )
     
    416416        refCell.appendChild( cellContents ) ;
    417417        this._MarkCells( [nextCell], '_Replace' ) ;
    418418        this._ReplaceCellsByMarker( tableMap, '_Replace', refCell ) ;
    419         this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ;
     419        this._InstallTableMap( tableMap, refCell ) ;
    420420
    421421        this._MoveCaretToCell( refCell, false ) ;
    422422}
     
    438438        refCell.appendChild( cellContents ) ;
    439439        this._MarkCells( [nextCell], '_Replace' ) ;
    440440        this._ReplaceCellsByMarker( tableMap, '_Replace', refCell ) ;
    441         this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ;
     441        this._InstallTableMap( tableMap, refCell ) ;
    442442
    443443        this._MoveCaretToCell( refCell, false ) ;
    444444}
     
    450450                return ;
    451451
    452452        var refCell = cells[0] ;
    453         var tableMap = this._CreateTableMap( refCell.parentNode.parentNode ) ;
     453        var tableMap = this._CreateTableMap( refCell ) ;
    454454        var rowIdx = refCell.parentNode.rowIndex ;
    455455        var colIdx = FCKTableHandler._GetCellIndexSpan( tableMap, rowIdx, refCell ) ;
    456456        var cellSpan = isNaN( refCell.colSpan ) ? 1 : refCell.colSpan ;
     
    504504                tableMap = newTableMap ;
    505505        }
    506506
    507         this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ;
     507        this._InstallTableMap( tableMap, refCell ) ;
    508508}
    509509
    510510FCKTableHandler.VerticalSplitCell = function()
     
    514514                return ;
    515515
    516516        var currentCell = cells[0] ;
    517         var tableMap = this._CreateTableMap( currentCell.parentNode.parentNode ) ;
     517        var tableMap = this._CreateTableMap( currentCell ) ;
    518518        var cellIndex = FCKTableHandler._GetCellIndexSpan( tableMap, currentCell.parentNode.rowIndex, currentCell ) ;
    519519        var currentRowSpan = currentCell.rowSpan ;
    520520        var currentRowIndex = currentCell.parentNode.rowIndex ;
     
    543543                newCell.rowSpan = Math.floor( currentRowSpan / 2 ) ;
    544544                if ( FCKBrowserInfo.IsGeckoLike )
    545545                        FCKTools.AppendBogusBr( newCell ) ;
    546                 currentCell.parentNode.parentNode.rows[newCellRowIndex].insertBefore( newCell, insertMarker ) ;
     546                currentCell.parentNode.parentNode.parentNode.rows[newCellRowIndex].insertBefore( newCell, insertMarker ) ;
    547547        }
    548548        else
    549549        {
    550550                // 1. Insert a new row.
    551551                var newCellRowIndex = currentRowIndex + 1 ;
    552552                var newRow = FCK.EditorDocument.createElement( 'tr' ) ;
    553                 currentCell.parentNode.parentNode.insertBefore( newRow, currentCell.parentNode.parentNode.rows[newCellRowIndex] ) ;
    554553
     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
    555580                // 2. +1 to rowSpan for all cells crossing currentCell's row.
    556581                for ( var i = 0 ; i < tableMap[currentRowIndex].length ; )
    557582                {
     
    629654// will produce a bi-dimensional matrix with the following values (representing the cells):
    630655//              Cell1, Cell2, Cell2, Cell 3
    631656//              Cell4, Cell2, Cell2, Cell 5
    632 FCKTableHandler._CreateTableMap = function( table )
     657FCKTableHandler._CreateTableMap = function( refCell )
    633658{
     659        var table = refCell.parentNode.parentNode.parentNode ;
    634660        var aRows = table.rows ;
    635661
    636662        // Row and Column counters.
     
    675701}
    676702
    677703// 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 )
     704FCKTableHandler._InstallTableMap = function( tableMap, refCell )
    679705{
     706        var table = refCell.parentNode.parentNode.parentNode ;
    680707        // Clear the table of all rows first.
    681708        while ( table.rows.length > 0 )
    682709        {
     
    771798                        if ( cell.rowSpan == 1 )
    772799                                cell.removeAttribute( 'rowspan' ) ;
    773800                }
    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                }
    775812        }
    776813}
    777814
     
    805842                return null ;
    806843
    807844        var refCell = cells[0] ;
    808         var tableMap = this._CreateTableMap( refCell.parentNode.parentNode ) ;
     845        var tableMap = this._CreateTableMap( refCell ) ;
    809846        var rowIdx = refCell.parentNode.rowIndex ;
    810847        var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, refCell ) ;
    811848        var nextColIdx = colIdx + ( isNaN( refCell.colSpan ) ? 1 : refCell.colSpan ) ;
     
    833870                return null ;
    834871
    835872        var refCell = cells[0] ;
    836         var tableMap = this._CreateTableMap( refCell.parentNode.parentNode ) ;
     873        var tableMap = this._CreateTableMap( refCell ) ;
    837874        var rowIdx = refCell.parentNode.rowIndex ;
    838875        var colIdx = this._GetCellIndexSpan( tableMap, rowIdx, refCell ) ;
    839876        var newRowIdx = rowIdx + ( isNaN( refCell.rowSpan ) ? 1 : refCell.rowSpan ) ;
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy