MCPcopy
hub / github.com/jquery/jquery / curCSS

Function curCSS

src/css/curCSS.js:7–62  ·  view source on GitHub ↗
( elem, name, computed )

Source from the content-addressed store, hash-verified

5import { rtrimCSS } from "../var/rtrimCSS.js";
6
7export function curCSS( elem, name, computed ) {
8 var ret,
9 isCustomProp = rcustomProp.test( name );
10
11 computed = computed || getStyles( elem );
12
13 // getPropertyValue is needed for `.css('--customProperty')` (gh-3144)
14 if ( computed ) {
15
16 // A fallback to direct property access is needed as `computed`, being
17 // the output of `getComputedStyle`, contains camelCased keys and
18 // `getPropertyValue` requires kebab-case ones.
19 //
20 // Support: IE <=9 - 11+
21 // IE only supports `"float"` in `getPropertyValue`; in computed styles
22 // it's only available as `"cssFloat"`. We no longer modify properties
23 // sent to `.css()` apart from camelCasing, so we need to check both.
24 // Normally, this would create difference in behavior: if
25 // `getPropertyValue` returns an empty string, the value returned
26 // by `.css()` would be `undefined`. This is usually the case for
27 // disconnected elements. However, in IE even disconnected elements
28 // with no styles return `"none"` for `getPropertyValue( "float" )`
29 ret = computed.getPropertyValue( name ) || computed[ name ];
30
31 if ( isCustomProp && ret ) {
32
33 // Support: Firefox 105 - 135+
34 // Spec requires trimming whitespace for custom properties (gh-4926).
35 // Firefox only trims leading whitespace.
36 //
37 // Fall back to `undefined` if empty string returned.
38 // This collapses a missing definition with property defined
39 // and set to an empty string but there's no standard API
40 // allowing us to differentiate them without a performance penalty
41 // and returning `undefined` aligns with older jQuery.
42 //
43 // rtrimCSS treats U+000D CARRIAGE RETURN and U+000C FORM FEED
44 // as whitespace while CSS does not, but this is not a problem
45 // because CSS preprocessing replaces them with U+000A LINE FEED
46 // (which *is* CSS whitespace)
47 // https://www.w3.org/TR/css-syntax-3/#input-preprocessing
48 ret = ret.replace( rtrimCSS, "$1" ) || undefined;
49 }
50
51 if ( ret === "" && !isAttached( elem ) ) {
52 ret = jQuery.style( elem, name );
53 }
54 }
55
56 return ret !== undefined ?
57
58 // Support: IE <=9 - 11+
59 // IE returns zIndex value as an integer.
60 ret + "" :
61 ret;
62}

Callers 2

getWidthOrHeightFunction · 0.90
css.jsFile · 0.90

Calls 2

getStylesFunction · 0.90
isAttachedFunction · 0.90

Tested by

no test coverage detected