Changeset 454

Show
Ignore:
Timestamp:
2007-07-16 12:13:34 (18 months ago)
Author:
martinkou
Message:

Added logic for precisely calculating table cell widths across supported browsers.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor/branches/developers/martinkou/editor/plugins/dragresizetable/fckplugin.js

    r441 r454  
    66        "_OldCursor" : null, 
    77        "_MouseMoveMode" : 0,   // 0 - find candidate cells for resizing, 1 - drag to resize 
     8        "_ResizeBar" : null, 
    89        "GetWindowPosition" : function( w, node ) 
    910        { 
     
    102103                        return FCKDragTableHandler._MouseDragHandler( FCK, evt ) ; 
    103104        }, 
     105        // Calculate the padding of a table cell. 
     106        // It returns the value of paddingLeft + paddingRight of a table cell. 
     107        // This function is used, in part, to calculate the width parameter that should be used for setting cell widths. 
     108        // The equation in question is clientWidth = paddingLeft + paddingRight + width. 
     109        // So that width = clientWidth - paddingLeft - paddingRight. 
     110        // The return value of this function must be pixel accurate acorss all supported browsers, so be careful if you need to modify it. 
     111        "_GetCellPadding" : function( table, cell ) 
     112        { 
     113                var attrGuess = parseInt( table.cellPadding ) * 2 ; 
     114                var cssGuess = null ; 
     115                if ( typeof( window.getComputedStyle ) == "function" ) 
     116                { 
     117                        var styleObj = window.getComputedStyle( cell, null ) ; 
     118                        cssGuess = parseInt( styleObj.getPropertyValue( "padding-left" ) ) +  
     119                                parseInt( styleObj.getPropertyValue( "padding-right" ) ) ; 
     120                } 
     121                else 
     122                        cssGuess = parseInt( cell.currentStyle.paddingLeft ) + parseInt (cell.currentStyle.paddingRight ) ; 
     123 
     124                var cssRuntime = cell.style.padding ; 
     125                if ( parseInt( cssRuntime ) == parseInt( cssRuntime ) ) 
     126                        cssGuess = parseInt( cssRuntime ) * 2 ; 
     127                else 
     128                { 
     129                        cssRuntime = cell.style.paddingLeft ; 
     130                        if ( parseInt( cssRuntime ) == parseInt( cssRuntime ) ) 
     131                                cssGuess = parseInt( cssRuntime ) ; 
     132                        cssRuntime = cell.style.paddingRight ; 
     133                        if ( parseInt( cssRuntime ) == parseInt( cssRuntime ) ) 
     134                                cssGuess += parseInt( cssRuntime ) ; 
     135                } 
     136 
     137                attrGuess = parseInt( attrGuess ) ; 
     138                cssGuess = parseInt( cssGuess ) ; 
     139                if ( attrGuess != attrGuess ) 
     140                        attrGuess = 0 ; 
     141                if ( cssGuess != cssGuess ) 
     142                        cssGuess = 0 ; 
     143                return Math.max( attrGuess, cssGuess ) ; 
     144        }, 
     145        // Calculate the real width of the table cell. 
     146        // The real width of the table cell is the pixel width that you can set to the width attribute of the table cell and after 
     147        // that, the table cell should be of exactly the same width as before. 
     148        // The real width of a table cell can be calculated as: 
     149        // width = clientWidth - paddingLeft - paddingRight. 
     150        "_GetCellWidth" : function( table, cell ) 
     151        { 
     152                var clientWidth = parseInt( cell.clientWidth ) ; 
     153                if ( clientWidth != clientWidth )               // NaN possible? lets just be safe... 
     154                        clientWidth = 0 ; 
     155                return clientWidth - FCKDragTableHandler._GetCellPadding( table, cell ) ; 
     156        }, 
    104157        "_MouseFindHandler" : function( FCK, evt ) 
    105158        { 
     
    147200        "_MouseDragHandler" : function( FCK, evt ) 
    148201        { 
     202        }, 
     203        "_CreateResizeBar" : function( w, table, evt ) 
     204        { 
    149205        } 
    150206};