Bug Tracker

Changeset 4100

Show
Ignore:
Timestamp:
12/11/07 04:40:54 (9 months ago)
Author:
brandon.aaron
Message:

Greatly reduced the complexity of the width/height methods. This also fixes #2009, #1870, #1796, #1843, #1839, #1818, #1613, #1415 and #1629

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/core.js

    r4094 r4100  
    773773 
    774774    css: function( elem, name, force ) { 
    775         if ( name == "height" || name == "width" ) { 
    776             var old = {}, height, width; 
    777  
    778             // Revert the padding and border widths to get the 
    779             // correct height/width values 
    780             jQuery.each([ "Top", "Bottom", "Right", "Left" ], function(){ 
    781                 old[ "padding" + this ] = 0; 
    782                 old[ "border" + this + "Width" ] = 0; 
    783             }); 
    784  
    785             // Swap out the padding/border values temporarily 
    786             jQuery.swap( elem, old, function() { 
    787  
    788                 // If the element is visible, then the calculation is easy 
    789                 if ( jQuery( elem ).is(":visible") ) { 
    790                     height = elem.offsetHeight; 
    791                     width = elem.offsetWidth; 
    792  
    793                 // Otherwise, we need to flip out more values 
    794                 } else { 
    795                     elem = jQuery( elem.cloneNode(true) ) 
    796                         .find(":radio").removeAttr("checked").removeAttr("defaultChecked").end() 
    797                         .css({ 
    798                             visibility: "hidden", 
    799                             position: "absolute", 
    800                             display: "block", 
    801                             right: "0", 
    802                             left: "0" 
    803                         }).appendTo( elem.parentNode )[0]; 
    804  
    805                     var position = jQuery.css( elem.parentNode, "position" ) || "static"; 
    806                     if ( position == "static" ) 
    807                         elem.parentNode.style.position = "relative"; 
    808  
    809                     height = elem.clientHeight; 
    810                     width = elem.clientWidth; 
    811  
    812                     if ( position == "static" ) 
    813                         elem.parentNode.style.position = "static"; 
    814  
    815                     elem.parentNode.removeChild( elem ); 
    816                 } 
    817             }); 
    818  
    819             return name == "height" ? 
    820                 height : 
    821                 width; 
     775        if ( name == "width" || name == "height" ) { 
     776            var width, height, props = { position: "absolute", visibility: "hidden", display:"block" }; 
     777         
     778            function getWH() { 
     779                width = elem.clientWidth; 
     780                height = elem.clientHeight; 
     781            } 
     782         
     783            if ( jQuery(elem).is(":visible") ) 
     784                getWH(); 
     785            else 
     786                jQuery.swap( elem, props, getWH ); 
     787 
     788            return name == "width" ? width : height; 
    822789        } 
    823  
     790         
    824791        return jQuery.curCSS( elem, name, force ); 
    825792    },