SpinWheel.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. define("dojox/mobile/SpinWheel", [
  2. "dojo/_base/array",
  3. "dojo/_base/declare",
  4. "dojo/_base/lang",
  5. "dojo/dom-class",
  6. "dojo/dom-construct",
  7. "dijit/_Contained",
  8. "dijit/_Container",
  9. "dijit/_WidgetBase",
  10. "./SpinWheelSlot"
  11. ], function(array, declare, lang, domClass, domConstruct, Contained, Container, WidgetBase, SpinWheelSlot){
  12. /*=====
  13. var Contained = dijit._Contained;
  14. var Container = dijit._Container;
  15. var WidgetBase = dijit._WidgetBase;
  16. =====*/
  17. // module:
  18. // dojox/mobile/SpinWheel
  19. // summary:
  20. // A value picker widget that has spin wheels.
  21. return declare("dojox.mobile.SpinWheel", [WidgetBase, Container, Contained],{
  22. // summary:
  23. // A value picker widget that has spin wheels.
  24. // description:
  25. // SpinWheel is a value picker component. It is a sectioned wheel
  26. // that can be used to pick up some values from the wheel slots by
  27. // spinning them.
  28. // slotClasses: Array
  29. // An array of slot classes to be this SpinWheel's slots.
  30. slotClasses: [],
  31. // slotProps: Array
  32. // An array of property objects for each slot class specified in
  33. // slotClasses.
  34. slotProps: [],
  35. /* internal properties */
  36. centerPos: 0,
  37. buildRendering: function(){
  38. this.inherited(arguments);
  39. domClass.add(this.domNode, "mblSpinWheel");
  40. this.centerPos = Math.round(this.domNode.offsetHeight / 2);
  41. this.slots = [];
  42. for(var i = 0; i < this.slotClasses.length; i++){
  43. this.slots.push(((typeof this.slotClasses[i] =='string') ? lang.getObject(this.slotClasses[i]) : this.slotClasses[i])(this.slotProps[i]));
  44. this.addChild(this.slots[i]);
  45. }
  46. domConstruct.create("DIV", {className: "mblSpinWheelBar"}, this.domNode);
  47. },
  48. startup: function(){
  49. this.inherited(arguments);
  50. this.reset();
  51. },
  52. getValue: function(){
  53. // summary:
  54. // Returns an array of slot values.
  55. var a = [];
  56. array.forEach(this.getChildren(), function(w){
  57. if(w instanceof SpinWheelSlot){
  58. a.push(w.getValue());
  59. }
  60. }, this);
  61. return a;
  62. },
  63. setValue: function(/*Array*/a){
  64. // summary:
  65. // Sets the slot values.
  66. var i = 0;
  67. array.forEach(this.getChildren(), function(w){
  68. if(w instanceof SpinWheelSlot){
  69. w.setValue(a[i]);
  70. w.setColor(a[i]);
  71. i++;
  72. }
  73. }, this);
  74. },
  75. reset: function(){
  76. // summary:
  77. // Resets the SpinWheel to show the initial values.
  78. array.forEach(this.getChildren(), function(w){
  79. if(w instanceof SpinWheelSlot){
  80. w.setInitialValue();
  81. }
  82. }, this);
  83. }
  84. });
  85. });