10 "./css/var/getStyles",
19 "./selector" // contains
20 ], function( jQuery, pnum, access, rmargin, document, rcssNum, rnumnonpx, cssExpand,
21 getStyles, swap, curCSS, adjustCSS, addGetHookIf, support ) {
27 // Swappable if display is none or starts with table
28 // except "table", "table-cell", or "table-caption"
29 // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
30 rdisplayswap = /^(none|table(?!-c[ea]).+)/,
32 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
33 cssNormalTransform = {
38 cssPrefixes = [ "Webkit", "Moz", "ms" ],
39 emptyStyle = document.createElement( "div" ).style;
41 // Return a css property mapped to a potentially vendor prefixed property
42 function vendorPropName( name ) {
44 // Shortcut for names that are not vendor prefixed
45 if ( name in emptyStyle ) {
49 // Check for vendor prefixed names
50 var capName = name[ 0 ].toUpperCase() + name.slice( 1 ),
51 i = cssPrefixes.length;
54 name = cssPrefixes[ i ] + capName;
55 if ( name in emptyStyle ) {
61 // Return a property mapped along what jQuery.cssProps suggests or to
62 // a vendor prefixed property.
63 function finalPropName( name ) {
64 var ret = jQuery.cssProps[ name ];
66 ret = jQuery.cssProps[ name ] = vendorPropName( name ) || name;
71 function setPositiveNumber( elem, value, subtract ) {
73 // Any relative (+/-) values have already been
74 // normalized at this point
75 var matches = rcssNum.exec( value );
78 // Guard against undefined "subtract", e.g., when used as in cssHooks
79 Math.max( 0, matches[ 2 ] - ( subtract || 0 ) ) + ( matches[ 3 ] || "px" ) :
83 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
87 // If we already have the right measurement, avoid augmentation
88 if ( extra === ( isBorderBox ? "border" : "content" ) ) {
91 // Otherwise initialize for horizontal or vertical properties
93 i = name === "width" ? 1 : 0;
96 for ( ; i < 4; i += 2 ) {
98 // Both box models exclude margin, so add it if we want it
99 if ( extra === "margin" ) {
100 val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
105 // border-box includes padding, so remove it if we want content
106 if ( extra === "content" ) {
107 val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
110 // At this point, extra isn't border nor margin, so remove border
111 if ( extra !== "margin" ) {
112 val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
116 // At this point, extra isn't content, so add padding
117 val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
119 // At this point, extra isn't content nor padding, so add border
120 if ( extra !== "padding" ) {
121 val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
129 function getWidthOrHeight( elem, name, extra ) {
131 // Start with computed style
132 var valueIsBorderBox,
133 styles = getStyles( elem ),
134 val = curCSS( elem, name, styles ),
135 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
137 // Computed unit is not pixels. Stop here and return.
138 if ( rnumnonpx.test( val ) ) {
142 // Check for style in case a browser which returns unreliable values
143 // for getComputedStyle silently falls back to the reliable elem.style
144 valueIsBorderBox = isBorderBox &&
145 ( support.boxSizingReliable() || val === elem.style[ name ] );
147 // Fall back to offsetWidth/Height when value is "auto"
148 // This happens for inline elements with no explicit setting (gh-3571)
149 if ( val === "auto" ) {
150 val = elem[ "offset" + name[ 0 ].toUpperCase() + name.slice( 1 ) ];
153 // Normalize "", auto, and prepare for extra
154 val = parseFloat( val ) || 0;
156 // Use the active box-sizing model to add/subtract irrelevant styles
158 augmentWidthOrHeight(
161 extra || ( isBorderBox ? "border" : "content" ),
170 // Add in style property hooks for overriding the default
171 // behavior of getting and setting a style property
174 get: function( elem, computed ) {
177 // We should always get a number back from opacity
178 var ret = curCSS( elem, "opacity" );
179 return ret === "" ? "1" : ret;
185 // Don't automatically add "px" to these possibly-unitless properties
187 "animationIterationCount": true,
202 // Add in properties whose names you wish to fix before
203 // setting or getting the value
208 // Get and set the style property on a DOM Node
209 style: function( elem, name, value, extra ) {
211 // Don't set styles on text and comment nodes
212 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
216 // Make sure that we're working with the right name
217 var ret, type, hooks,
218 origName = jQuery.camelCase( name ),
219 isCustomProp = rcustomProp.test( name ),
222 // Make sure that we're working with the right name. We don't
223 // want to query the value if it is a CSS custom property
224 // since they are user-defined.
225 if ( !isCustomProp ) {
226 name = finalPropName( origName );
229 // Gets hook for the prefixed version, then unprefixed version
230 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
232 // Check if we're setting a value
233 if ( value !== undefined ) {
236 // Convert "+=" or "-=" to relative numbers (#7345)
237 if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) {
238 value = adjustCSS( elem, name, ret );
244 // Make sure that null and NaN values aren't set (#7116)
245 if ( value == null || value !== value ) {
249 // If a number was passed in, add the unit (except for certain CSS properties)
250 if ( type === "number" ) {
251 value += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? "" : "px" );
254 // background-* props affect original clone's values
255 if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
256 style[ name ] = "inherit";
259 // If a hook was provided, use that value, otherwise just set the specified value
260 if ( !hooks || !( "set" in hooks ) ||
261 ( value = hooks.set( elem, value, extra ) ) !== undefined ) {
263 if ( isCustomProp ) {
264 style.setProperty( name, value );
266 style[ name ] = value;
272 // If a hook was provided get the non-computed value from there
273 if ( hooks && "get" in hooks &&
274 ( ret = hooks.get( elem, false, extra ) ) !== undefined ) {
279 // Otherwise just get the value from the style object
280 return style[ name ];
284 css: function( elem, name, extra, styles ) {
286 origName = jQuery.camelCase( name ),
287 isCustomProp = rcustomProp.test( name );
289 // Make sure that we're working with the right name. We don't
290 // want to modify the value if it is a CSS custom property
291 // since they are user-defined.
292 if ( !isCustomProp ) {
293 name = finalPropName( origName );
296 // Try prefixed name followed by the unprefixed name
297 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
299 // If a hook was provided get the computed value from there
300 if ( hooks && "get" in hooks ) {
301 val = hooks.get( elem, true, extra );
304 // Otherwise, if a way to get the computed value exists, use that
305 if ( val === undefined ) {
306 val = curCSS( elem, name, styles );
309 // Convert "normal" to computed value
310 if ( val === "normal" && name in cssNormalTransform ) {
311 val = cssNormalTransform[ name ];
314 // Make numeric if forced or a qualifier was provided and val looks numeric
315 if ( extra === "" || extra ) {
316 num = parseFloat( val );
317 return extra === true || isFinite( num ) ? num || 0 : val;
324 jQuery.each( [ "height", "width" ], function( i, name ) {
325 jQuery.cssHooks[ name ] = {
326 get: function( elem, computed, extra ) {
329 // Certain elements can have dimension info if we invisibly show them
330 // but it must have a current display style that would benefit
331 return rdisplayswap.test( jQuery.css( elem, "display" ) ) &&
333 // Support: Safari 8+
334 // Table columns in Safari have non-zero offsetWidth & zero
335 // getBoundingClientRect().width unless display is changed.
336 // Support: IE <=11 only
337 // Running getBoundingClientRect on a disconnected node
338 // in IE throws an error.
339 ( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ?
340 swap( elem, cssShow, function() {
341 return getWidthOrHeight( elem, name, extra );
343 getWidthOrHeight( elem, name, extra );
347 set: function( elem, value, extra ) {
349 styles = extra && getStyles( elem ),
350 subtract = extra && augmentWidthOrHeight(
354 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
358 // Convert to pixels if value adjustment is needed
359 if ( subtract && ( matches = rcssNum.exec( value ) ) &&
360 ( matches[ 3 ] || "px" ) !== "px" ) {
362 elem.style[ name ] = value;
363 value = jQuery.css( elem, name );
366 return setPositiveNumber( elem, value, subtract );
371 jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft,
372 function( elem, computed ) {
374 return ( parseFloat( curCSS( elem, "marginLeft" ) ) ||
375 elem.getBoundingClientRect().left -
376 swap( elem, { marginLeft: 0 }, function() {
377 return elem.getBoundingClientRect().left;
384 // These hooks are used by animate to expand properties
389 }, function( prefix, suffix ) {
390 jQuery.cssHooks[ prefix + suffix ] = {
391 expand: function( value ) {
395 // Assumes a single number if not a string
396 parts = typeof value === "string" ? value.split( " " ) : [ value ];
398 for ( ; i < 4; i++ ) {
399 expanded[ prefix + cssExpand[ i ] + suffix ] =
400 parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
407 if ( !rmargin.test( prefix ) ) {
408 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
413 css: function( name, value ) {
414 return access( this, function( elem, name, value ) {
419 if ( Array.isArray( name ) ) {
420 styles = getStyles( elem );
423 for ( ; i < len; i++ ) {
424 map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
430 return value !== undefined ?
431 jQuery.style( elem, name, value ) :
432 jQuery.css( elem, name );
433 }, name, value, arguments.length > 1 );