Ticket #2329: dragresizetable_use_relative.patch

File dragresizetable_use_relative.patch, 2.1 KB (added by Davey Shafik, 16 years ago)

Use Relative Widths for Columns (patch)

  • editor/plugins/dragresizetable/fckplugin.js

    old new  
    1 var FCKDragTableHandler =
     1var FCKDragTableHandler =
    22{
    33        "_DragState" : 0,
    44        "_LeftCell" : null,
     
    139139                // Then, build an array of current column width values.
    140140                // This algorithm can be very slow if the cells have insane colSpan values. (e.g. colSpan=1000).
    141141                var table = FCKTools.GetElementAscensor( FCKDragTableHandler._LeftCell, "table" ) ;
     142                // Gets the value from the Width or the Style attribute
     143                var tableWidth  = (table.style.width  ? table.style.width  : table.width ) ;
     144               
     145                if (tableWidth.indexOf('%') >= 0)                       // Percentual = %
     146                {
     147                        var relativeWidth = true;
     148                }
     149                else
     150                {
     151                        var relativeWidth = false;
     152                        tableWidth = tableWidth = tableWidth.substr(0,tableWidth.length - 2) ;
     153                }
     154
    142155                var colArray = [] ;
    143156                var tableMap = FCKDragTableHandler._TableMap ;
    144157                for ( var i = 0 ; i < tableMap.length ; i++ )
     
    187200                for ( var i = colElements.length - 1 ; i >= 0 ; i-- )
    188201                        colElements[i].parentNode.removeChild( colElements[i] ) ;
    189202
     203                if ( relativeWidth )
     204                {
     205                        tableWidth = 0;
     206                        for (var i = 0 ; i < colArray.length ; i++ )
     207                        {
     208                                tableWidth += colArray[i].width ;
     209                        }
     210                }
     211
    190212                // Set new cell widths.
    191213                var processedCells = [] ;
    192214                for ( var i = 0 ; i < tableMap.length ; i++ )
     
    197219                                if ( cell._Processed )
    198220                                        continue ;
    199221                                if ( tableMap[i][j-1] != cell )
    200                                         cell.width = colArray[j].width ;
     222                                        var colWidth = colArray[j].width ;
    201223                                else
    202                                         cell.width = parseInt( cell.width, 10 ) + parseInt( colArray[j].width, 10 ) ;
     224                                        var colWidth = parseInt( cell.width, 10 ) + parseInt( colArray[j].width, 10 ) ;
     225                                if ( relativeWidth )
     226                                {
     227                                        var percentWidth = (colWidth / tableWidth) * 100;
     228                                        cell.width = percentWidth + "%";
     229                                }
     230                                else
     231                                {
     232                                        cell.width = colWidth;
     233                                }
    203234                                if ( tableMap[i][j+1] != cell )
    204235                                {
    205236                                        processedCells.push( cell ) ;
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy