cc2d8579a9756436f01e5ab961c393a9575de7faf98a1d3f6061100ae682c9e0266cbe10790a6a801f855bcf225aa3a4743d3a0342f6c356b71299236e60f5 3.2 KB

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