You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.8KB

  1. define( [
  2. "../core",
  3. "../var/rcssNum"
  4. ], function( jQuery, rcssNum ) {
  5. function adjustCSS( elem, prop, valueParts, tween ) {
  6. var adjusted,
  7. scale = 1,
  8. maxIterations = 20,
  9. currentValue = tween ?
  10. function() { return tween.cur(); } :
  11. function() { return jQuery.css( elem, prop, "" ); },
  12. initial = currentValue(),
  13. unit = valueParts && valueParts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
  14. // Starting value computation is required for potential unit mismatches
  15. initialInUnit = ( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) &&
  16. rcssNum.exec( jQuery.css( elem, prop ) );
  17. if ( initialInUnit && initialInUnit[ 3 ] !== unit ) {
  18. // Trust units reported by jQuery.css
  19. unit = unit || initialInUnit[ 3 ];
  20. // Make sure we update the tween properties later on
  21. valueParts = valueParts || [];
  22. // Iteratively approximate from a nonzero starting point
  23. initialInUnit = +initial || 1;
  24. do {
  25. // If previous iteration zeroed out, double until we get *something*.
  26. // Use string for doubling so we don't accidentally see scale as unchanged below
  27. scale = scale || ".5";
  28. // Adjust and apply
  29. initialInUnit = initialInUnit / scale;
  30. jQuery.style( elem, prop, initialInUnit + unit );
  31. // Update scale, tolerating zero or NaN from tween.cur()
  32. // Break the loop if scale is unchanged or perfect, or if we've just had enough.
  33. } while (
  34. scale !== ( scale = currentValue() / initial ) && scale !== 1 && --maxIterations
  35. );
  36. }
  37. if ( valueParts ) {
  38. initialInUnit = +initialInUnit || +initial || 0;
  39. // Apply relative offset (+=/-=) if specified
  40. adjusted = valueParts[ 1 ] ?
  41. initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] :
  42. +valueParts[ 2 ];
  43. if ( tween ) {
  44. tween.unit = unit;
  45. tween.start = initialInUnit;
  46. tween.end = adjusted;
  47. }
  48. }
  49. return adjusted;
  50. }
  51. return adjustCSS;
  52. } );