MCPcopy Index your code
hub / github.com/jquery/jquery / getWidthOrHeight

Function getWidthOrHeight

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

Source from the content-addressed store, hash-verified

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

Callers 1

jQueryFactoryWrapperFunction · 0.70

Calls 4

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

Tested by

no test coverage detected