_core.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. define("dojox/fx/_core", ["dojo/_base/lang", "dojo/_base/array","./_base"],
  2. function(lang, arrayUtil, dojoxFx){
  3. /*===== var dojox.fx._Line = line =====*/
  4. var line = function(start, end){
  5. // summary: a custom _Line to accomodate multi-dimensional values
  6. //
  7. // description:
  8. // a normal dojo._Line is the curve, and does Line(start,end)
  9. // for propertyAnimation. as we make more complicatied animations, we realize
  10. // some properties can have 2, or 4 values relevant (x,y) or (t,l,r,b) for example
  11. //
  12. // this function provides support for those Lines, and is ported directly from 0.4
  13. // this is a lot of extra code for something so seldom used, so we'll put it here as
  14. // and optional core addition. you can create a new line, and use it during onAnimate
  15. // as you see fit.
  16. //
  17. // start: Integer|Array
  18. // An Integer (or an Array of integers) to use as a starting point
  19. // end: Integer|Array
  20. // An Integer (or an Array of integers) to use as an ending point
  21. //
  22. // example: see dojox.fx.smoothScroll
  23. //
  24. // example:
  25. // | // this is 10 .. 100 and 50 .. 500
  26. // | var curve = new dojox.fx._Line([10,50],[100,500]);
  27. // | // dojo.Animation.onAnimate is called at every step of the animation
  28. // | // to define current values. this _Line returns an array
  29. // | // at each step. arguments[0] and [1] in this example.
  30. //
  31. this.start = start;
  32. this.end = end;
  33. var isArray = lang.isArray(start),
  34. d = (isArray ? [] : end - start);
  35. if(isArray){
  36. // multi-dimensional branch
  37. arrayUtil.forEach(this.start, function(s, i){
  38. d[i] = this.end[i] - s;
  39. }, this);
  40. this.getValue = function(/*float*/ n){
  41. var res = [];
  42. arrayUtil.forEach(this.start, function(s, i){
  43. res[i] = (d[i] * n) + s;
  44. }, this);
  45. return res; // Array
  46. }
  47. }else{
  48. // single value branch, document here for both branches:
  49. this.getValue = function(/*float*/ n){
  50. // summary: Returns the point on the line, or an array of points
  51. // n: a floating point number greater than 0 and less than 1
  52. // returns: Mixed
  53. return (d * n) + this.start; // Decimal
  54. }
  55. }
  56. };
  57. dojoxFx._Line = line; // COMPAT
  58. return line;
  59. });