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.

127 lines
3.5 KiB

  1. /**
  2. enyo.TabPanels is a subkind of <a href="#enyo.Panels">enyo.Panels</a> that
  3. displays a set of tabs, which allow navigation between the individual panels.
  4. Unlike enyo.Panels, by default, the user cannot drag between the panels of a
  5. TabPanels. This behavior can be enabled by setting *draggable* to true.
  6. Here's an example:
  7. enyo.kind({
  8. name: "App",
  9. kind: "TabPanels",
  10. fit: true,
  11. components: [
  12. {kind: "MyStartPanel"},
  13. {kind: "MyMiddlePanel"},
  14. {kind: "MyLastPanel"}
  15. ]
  16. });
  17. new App().write();
  18. */
  19. enyo.kind({
  20. name: "enyo.TabPanels",
  21. kind: "Panels",
  22. //* @protected
  23. draggable: false,
  24. tabTools: [
  25. {name: "scroller", kind: "Scroller", maxHeight: "100px", strategyKind: "TranslateScrollStrategy", thumb: false, vertical: "hidden", horizontal: "auto", components: [
  26. {name: "tabs", kind: "onyx.RadioGroup", style: "text-align: left; white-space: nowrap", controlClasses: "onyx-tabbutton", onActivate: "tabActivate"}
  27. ]},
  28. {name: "client", fit: true, kind: "Panels", classes: "enyo-tab-panels", onTransitionStart: "clientTransitionStart"}
  29. ],
  30. create: function() {
  31. this.inherited(arguments);
  32. this.$.client.getPanels = enyo.bind(this, "getClientPanels");
  33. this.draggableChanged();
  34. this.animateChanged();
  35. this.wrapChanged();
  36. },
  37. initComponents: function() {
  38. this.createChrome(this.tabTools);
  39. this.inherited(arguments);
  40. },
  41. getClientPanels: function() {
  42. return this.getPanels();
  43. },
  44. flow: function() {
  45. this.inherited(arguments);
  46. this.$.client.flow();
  47. },
  48. reflow: function() {
  49. this.inherited(arguments);
  50. this.$.client.reflow();
  51. },
  52. draggableChanged: function() {
  53. this.$.client.setDraggable(this.draggable);
  54. this.draggable = false;
  55. },
  56. animateChanged: function() {
  57. this.$.client.setAnimate(this.animate);
  58. this.animate = false;
  59. },
  60. wrapChanged: function() {
  61. this.$.client.setWrap(this.wrap);
  62. this.wrap = false;
  63. },
  64. isPanel: function(inControl) {
  65. var n = inControl.name;
  66. return !(n == "tabs" || n == "client" || n == "scroller");
  67. },
  68. addControl: function(inControl) {
  69. this.inherited(arguments);
  70. if (this.isPanel(inControl)) {
  71. var c = inControl.caption || ("Tab " + this.$.tabs.controls.length);
  72. var t = inControl._tab = this.$.tabs.createComponent({content: c});
  73. if (this.hasNode()) {
  74. t.render();
  75. }
  76. }
  77. },
  78. removeControl: function(inControl) {
  79. if (this.isPanel(inControl) && inControl._tab) {
  80. inControl._tab.destroy();
  81. }
  82. this.inherited(arguments);
  83. },
  84. layoutKindChanged: function() {
  85. if (!this.layout) {
  86. this.layout = enyo.createFromKind("FittableRowsLayout", this);
  87. }
  88. this.$.client.setLayoutKind(this.layoutKind);
  89. },
  90. indexChanged: function() {
  91. // FIXME: initialization order problem
  92. if (this.$.client.layout) {
  93. this.$.client.setIndex(this.index);
  94. }
  95. this.index = this.$.client.getIndex();
  96. },
  97. tabActivate: function(inSender, inEvent) {
  98. if (this.hasNode()) {
  99. if (inEvent.originator.active) {
  100. var i = inEvent.originator.indexInContainer();
  101. if (this.getIndex() != i) {
  102. this.setIndex(i);
  103. }
  104. }
  105. }
  106. },
  107. clientTransitionStart: function(inSender, inEvent) {
  108. var i = inEvent.toIndex;
  109. var t = this.$.tabs.getClientControls()[i];
  110. if (t && t.hasNode()) {
  111. this.$.tabs.setActive(t);
  112. var tn = t.node;
  113. var tl = tn.offsetLeft;
  114. var tr = tl + tn.offsetWidth;
  115. var sb = this.$.scroller.getScrollBounds();
  116. if (tr < sb.left || tr > sb.left + sb.clientWidth) {
  117. this.$.scroller.scrollToControl(t);
  118. }
  119. }
  120. return true;
  121. },
  122. startTransition: enyo.nop,
  123. finishTransition: enyo.nop,
  124. stepTransition: enyo.nop,
  125. refresh: enyo.nop
  126. });