_TabContainerBase.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. require({cache:{
  2. 'url:dijit/layout/templates/TabContainer.html':"<div class=\"dijitTabContainer\">\n\t<div class=\"dijitTabListWrapper\" data-dojo-attach-point=\"tablistNode\"></div>\n\t<div data-dojo-attach-point=\"tablistSpacer\" class=\"dijitTabSpacer ${baseClass}-spacer\"></div>\n\t<div class=\"dijitTabPaneWrapper ${baseClass}-container\" data-dojo-attach-point=\"containerNode\"></div>\n</div>\n"}});
  3. define("dijit/layout/_TabContainerBase", [
  4. "dojo/text!./templates/TabContainer.html",
  5. "./StackContainer",
  6. "./utils", // marginBox2contextBox, layoutChildren
  7. "../_TemplatedMixin",
  8. "dojo/_base/declare", // declare
  9. "dojo/dom-class", // domClass.add
  10. "dojo/dom-geometry", // domGeometry.contentBox
  11. "dojo/dom-style" // domStyle.style
  12. ], function(template, StackContainer, layoutUtils, _TemplatedMixin, declare, domClass, domGeometry, domStyle){
  13. /*=====
  14. var StackContainer = dijit.layout.StackContainer;
  15. var _TemplatedMixin = dijit._TemplatedMixin;
  16. =====*/
  17. // module:
  18. // dijit/layout/_TabContainerBase
  19. // summary:
  20. // Abstract base class for TabContainer. Must define _makeController() to instantiate
  21. // and return the widget that displays the tab labels
  22. return declare("dijit.layout._TabContainerBase", [StackContainer, _TemplatedMixin], {
  23. // summary:
  24. // Abstract base class for TabContainer. Must define _makeController() to instantiate
  25. // and return the widget that displays the tab labels
  26. // description:
  27. // A TabContainer is a container that has multiple panes, but shows only
  28. // one pane at a time. There are a set of tabs corresponding to each pane,
  29. // where each tab has the name (aka title) of the pane, and optionally a close button.
  30. // tabPosition: String
  31. // Defines where tabs go relative to tab content.
  32. // "top", "bottom", "left-h", "right-h"
  33. tabPosition: "top",
  34. baseClass: "dijitTabContainer",
  35. // tabStrip: [const] Boolean
  36. // Defines whether the tablist gets an extra class for layouting, putting a border/shading
  37. // around the set of tabs. Not supported by claro theme.
  38. tabStrip: false,
  39. // nested: [const] Boolean
  40. // If true, use styling for a TabContainer nested inside another TabContainer.
  41. // For tundra etc., makes tabs look like links, and hides the outer
  42. // border since the outer TabContainer already has a border.
  43. nested: false,
  44. templateString: template,
  45. postMixInProperties: function(){
  46. // set class name according to tab position, ex: dijitTabContainerTop
  47. this.baseClass += this.tabPosition.charAt(0).toUpperCase() + this.tabPosition.substr(1).replace(/-.*/, "");
  48. this.srcNodeRef && domStyle.set(this.srcNodeRef, "visibility", "hidden");
  49. this.inherited(arguments);
  50. },
  51. buildRendering: function(){
  52. this.inherited(arguments);
  53. // Create the tab list that will have a tab (a.k.a. tab button) for each tab panel
  54. this.tablist = this._makeController(this.tablistNode);
  55. if(!this.doLayout){ domClass.add(this.domNode, "dijitTabContainerNoLayout"); }
  56. if(this.nested){
  57. /* workaround IE's lack of support for "a > b" selectors by
  58. * tagging each node in the template.
  59. */
  60. domClass.add(this.domNode, "dijitTabContainerNested");
  61. domClass.add(this.tablist.containerNode, "dijitTabContainerTabListNested");
  62. domClass.add(this.tablistSpacer, "dijitTabContainerSpacerNested");
  63. domClass.add(this.containerNode, "dijitTabPaneWrapperNested");
  64. }else{
  65. domClass.add(this.domNode, "tabStrip-" + (this.tabStrip ? "enabled" : "disabled"));
  66. }
  67. },
  68. _setupChild: function(/*dijit._Widget*/ tab){
  69. // Overrides StackContainer._setupChild().
  70. domClass.add(tab.domNode, "dijitTabPane");
  71. this.inherited(arguments);
  72. },
  73. startup: function(){
  74. if(this._started){ return; }
  75. // wire up the tablist and its tabs
  76. this.tablist.startup();
  77. this.inherited(arguments);
  78. },
  79. layout: function(){
  80. // Overrides StackContainer.layout().
  81. // Configure the content pane to take up all the space except for where the tabs are
  82. if(!this._contentBox || typeof(this._contentBox.l) == "undefined"){return;}
  83. var sc = this.selectedChildWidget;
  84. if(this.doLayout){
  85. // position and size the titles and the container node
  86. var titleAlign = this.tabPosition.replace(/-h/, "");
  87. this.tablist.layoutAlign = titleAlign;
  88. var children = [this.tablist, {
  89. domNode: this.tablistSpacer,
  90. layoutAlign: titleAlign
  91. }, {
  92. domNode: this.containerNode,
  93. layoutAlign: "client"
  94. }];
  95. layoutUtils.layoutChildren(this.domNode, this._contentBox, children);
  96. // Compute size to make each of my children.
  97. // children[2] is the margin-box size of this.containerNode, set by layoutChildren() call above
  98. this._containerContentBox = layoutUtils.marginBox2contentBox(this.containerNode, children[2]);
  99. if(sc && sc.resize){
  100. sc.resize(this._containerContentBox);
  101. }
  102. }else{
  103. // just layout the tab controller, so it can position left/right buttons etc.
  104. if(this.tablist.resize){
  105. //make the tabs zero width so that they don't interfere with width calc, then reset
  106. var s = this.tablist.domNode.style;
  107. s.width="0";
  108. var width = domGeometry.getContentBox(this.domNode).w;
  109. s.width="";
  110. this.tablist.resize({w: width});
  111. }
  112. // and call resize() on the selected pane just to tell it that it's been made visible
  113. if(sc && sc.resize){
  114. sc.resize();
  115. }
  116. }
  117. },
  118. destroy: function(){
  119. if(this.tablist){
  120. this.tablist.destroy();
  121. }
  122. this.inherited(arguments);
  123. }
  124. });
  125. });