_core.js 2.3 KB

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