Ticket #4784: 4784_2.patch

File 4784_2.patch, 2.4 KB (added by brooks, 14 years ago)
  • _source/plugins/tabletools/plugin.js

     
    8585
    8686                return retval;
    8787        }
     88       
     89        function getBesideFocusableCell( cell, cellsToDelete ) {
     90                var focusedCell;
    8891
     92                return (
     93                                        ( focusedCell = cell.getPrevious() ) &&
     94                                        indexOf( cellsToDelete, focusedCell ) == -1  &&
     95                                        focusedCell
     96                                )
     97                                ||
     98                                (
     99                                        ( focusedCell = cell.getNext() )  &&
     100                                        indexOf( cellsToDelete, focusedCell ) == -1  &&
     101                                        focusedCell
     102                                );
     103               
     104                function indexOf( cells, cell ) {
     105                        for ( var i = 0, len = cells.length ; i < len ; i++ )
     106                        {       
     107                                if ( cells[i].$ == cell.$)
     108                                        return i;
     109                        }
     110
     111                        return -1;
     112                }
     113        }
     114
     115        function getToFocusedCell( cellsToDelete ) {
     116                var i = 0,
     117                        last = cellsToDelete.length - 1,
     118                        cell,parentTr,tr;
     119       
     120                // 1.first we check left or right side focusable cell row by row;
     121                while ( cell = cellsToDelete[ i++ ] )
     122                {
     123                        cell = getBesideFocusableCell( cell, cellsToDelete );
     124                        if ( cell )
     125                                return cell;
     126                }
     127               
     128                // 2. then we check the toppest  row focusable cell
     129                parentTr =  cellsToDelete[ 0 ].getParent();
     130                if ( tr = parentTr.getPrevious() )
     131                        return tr.getLast();
     132               
     133                // 3. last we check the lowerest  row focusable cell
     134                parentTr = cellsToDelete[ last ].getParent();
     135                if ( tr = parentTr.getNext() )
     136                        return tr.getChild( 0 );
     137
     138                return null;
     139        }
     140
    89141        function clearRow( $tr )
    90142        {
    91143                // Get the array of row's cells.
     
    277329                if ( selectionOrCell instanceof CKEDITOR.dom.selection )
    278330                {
    279331                        var cellsToDelete = getSelectedCells( selectionOrCell );
     332                        var table = cellsToDelete[ 0 ] && cellsToDelete[ 0 ].getAscendant( 'table' );
     333                        var cellToFocus   = getToFocusedCell( cellsToDelete );
     334
    280335                        for ( var i = cellsToDelete.length - 1 ; i >= 0 ; i-- )
    281336                                deleteCells( cellsToDelete[ i ] );
     337                       
     338                        if ( cellToFocus )
     339                                placeCursorInCell( cellToFocus, true );
     340                        else if ( table )
     341                                table.remove();
    282342                }
    283343                else if ( selectionOrCell instanceof CKEDITOR.dom.element )
    284344                {
    285                         if ( selectionOrCell.getParent().getChildCount() == 1 )
    286                                 selectionOrCell.getParent().remove();
     345                        var tr = selectionOrCell.getParent();
     346                        if ( tr.getChildCount() == 1 )
     347                                tr.remove();
    287348                        else
    288349                                selectionOrCell.remove();
    289350                }
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy