curCSS.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. define([
  2. "../core",
  3. "./var/rnumnonpx",
  4. "./var/rmargin",
  5. "./var/getStyles",
  6. "../selector" // contains
  7. ], function( jQuery, rnumnonpx, rmargin, getStyles ) {
  8. function curCSS( elem, name, computed ) {
  9. var width, minWidth, maxWidth, ret,
  10. style = elem.style;
  11. computed = computed || getStyles( elem );
  12. // Support: IE9
  13. // getPropertyValue is only needed for .css('filter') (#12537)
  14. if ( computed ) {
  15. ret = computed.getPropertyValue( name ) || computed[ name ];
  16. }
  17. if ( computed ) {
  18. if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
  19. ret = jQuery.style( elem, name );
  20. }
  21. // Support: iOS < 6
  22. // A tribute to the "awesome hack by Dean Edwards"
  23. // iOS < 6 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
  24. // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
  25. if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
  26. // Remember the original values
  27. width = style.width;
  28. minWidth = style.minWidth;
  29. maxWidth = style.maxWidth;
  30. // Put in the new values to get a computed value out
  31. style.minWidth = style.maxWidth = style.width = ret;
  32. ret = computed.width;
  33. // Revert the changed values
  34. style.width = width;
  35. style.minWidth = minWidth;
  36. style.maxWidth = maxWidth;
  37. }
  38. }
  39. return ret !== undefined ?
  40. // Support: IE
  41. // IE returns zIndex value as an integer.
  42. ret + "" :
  43. ret;
  44. }
  45. return curCSS;
  46. });