not really known
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.

110 lines
3.3 KiB

  1. /**
  2. _onyx.FlyweightPicker_, a subkind of <a href="#onyx.Picker">onyx.Picker</a>,
  3. is a picker that employs the flyweight pattern. It is used to display a
  4. large list of selectable items. As with
  5. <a href="#enyo.FlyweightRepeater">enyo.FlyweightRepeater</a>,
  6. the _onSetupItem_ event allows for customization of item rendering.
  7. To initialize the FlyweightPicker to a particular value, call _setSelected_
  8. with the index of the item you wish to select, and call _setContent_ with
  9. the item that should be shown in the activator button.
  10. FlyweightPicker will send an _onSelect_ event with a selected item's
  11. information. This can be received by a client application to determine which
  12. item was selected.
  13. enyo.kind({
  14. handlers: {
  15. onSelect: "itemSelected"
  16. },
  17. components: [
  18. {kind: "onyx.PickerDecorator", components: [
  19. {},
  20. {name: "yearPicker", kind: "onyx.FlyweightPicker", count: 200,
  21. onSetupItem: "setupYear", components: [
  22. {name: "year"}
  23. ]
  24. }
  25. ]}
  26. ],
  27. create: function() {
  28. var d = new Date();
  29. var y = d.getYear();
  30. this.$.yearPicker.setSelected(y);
  31. this.$.year.setContent(1900+y);
  32. },
  33. setupYear: function(inSender, inEvent) {
  34. this.$.year.setContent(1900+inEvent.index);
  35. },
  36. itemSelected: function(inSender, inEvent) {
  37. enyo.log("Picker Item Selected: " + inEvent.selected.content);
  38. }
  39. })
  40. */
  41. enyo.kind({
  42. name: "onyx.FlyweightPicker",
  43. kind: "onyx.Picker",
  44. classes: "onyx-flyweight-picker",
  45. published: {
  46. //* How many rows to render
  47. count: 0
  48. },
  49. events: {
  50. //* Sends the row index, and the row control, for decoration.
  51. onSetupItem: "",
  52. onSelect: ""
  53. },
  54. handlers: {
  55. onSelect: "itemSelect"
  56. },
  57. components: [
  58. {name: "scroller", kind: "enyo.Scroller", strategyKind: "TouchScrollStrategy", components: [
  59. {name: "client", kind: "FlyweightRepeater", ontap: "itemTap"}
  60. ]}
  61. ],
  62. scrollerName: "scroller",
  63. create: function() {
  64. this.inherited(arguments);
  65. this.countChanged();
  66. },
  67. rendered: function() {
  68. this.inherited(arguments);
  69. this.selectedChanged();
  70. },
  71. scrollToSelected: function() {
  72. var n = this.$.client.fetchRowNode(this.selected);
  73. this.getScroller().scrollToNode(n, !this.menuUp);
  74. },
  75. countChanged: function() {
  76. this.$.client.count = this.count;
  77. },
  78. processActivatedItem: function(inItem) {
  79. this.item = inItem;
  80. },
  81. selectedChanged: function(inOld) {
  82. if (!this.item) {
  83. return;
  84. }
  85. if (inOld !== undefined) {
  86. this.item.removeClass("selected");
  87. this.$.client.renderRow(inOld);
  88. }
  89. this.item.addClass("selected");
  90. this.$.client.renderRow(this.selected);
  91. // need to remove the class from control to make sure it won't apply to other rows
  92. this.item.removeClass("selected");
  93. var n = this.$.client.fetchRowNode(this.selected);
  94. this.doChange({selected: this.selected, content: n && n.textContent || this.item.content});
  95. },
  96. itemTap: function(inSender, inEvent) {
  97. this.setSelected(inEvent.rowIndex);
  98. //Send the select event that we want the client to receive.
  99. this.doSelect({selected: this.item, content: this.item.content})
  100. },
  101. itemSelect: function(inSender, inEvent) {
  102. //Block all select events that aren't coming from this control. This is to prevent select events from MenuItems since they won't have the correct value in a Flyweight context.
  103. if (inEvent.originator != this) {
  104. return true;
  105. }
  106. }
  107. });