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.

141 lines
4.1 KiB

  1. /**
  2. onyx.MoreToolbar is a kind of <a href="#onyx.Toolbar">onyx.Toolbar</a> that can adapt to different screen sizes by moving overflowing controls and content into an <a href="#onyx.Menu">onyx.Menu</a>
  3. {kind: "onyx.MoreToolbar", components: [
  4. {content: "More Toolbar", unmoveable: true},
  5. {kind: "onyx.Button", content: "Alpha"},
  6. {kind: "onyx.Button", content: "Beta"},
  7. {kind: "onyx.Button", content: "Gamma", unmoveable: true},
  8. {kind: "onyx.Button", content: "Epsilon"}
  9. ]},
  10. A control can be forced to never move to the menu by setting the optional unmovable property to true (default is false).
  11. Optionally you can specify a class to be applied to the menu via the menuClass property. You can also specify a class for items that have been moved via the the movedClass property.
  12. */
  13. enyo.kind({
  14. name: "onyx.MoreToolbar",
  15. //* @public
  16. classes: "onyx-toolbar onyx-more-toolbar",
  17. //* style class to be applied to the menu
  18. menuClass: "",
  19. //* style class to be applied to individual controls moved from the toolbar to the menu
  20. movedClass: "",
  21. //* @protected
  22. layoutKind: "FittableColumnsLayout",
  23. noStretch: true,
  24. handlers: {
  25. onHide: "reflow"
  26. },
  27. tools: [
  28. {name: "client", fit: true, classes: "onyx-toolbar-inline"},
  29. {name: "nard", kind: "onyx.MenuDecorator", showing: false, onActivate: "activated", components: [
  30. {kind: "onyx.IconButton", classes: "onyx-more-button"},
  31. {name: "menu", kind: "onyx.Menu", classes: "onyx-more-menu", prepend: true}
  32. ]}
  33. ],
  34. initComponents: function() {
  35. if(this.menuClass && this.menuClass.length>0 && !this.$.menu.hasClass(this.menuClass)) {
  36. this.$.menu.addClass(this.menuClass);
  37. }
  38. this.createChrome(this.tools);
  39. this.inherited(arguments);
  40. },
  41. reflow: function() {
  42. this.inherited(arguments);
  43. if (this.isContentOverflowing()) {
  44. this.$.nard.show();
  45. if (this.popItem()) {
  46. this.reflow();
  47. }
  48. } else if (this.tryPushItem()) {
  49. this.reflow();
  50. } else if (!this.$.menu.children.length) {
  51. this.$.nard.hide();
  52. this.$.menu.hide();
  53. }
  54. },
  55. activated: function(inSender, inEvent) {
  56. this.addRemoveClass("active",inEvent.originator.active);
  57. },
  58. popItem: function() {
  59. var c = this.findCollapsibleItem();
  60. if (c) {
  61. //apply movedClass is needed
  62. if(this.movedClass && this.movedClass.length>0 && !c.hasClass(this.movedClass)) {
  63. c.addClass(this.movedClass);
  64. }
  65. this.$.menu.addChild(c);
  66. var p = this.$.menu.hasNode();
  67. if (p && c.hasNode()) {
  68. c.insertNodeInParent(p);
  69. }
  70. return true;
  71. }
  72. },
  73. pushItem: function() {
  74. var c$ = this.$.menu.children;
  75. var c = c$[0];
  76. if (c) {
  77. //remove any applied movedClass
  78. if(this.movedClass && this.movedClass.length>0 && c.hasClass(this.movedClass)) {
  79. c.removeClass(this.movedClass);
  80. }
  81. this.$.client.addChild(c);
  82. var p = this.$.client.hasNode();
  83. if (p && c.hasNode()) {
  84. var nextChild = undefined;
  85. var currIndex;
  86. for(var i=0; i<this.$.client.children.length; i++) {
  87. var curr = this.$.client.children[i];
  88. if(curr.toolbarIndex!=undefined && curr.toolbarIndex!=i) {
  89. nextChild = curr;
  90. currIndex = i;
  91. break;
  92. }
  93. }
  94. if(nextChild && nextChild.hasNode()) {
  95. c.insertNodeInParent(p, nextChild.node);
  96. var newChild = this.$.client.children.pop();
  97. this.$.client.children.splice(currIndex, 0, newChild);
  98. } else {
  99. c.appendNodeToParent(p);
  100. }
  101. }
  102. return true;
  103. }
  104. },
  105. tryPushItem: function() {
  106. if (this.pushItem()) {
  107. if (!this.isContentOverflowing()) {
  108. return true;
  109. } else {
  110. this.popItem();
  111. }
  112. }
  113. },
  114. isContentOverflowing: function() {
  115. if (this.$.client.hasNode()) {
  116. var c$ = this.$.client.children;
  117. var n = c$[c$.length-1].hasNode();
  118. if(n) {
  119. //Workaround: scrollWidth value not working in Firefox, so manually compute
  120. //return (this.$.client.node.scrollWidth > this.$.client.node.clientWidth);
  121. return ((n.offsetLeft + n.offsetWidth) > this.$.client.node.clientWidth);
  122. }
  123. }
  124. },
  125. findCollapsibleItem: function() {
  126. var c$ = this.$.client.children;
  127. for (var i=c$.length-1; c=c$[i]; i--) {
  128. if (!c.unmoveable) {
  129. return c;
  130. } else {
  131. if(c.toolbarIndex==undefined) {
  132. c.toolbarIndex = i;
  133. }
  134. }
  135. }
  136. }
  137. });