curCSS.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. style = elem.style;
  13. computed = computed || getStyles( elem );
  14. // Support: IE <=9 only
  15. // getPropertyValue is only needed for .css('filter') (#12537)
  16. if ( computed ) {
  17. ret = computed.getPropertyValue( name ) || computed[ name ];
  18. if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
  19. ret = jQuery.style( elem, name );
  20. }
  21. // A tribute to the "awesome hack by Dean Edwards"
  22. // Android Browser returns percentage for some values,
  23. // but width seems to be reliably pixels.
  24. // This is against the CSSOM draft spec:
  25. // https://drafts.csswg.org/cssom/#resolved-values
  26. if ( !support.pixelMarginRight() && rnumnonpx.test( ret ) && rmargin.test( name ) ) {
  27. // Remember the original values
  28. width = style.width;
  29. minWidth = style.minWidth;
  30. maxWidth = style.maxWidth;
  31. // Put in the new values to get a computed value out
  32. style.minWidth = style.maxWidth = style.width = ret;
  33. ret = computed.width;
  34. // Revert the changed values
  35. style.width = width;
  36. style.minWidth = minWidth;
  37. style.maxWidth = maxWidth;
  38. }
  39. }
  40. return ret !== undefined ?
  41. // Support: IE <=9 - 11 only
  42. // IE returns zIndex value as an integer.
  43. ret + "" :
  44. ret;
  45. }
  46. return curCSS;
  47. } );