curCSS.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. define( [
  2. "../core",
  3. "./var/rnumnonpx",
  4. "./var/rmargin",
  5. "./var/getStyles",
  6. "./support",
  7. "../selector" // Get jQuery.contains
  8. ], function( jQuery, rnumnonpx, rmargin, getStyles, support ) {
  9. "use strict";
  10. function curCSS( elem, name, computed ) {
  11. var width, minWidth, maxWidth, ret,
  12. // Support: Firefox 51+
  13. // Retrieving style before computed somehow
  14. // fixes an issue with getting wrong values
  15. // on detached elements
  16. style = elem.style;
  17. computed = computed || getStyles( elem );
  18. // getPropertyValue is needed for:
  19. // .css('filter') (IE 9 only, #12537)
  20. // .css('--customProperty) (#3144)
  21. if ( computed ) {
  22. ret = computed.getPropertyValue( name ) || computed[ name ];
  23. if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
  24. ret = jQuery.style( elem, name );
  25. }
  26. // A tribute to the "awesome hack by Dean Edwards"
  27. // Android Browser returns percentage for some values,
  28. // but width seems to be reliably pixels.
  29. // This is against the CSSOM draft spec:
  30. // https://drafts.csswg.org/cssom/#resolved-values
  31. if ( !support.pixelMarginRight() && rnumnonpx.test( ret ) && rmargin.test( name ) ) {
  32. // Remember the original values
  33. width = style.width;
  34. minWidth = style.minWidth;
  35. maxWidth = style.maxWidth;
  36. // Put in the new values to get a computed value out
  37. style.minWidth = style.maxWidth = style.width = ret;
  38. ret = computed.width;
  39. // Revert the changed values
  40. style.width = width;
  41. style.minWidth = minWidth;
  42. style.maxWidth = maxWidth;
  43. }
  44. }
  45. return ret !== undefined ?
  46. // Support: IE <=9 - 11 only
  47. // IE returns zIndex value as an integer.
  48. ret + "" :
  49. ret;
  50. }
  51. return curCSS;
  52. } );