Greatly reduced the complexity of the width/height methods. This also fixes #2009, #1870, #1796, #1843, #1839, #1818, #1613, #1415 and #1629
This commit is contained in:
parent
540f9304a7
commit
227f8b2514
1 changed files with 14 additions and 47 deletions
55
src/core.js
55
src/core.js
|
@ -772,53 +772,20 @@ jQuery.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
css: function( elem, name, force ) {
|
css: function( elem, name, force ) {
|
||||||
if ( name == "height" || name == "width" ) {
|
if ( name == "width" || name == "height" ) {
|
||||||
var old = {}, height, width;
|
var width, height, props = { position: "absolute", visibility: "hidden", display:"block" };
|
||||||
|
|
||||||
// Revert the padding and border widths to get the
|
function getWH() {
|
||||||
// correct height/width values
|
width = elem.clientWidth;
|
||||||
jQuery.each([ "Top", "Bottom", "Right", "Left" ], function(){
|
height = elem.clientHeight;
|
||||||
old[ "padding" + this ] = 0;
|
}
|
||||||
old[ "border" + this + "Width" ] = 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Swap out the padding/border values temporarily
|
if ( jQuery(elem).is(":visible") )
|
||||||
jQuery.swap( elem, old, function() {
|
getWH();
|
||||||
|
else
|
||||||
|
jQuery.swap( elem, props, getWH );
|
||||||
|
|
||||||
// If the element is visible, then the calculation is easy
|
return name == "width" ? width : height;
|
||||||
if ( jQuery( elem ).is(":visible") ) {
|
|
||||||
height = elem.offsetHeight;
|
|
||||||
width = elem.offsetWidth;
|
|
||||||
|
|
||||||
// Otherwise, we need to flip out more values
|
|
||||||
} else {
|
|
||||||
elem = jQuery( elem.cloneNode(true) )
|
|
||||||
.find(":radio").removeAttr("checked").removeAttr("defaultChecked").end()
|
|
||||||
.css({
|
|
||||||
visibility: "hidden",
|
|
||||||
position: "absolute",
|
|
||||||
display: "block",
|
|
||||||
right: "0",
|
|
||||||
left: "0"
|
|
||||||
}).appendTo( elem.parentNode )[0];
|
|
||||||
|
|
||||||
var position = jQuery.css( elem.parentNode, "position" ) || "static";
|
|
||||||
if ( position == "static" )
|
|
||||||
elem.parentNode.style.position = "relative";
|
|
||||||
|
|
||||||
height = elem.clientHeight;
|
|
||||||
width = elem.clientWidth;
|
|
||||||
|
|
||||||
if ( position == "static" )
|
|
||||||
elem.parentNode.style.position = "static";
|
|
||||||
|
|
||||||
elem.parentNode.removeChild( elem );
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return name == "height" ?
|
|
||||||
height :
|
|
||||||
width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return jQuery.curCSS( elem, name, force );
|
return jQuery.curCSS( elem, name, force );
|
||||||
|
|
Loading…
Add table
Reference in a new issue