parent
0742056645
commit
80ad14bd14
2 changed files with 71 additions and 22 deletions
69
src/css.js
69
src/css.js
|
@ -168,12 +168,11 @@ jQuery.curCSS = jQuery.css;
|
||||||
jQuery.each(["height", "width"], function( i, name ) {
|
jQuery.each(["height", "width"], function( i, name ) {
|
||||||
jQuery.cssHooks[ name ] = {
|
jQuery.cssHooks[ name ] = {
|
||||||
get: function( elem, computed, extra ) {
|
get: function( elem, computed, extra ) {
|
||||||
var val;
|
var val, fellback = false;
|
||||||
|
|
||||||
if ( computed ) {
|
if ( computed ) {
|
||||||
if ( elem.offsetWidth !== 0 ) {
|
if ( elem.offsetWidth !== 0 ) {
|
||||||
val = getWH( elem, name, extra );
|
val = getWH( elem, name, extra );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
jQuery.swap( elem, cssShow, function() {
|
jQuery.swap( elem, cssShow, function() {
|
||||||
val = getWH( elem, name, extra );
|
val = getWH( elem, name, extra );
|
||||||
|
@ -188,20 +187,37 @@ jQuery.each(["height", "width"], function( i, name ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( val != null ) {
|
if ( val != null ) {
|
||||||
// Should return "auto" instead of 0, use 0 for
|
fellback = true;
|
||||||
// temporary backwards-compat
|
|
||||||
return val === "" || val === "auto" ? "0px" : val;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( val < 0 || val == null ) {
|
if ( !fellback && ( val < 0 || val == null ) ) {
|
||||||
val = elem.style[ name ];
|
val = elem.style[ name ];
|
||||||
// Should return "auto" instead of 0, use 0 for
|
fellback = true;
|
||||||
// temporary backwards-compat
|
|
||||||
return val === "" || val === "auto" ? "0px" : val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeof val === "string" ? val : val + "px";
|
// Should return "auto" instead of 0, use 0 for
|
||||||
|
// temporary backwards-compat
|
||||||
|
if ( fellback && ( val === "" || val === "auto" ) ) {
|
||||||
|
val = "0px";
|
||||||
|
} else if ( typeof val !== "string" ) {
|
||||||
|
val += "px";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( extra ) {
|
||||||
|
val = parseFloat( val ) || 0;
|
||||||
|
if ( fellback ) {
|
||||||
|
val += adjustWH( elem, name, "padding" );
|
||||||
|
if ( extra !== "padding" ) {
|
||||||
|
val += adjustWH( elem, name, "border", "Width" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( extra === "margin" ) {
|
||||||
|
val += adjustWH( elem, name, "margin" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -331,24 +347,33 @@ if ( document.documentElement.currentStyle ) {
|
||||||
curCSS = getComputedStyle || currentStyle;
|
curCSS = getComputedStyle || currentStyle;
|
||||||
|
|
||||||
function getWH( elem, name, extra ) {
|
function getWH( elem, name, extra ) {
|
||||||
var which = name === "width" ? cssWidth : cssHeight,
|
var val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
|
||||||
val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
|
|
||||||
|
|
||||||
if ( extra === "border" ) {
|
if ( extra === "border" ) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !extra ) {
|
||||||
|
val -= adjustWH( elem, name, "padding");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( extra !== "margin" ) {
|
||||||
|
val -= adjustWH( elem, name, "border", "Width");
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
function adjustWH( elem, name, prepend, append ) {
|
||||||
|
var which = name === "width" ? cssWidth : cssHeight,
|
||||||
|
val = 0;
|
||||||
|
|
||||||
|
if( !append ){
|
||||||
|
append = "";
|
||||||
|
}
|
||||||
|
|
||||||
jQuery.each( which, function() {
|
jQuery.each( which, function() {
|
||||||
if ( !extra ) {
|
val += parseFloat( jQuery.css( elem, prepend + this + append ) ) || 0;
|
||||||
val -= parseFloat(jQuery.css( elem, "padding" + this )) || 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( extra === "margin" ) {
|
|
||||||
val += parseFloat(jQuery.css( elem, "margin" + this )) || 0;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
val -= parseFloat(jQuery.css( elem, "border" + this + "Width" )) || 0;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
|
|
|
@ -211,6 +211,30 @@ test("outerWidth()", function() {
|
||||||
jQuery.removeData($div[0], "olddisplay", true);
|
jQuery.removeData($div[0], "olddisplay", true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("child of a hidden elem has accurate inner/outer/Width()/Height() see #9441 #9300", function() {
|
||||||
|
expect(8);
|
||||||
|
|
||||||
|
//setup html
|
||||||
|
var $divNormal = jQuery( '<div>' ).css({ width: "100px", border: "10px solid white", padding: "2px", margin: "3px" });
|
||||||
|
var $divChild = $divNormal.clone();
|
||||||
|
var $divHiddenParent = jQuery( '<div>' ).css( "display", "none" ).append( $divChild );
|
||||||
|
jQuery( 'body' ).append( $divHiddenParent ).append( $divNormal );
|
||||||
|
|
||||||
|
//tests that child div of a hidden div works the same as a normal div
|
||||||
|
equals( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #9441" );
|
||||||
|
equals( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #9441" );
|
||||||
|
equals( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #9441" );
|
||||||
|
equals( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" );
|
||||||
|
equals( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see #9441" );
|
||||||
|
equals( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see #9441" );
|
||||||
|
equals( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #9441" );
|
||||||
|
equals( $divChild.outerHeight(true), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #9300" );
|
||||||
|
|
||||||
|
//teardown html
|
||||||
|
$divHiddenParent.remove();
|
||||||
|
$divNormal.remove();
|
||||||
|
});
|
||||||
|
|
||||||
test("outerHeight()", function() {
|
test("outerHeight()", function() {
|
||||||
expect(11);
|
expect(11);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue