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

Function getWidthOrHeight

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

Source from the content-addressed store, hash-verified

5782}
5783
5784function getWidthOrHeight( elem, dimension, extra ) {
5785
5786 // Start with computed style
5787 var styles = getStyles( elem ),
5788
5789 // To avoid forcing a reflow, only fetch boxSizing if we need it (gh-4322).
5790 // Fake content-box until we know it's needed to know the true value.
5791 boxSizingNeeded = isIE || extra,
5792 isBorderBox = boxSizingNeeded &&
5793 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
5794 valueIsBorderBox = isBorderBox,
5795
5796 val = curCSS( elem, dimension, styles ),
5797 offsetProp = "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 );
5798
5799 // Return a confounding non-pixel value or feign ignorance, as appropriate.
5800 if ( rnumnonpx.test( val ) ) {
5801 if ( !extra ) {
5802 return val;
5803 }
5804 val = "auto";
5805 }
5806
5807
5808 if (
5809 (
5810
5811 // Fall back to offsetWidth/offsetHeight when value is "auto"
5812 // This happens for inline elements with no explicit setting (gh-3571)
5813 val === "auto" ||
5814
5815 // Support: IE 9 - 11+
5816 // Use offsetWidth/offsetHeight for when box sizing is unreliable.
5817 // In those cases, the computed value can be trusted to be border-box.
5818 ( isIE && isBorderBox ) ||
5819
5820 ( !support.reliableColDimensions() && nodeName( elem, "col" ) ) ||
5821
5822 ( !support.reliableTrDimensions() && nodeName( elem, "tr" ) )
5823 ) &&
5824
5825 // Make sure the element is visible & connected
5826 elem.getClientRects().length ) {
5827
5828 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
5829
5830 // Where available, offsetWidth/offsetHeight approximate border box dimensions.
5831 // Where not available (e.g., SVG), assume unreliable box-sizing and interpret the
5832 // retrieved value as a content box dimension.
5833 valueIsBorderBox = offsetProp in elem;
5834 if ( valueIsBorderBox ) {
5835 val = elem[ offsetProp ];
5836 }
5837 }
5838
5839 // Normalize "" and auto
5840 val = parseFloat( val ) || 0;
5841

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