Toggler.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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["dojo.fx.Toggler"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojo.fx.Toggler"] = true;
  8. dojo.provide("dojo.fx.Toggler");
  9. dojo.declare("dojo.fx.Toggler", null, {
  10. // summary:
  11. // A simple `dojo.Animation` toggler API.
  12. //
  13. // description:
  14. // class constructor for an animation toggler. It accepts a packed
  15. // set of arguments about what type of animation to use in each
  16. // direction, duration, etc. All available members are mixed into
  17. // these animations from the constructor (for example, `node`,
  18. // `showDuration`, `hideDuration`).
  19. //
  20. // example:
  21. // | var t = new dojo.fx.Toggler({
  22. // | node: "nodeId",
  23. // | showDuration: 500,
  24. // | // hideDuration will default to "200"
  25. // | showFunc: dojo.fx.wipeIn,
  26. // | // hideFunc will default to "fadeOut"
  27. // | });
  28. // | t.show(100); // delay showing for 100ms
  29. // | // ...time passes...
  30. // | t.hide();
  31. // node: DomNode
  32. // the node to target for the showing and hiding animations
  33. node: null,
  34. // showFunc: Function
  35. // The function that returns the `dojo.Animation` to show the node
  36. showFunc: dojo.fadeIn,
  37. // hideFunc: Function
  38. // The function that returns the `dojo.Animation` to hide the node
  39. hideFunc: dojo.fadeOut,
  40. // showDuration:
  41. // Time in milliseconds to run the show Animation
  42. showDuration: 200,
  43. // hideDuration:
  44. // Time in milliseconds to run the hide Animation
  45. hideDuration: 200,
  46. // FIXME: need a policy for where the toggler should "be" the next
  47. // time show/hide are called if we're stopped somewhere in the
  48. // middle.
  49. // FIXME: also would be nice to specify individual showArgs/hideArgs mixed into
  50. // each animation individually.
  51. // FIXME: also would be nice to have events from the animations exposed/bridged
  52. /*=====
  53. _showArgs: null,
  54. _showAnim: null,
  55. _hideArgs: null,
  56. _hideAnim: null,
  57. _isShowing: false,
  58. _isHiding: false,
  59. =====*/
  60. constructor: function(args){
  61. var _t = this;
  62. dojo.mixin(_t, args);
  63. _t.node = args.node;
  64. _t._showArgs = dojo.mixin({}, args);
  65. _t._showArgs.node = _t.node;
  66. _t._showArgs.duration = _t.showDuration;
  67. _t.showAnim = _t.showFunc(_t._showArgs);
  68. _t._hideArgs = dojo.mixin({}, args);
  69. _t._hideArgs.node = _t.node;
  70. _t._hideArgs.duration = _t.hideDuration;
  71. _t.hideAnim = _t.hideFunc(_t._hideArgs);
  72. dojo.connect(_t.showAnim, "beforeBegin", dojo.hitch(_t.hideAnim, "stop", true));
  73. dojo.connect(_t.hideAnim, "beforeBegin", dojo.hitch(_t.showAnim, "stop", true));
  74. },
  75. show: function(delay){
  76. // summary: Toggle the node to showing
  77. // delay: Integer?
  78. // Ammount of time to stall playing the show animation
  79. return this.showAnim.play(delay || 0);
  80. },
  81. hide: function(delay){
  82. // summary: Toggle the node to hidden
  83. // delay: Integer?
  84. // Ammount of time to stall playing the hide animation
  85. return this.hideAnim.play(delay || 0);
  86. }
  87. });
  88. }