_TabContainerBase.js 5.0 KB

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