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.

87 lines
2.5 KiB

  1. /**
  2. _onyx.Picker_, a subkind of <a href="#onyx.Menu">onyx.Menu</a>, is used to
  3. display a list of items that can be selected. It is meant to be used in
  4. conjunction with an <a href="#onyx.PickerDecorator">onyx.PickerDecorator</a>.
  5. The decorator loosely couples the Picker with an
  6. <a href="#onyx.PickerButton">onyx.PickerButton</a>--a button that, when
  7. tapped, shows the picker. Once an item is selected, the list of items closes,
  8. but the item stays selected and the PickerButton displays the choice that
  9. was made.
  10. To initialize the Picker to a particular value, set the _active_ property to
  11. true for the item that should be selected.
  12. {kind: "onyx.PickerDecorator", components: [
  13. {}, //this uses the defaultKind property of PickerDecorator to inherit from PickerButton
  14. {kind: "onyx.Picker", components: [
  15. {content: "Gmail", active: true},
  16. {content: "Yahoo"},
  17. {content: "Outlook"},
  18. {content: "Hotmail"}
  19. ]}
  20. ]}
  21. Each item in the list is an <a href="#onyx.MenuItem">onyx.MenuItem</a>, so
  22. an _onSelect_ event with the item can be listened to by a client application
  23. to determine which picker item was selected.
  24. */
  25. enyo.kind({
  26. name: "onyx.Picker",
  27. kind: "onyx.Menu",
  28. classes: "onyx-picker enyo-unselectable",
  29. published: {
  30. selected: null,
  31. maxHeight: "200px"
  32. },
  33. events: {
  34. onChange: ""
  35. },
  36. components: [
  37. {name: "client", kind: "enyo.Scroller", strategyKind: "TouchScrollStrategy"}
  38. ],
  39. floating: true,
  40. showOnTop: true,
  41. scrollerName: "client",
  42. create: function() {
  43. this.inherited(arguments);
  44. this.maxHeightChanged();
  45. },
  46. getScroller: function() {
  47. return this.$[this.scrollerName];
  48. },
  49. maxHeightChanged: function() {
  50. this.getScroller().setMaxHeight(this.maxHeight);
  51. },
  52. showingChanged: function() {
  53. this.getScroller().setShowing(this.showing);
  54. this.inherited(arguments);
  55. if (this.showing && this.selected) {
  56. this.scrollToSelected();
  57. }
  58. },
  59. scrollToSelected: function() {
  60. this.getScroller().scrollToControl(this.selected, !this.menuUp);
  61. },
  62. itemActivated: function(inSender, inEvent) {
  63. this.processActivatedItem(inEvent.originator)
  64. return this.inherited(arguments);
  65. },
  66. processActivatedItem: function(inItem) {
  67. if (inItem.active) {
  68. this.setSelected(inItem);
  69. }
  70. },
  71. selectedChanged: function(inOld) {
  72. if (inOld) {
  73. inOld.removeClass("selected");
  74. }
  75. if (this.selected) {
  76. this.selected.addClass("selected");
  77. this.doChange({selected: this.selected, content: this.selected.content});
  78. };
  79. },
  80. resizeHandler: function() {
  81. this.inherited(arguments);
  82. this.adjustPosition(false);
  83. }
  84. });