MCPcopy
hub / github.com/jquery/jquery / getWidthOrHeight

Function getWidthOrHeight

dist-module/jquery.module.js:6047–6118  ·  view source on GitHub ↗
( elem, dimension, extra )

Source from the content-addressed store, hash-verified

6045}
6046
6047function getWidthOrHeight( elem, dimension, extra ) {
6048
6049 // Start with computed style
6050 var styles = getStyles( elem ),
6051
6052 // To avoid forcing a reflow, only fetch boxSizing if we need it (gh-4322).
6053 // Fake content-box until we know it's needed to know the true value.
6054 boxSizingNeeded = isIE || extra,
6055 isBorderBox = boxSizingNeeded &&
6056 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
6057 valueIsBorderBox = isBorderBox,
6058
6059 val = curCSS( elem, dimension, styles ),
6060 offsetProp = "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 );
6061
6062 // Return a confounding non-pixel value or feign ignorance, as appropriate.
6063 if ( rnumnonpx.test( val ) ) {
6064 if ( !extra ) {
6065 return val;
6066 }
6067 val = "auto";
6068 }
6069
6070
6071 if (
6072 (
6073
6074 // Fall back to offsetWidth/offsetHeight when value is "auto"
6075 // This happens for inline elements with no explicit setting (gh-3571)
6076 val === "auto" ||
6077
6078 // Support: IE 9 - 11+
6079 // Use offsetWidth/offsetHeight for when box sizing is unreliable.
6080 // In those cases, the computed value can be trusted to be border-box.
6081 ( isIE && isBorderBox ) ||
6082
6083 ( !support.reliableColDimensions() && nodeName( elem, "col" ) ) ||
6084
6085 ( !support.reliableTrDimensions() && nodeName( elem, "tr" ) )
6086 ) &&
6087
6088 // Make sure the element is visible & connected
6089 elem.getClientRects().length ) {
6090
6091 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
6092
6093 // Where available, offsetWidth/offsetHeight approximate border box dimensions.
6094 // Where not available (e.g., SVG), assume unreliable box-sizing and interpret the
6095 // retrieved value as a content box dimension.
6096 valueIsBorderBox = offsetProp in elem;
6097 if ( valueIsBorderBox ) {
6098 val = elem[ offsetProp ];
6099 }
6100 }
6101
6102 // Normalize "" and auto
6103 val = parseFloat( val ) || 0;
6104

Callers 1

jQueryFactoryFunction · 0.70

Calls 4

getStylesFunction · 0.70
curCSSFunction · 0.70
nodeNameFunction · 0.70
boxModelAdjustmentFunction · 0.70

Tested by

no test coverage detected