Make sure that .width()/.height() don't return NaN also standardize on returning instead of auto for default values (which is what we do elsewhere in .css() as well). Fixes #7225.
This commit is contained in:
parent
7e02cee5ff
commit
53396b879b
|
@ -169,15 +169,11 @@ jQuery.each(["height", "width"], function( i, name ) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( val < 0 ) {
|
if ( val <= 0 ) {
|
||||||
return elem.style[ name ] || "0px";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( val === 0 ) {
|
|
||||||
val = curCSS( elem, name, name );
|
val = curCSS( elem, name, name );
|
||||||
|
|
||||||
if ( val != null ) {
|
if ( val != null ) {
|
||||||
return val;
|
return val === "auto" ? "" : val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,27 +33,29 @@ jQuery.each([ "Height", "Width" ], function( i, name ) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return jQuery.isWindow( elem ) ?
|
if ( jQuery.isWindow( elem ) ) {
|
||||||
// Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
|
// Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
|
||||||
elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] ||
|
return elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] ||
|
||||||
elem.document.body[ "client" + name ] :
|
elem.document.body[ "client" + name ];
|
||||||
|
|
||||||
// Get document width or height
|
// Get document width or height
|
||||||
(elem.nodeType === 9) ? // is it a document
|
} else if ( elem.nodeType === 9 ) {
|
||||||
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
|
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
|
||||||
Math.max(
|
return Math.max(
|
||||||
elem.documentElement["client" + name],
|
elem.documentElement["client" + name],
|
||||||
elem.body["scroll" + name], elem.documentElement["scroll" + name],
|
elem.body["scroll" + name], elem.documentElement["scroll" + name],
|
||||||
elem.body["offset" + name], elem.documentElement["offset" + name]
|
elem.body["offset" + name], elem.documentElement["offset" + name]
|
||||||
) :
|
);
|
||||||
|
|
||||||
// Get or set width or height on the element
|
// Get or set width or height on the element
|
||||||
size === undefined ?
|
} else if ( size === undefined ) {
|
||||||
// Get width or height on the element
|
var orig = jQuery.css( elem, type ), ret = parseFloat( orig );
|
||||||
parseFloat( jQuery.css( elem, type ) ) :
|
return jQuery.isNaN( ret ) ? orig : ret;
|
||||||
|
|
||||||
// Set the width or height on the element (default to pixels if value is unitless)
|
// Set the width or height on the element (default to pixels if value is unitless)
|
||||||
this.css( type, typeof size === "string" ? size : size + "px" );
|
} else {
|
||||||
|
return this.css( type, typeof size === "string" ? size : size + "px" );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,8 +13,8 @@ test("css(String|Hash)", function() {
|
||||||
|
|
||||||
var div = jQuery( "<div>" );
|
var div = jQuery( "<div>" );
|
||||||
|
|
||||||
equals( div.css("width") || "auto", "auto", "Width on disconnected node." );
|
equals( div.css("width"), "", "Width on disconnected node." );
|
||||||
equals( div.css("height") || "auto", "auto", "Height on disconnected node." );
|
equals( div.css("height"), "", "Height on disconnected node." );
|
||||||
|
|
||||||
div.css({ width: 4, height: 4 });
|
div.css({ width: 4, height: 4 });
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue