jQuery: The Write Less, Do More JavaScript Library

Ticket #2071: css.diff

File css.diff, 1.6 kB (added by brandon, 7 months ago)
  • src/core.js

     
    766766 
    767767    // A method for quickly swapping in/out CSS properties to get correct calculations 
    768768    swap: function( elem, options, callback ) { 
     769        var old = {}; 
    769770        // Remember the old values, and insert the new ones 
    770771        for ( var name in options ) { 
    771             elem.style[ "old" + name ] = elem.style[ name ]; 
     772            old[ name ] = elem.style[ name ]; 
    772773            elem.style[ name ] = options[ name ]; 
    773774        } 
    774775 
     
    776777 
    777778        // Revert the old values 
    778779        for ( var name in options ) 
    779             elem.style[ name ] = elem.style[ "old" + name ]; 
     780            elem.style[ name ] = old[ name ]; 
    780781    }, 
    781782 
    782783    css: function( elem, name, force ) { 
    783784        if ( name == "width" || name == "height" ) { 
    784             var width, height, props = { position: "absolute", visibility: "hidden", display:"block" }; 
     785            var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ]; 
    785786         
    786787            function getWH() { 
    787                 width = elem.clientWidth; 
    788                 height = elem.clientHeight; 
     788                val = name == "width" ? elem.offsetWidth : elem.offsetHeight; 
     789                jQuery.each( which, function() { 
     790                    val = val - parseInt(jQuery.curCSS( elem, "padding" + this, true )) || 0; 
     791                    val = val - parseInt(jQuery.curCSS( elem, "border" + this + "Width", true )) || 0; 
     792                }); 
    789793            } 
    790794         
    791795            if ( jQuery(elem).is(":visible") ) 
    792796                getWH(); 
    793797            else 
    794798                jQuery.swap( elem, props, getWH ); 
    795  
    796             return name == "width" ? width : height; 
     799             
     800            return val; 
    797801        } 
    798802         
    799803        return jQuery.curCSS( elem, name, force );