Blame view

node_modules/jquery/src/css/curCSS.js 3.23 KB
7820380e   “wangming”   1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  define( [
  	"../core",
  	"../core/isAttached",
  	"./var/rboxStyle",
  	"./var/rnumnonpx",
  	"./var/getStyles",
  	"./var/rcustomProp",
  	"../var/rtrimCSS",
  	"./support"
  ], function( jQuery, isAttached, rboxStyle, rnumnonpx, getStyles,
  	rcustomProp, rtrimCSS, support ) {
  
  "use strict";
  
  function curCSS( elem, name, computed ) {
  	var width, minWidth, maxWidth, ret,
  		isCustomProp = rcustomProp.test( name ),
  
  		// Support: Firefox 51+
  		// Retrieving style before computed somehow
  		// fixes an issue with getting wrong values
  		// on detached elements
  		style = elem.style;
  
  	computed = computed || getStyles( elem );
  
  	// getPropertyValue is needed for:
  	//   .css('filter') (IE 9 only, trac-12537)
  	//   .css('--customProperty) (gh-3144)
  	if ( computed ) {
  
  		// Support: IE <=9 - 11+
  		// IE only supports `"float"` in `getPropertyValue`; in computed styles
  		// it's only available as `"cssFloat"`. We no longer modify properties
  		// sent to `.css()` apart from camelCasing, so we need to check both.
  		// Normally, this would create difference in behavior: if
  		// `getPropertyValue` returns an empty string, the value returned
  		// by `.css()` would be `undefined`. This is usually the case for
  		// disconnected elements. However, in IE even disconnected elements
  		// with no styles return `"none"` for `getPropertyValue( "float" )`
  		ret = computed.getPropertyValue( name ) || computed[ name ];
  
  		if ( isCustomProp && ret ) {
  
  			// Support: Firefox 105+, Chrome <=105+
  			// Spec requires trimming whitespace for custom properties (gh-4926).
  			// Firefox only trims leading whitespace. Chrome just collapses
  			// both leading & trailing whitespace to a single space.
  			//
  			// Fall back to `undefined` if empty string returned.
  			// This collapses a missing definition with property defined
  			// and set to an empty string but there's no standard API
  			// allowing us to differentiate them without a performance penalty
  			// and returning `undefined` aligns with older jQuery.
  			//
  			// rtrimCSS treats U+000D CARRIAGE RETURN and U+000C FORM FEED
  			// as whitespace while CSS does not, but this is not a problem
  			// because CSS preprocessing replaces them with U+000A LINE FEED
  			// (which *is* CSS whitespace)
  			// https://www.w3.org/TR/css-syntax-3/#input-preprocessing
  			ret = ret.replace( rtrimCSS, "$1" ) || undefined;
  		}
  
  		if ( ret === "" && !isAttached( elem ) ) {
  			ret = jQuery.style( elem, name );
  		}
  
  		// A tribute to the "awesome hack by Dean Edwards"
  		// Android Browser returns percentage for some values,
  		// but width seems to be reliably pixels.
  		// This is against the CSSOM draft spec:
  		// https://drafts.csswg.org/cssom/#resolved-values
  		if ( !support.pixelBoxStyles() && rnumnonpx.test( ret ) && rboxStyle.test( name ) ) {
  
  			// Remember the original values
  			width = style.width;
  			minWidth = style.minWidth;
  			maxWidth = style.maxWidth;
  
  			// Put in the new values to get a computed value out
  			style.minWidth = style.maxWidth = style.width = ret;
  			ret = computed.width;
  
  			// Revert the changed values
  			style.width = width;
  			style.minWidth = minWidth;
  			style.maxWidth = maxWidth;
  		}
  	}
  
  	return ret !== undefined ?
  
  		// Support: IE <=9 - 11 only
  		// IE returns zIndex value as an integer.
  		ret + "" :
  		ret;
  }
  
  return curCSS;
  } );