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

Function boxModelAdjustment

dist-module/jquery.factory.module.js:5981–6050  ·  view source on GitHub ↗
( elem, dimension, box, isBorderBox, styles, computedVal )

Source from the content-addressed store, hash-verified

5979}
5980
5981function boxModelAdjustment( elem, dimension, box, isBorderBox, styles, computedVal ) {
5982 var i = dimension === "width" ? 1 : 0,
5983 extra = 0,
5984 delta = 0,
5985 marginDelta = 0;
5986
5987 // Adjustment may not be necessary
5988 if ( box === ( isBorderBox ? "border" : "content" ) ) {
5989 return 0;
5990 }
5991
5992 for ( ; i < 4; i += 2 ) {
5993
5994 // Both box models exclude margin
5995 // Count margin delta separately to only add it after scroll gutter adjustment.
5996 // This is needed to make negative margins work with `outerHeight( true )` (gh-3982).
5997 if ( box === "margin" ) {
5998 marginDelta += jQuery.css( elem, box + cssExpand[ i ], true, styles );
5999 }
6000
6001 // If we get here with a content-box, we're seeking "padding" or "border" or "margin"
6002 if ( !isBorderBox ) {
6003
6004 // Add padding
6005 delta += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
6006
6007 // For "border" or "margin", add border
6008 if ( box !== "padding" ) {
6009 delta += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
6010
6011 // But still keep track of it otherwise
6012 } else {
6013 extra += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
6014 }
6015
6016 // If we get here with a border-box (content + padding + border), we're seeking "content" or
6017 // "padding" or "margin"
6018 } else {
6019
6020 // For "content", subtract padding
6021 if ( box === "content" ) {
6022 delta -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
6023 }
6024
6025 // For "content" or "padding", subtract border
6026 if ( box !== "margin" ) {
6027 delta -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
6028 }
6029 }
6030 }
6031
6032 // Account for positive content-box scroll gutter when requested by providing computedVal
6033 if ( !isBorderBox && computedVal >= 0 ) {
6034
6035 // offsetWidth/offsetHeight is a rounded sum of content, padding, scroll gutter, and border
6036 // Assuming integer scroll gutter, subtract the rest and round down
6037 delta += Math.max( 0, Math.ceil(
6038 elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ] -

Callers 2

getWidthOrHeightFunction · 0.70
jQueryFactoryWrapperFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected