1 if(!dojo._hasResource["dijit.layout.TabContainer"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dijit.layout.TabContainer"] = true;
3 dojo.provide("dijit.layout.TabContainer");
5 dojo.require("dijit.layout.StackContainer");
6 dojo.require("dijit._Templated");
8 dojo.declare("dijit.layout.TabContainer",
9 [dijit.layout.StackContainer, dijit._Templated],
12 // A Container with Title Tabs, each one pointing at a pane in the container.
14 // A TabContainer is a container that has multiple panes, but shows only
15 // one pane at a time. There are a set of tabs corresponding to each pane,
16 // where each tab has the title (aka title) of the pane, and optionally a close button.
18 // Publishes topics [widgetId]-addChild, [widgetId]-removeChild, and [widgetId]-selectChild
19 // (where [widgetId] is the id of the TabContainer itself.
21 // tabPosition: String
22 // Defines where tabs go relative to tab content.
23 // "top", "bottom", "left-h", "right-h"
26 templateString: null, // override setting in StackContainer
27 templateString:"<div class=\"dijitTabContainer\">\n\t<div dojoAttachPoint=\"tablistNode\"></div>\n\t<div class=\"dijitTabPaneWrapper\" dojoAttachPoint=\"containerNode\"></div>\n</div>\n",
29 // _controllerWidget: String
30 // An optional parameter to overrider the default TabContainer controller used.
31 _controllerWidget: "dijit.layout.TabController",
33 postCreate: function(){
34 this.inherited(arguments);
35 // create the tab list that will have a tab (a.k.a. tab button) for each tab panel
36 var TabController = dojo.getObject(this._controllerWidget);
37 this.tablist = new TabController({
38 id: this.id + "_tablist",
39 tabPosition: this.tabPosition,
40 doLayout: this.doLayout,
45 _setupChild: function(/* Widget */tab){
46 dojo.addClass(tab.domNode, "dijitTabPane");
47 this.inherited(arguments);
52 if(this._started){ return; }
54 // wire up the tablist and its tabs
55 this.tablist.startup();
56 this.inherited(arguments);
59 // sometimes safari 3.0.3 miscalculates the height of the tab labels, see #4058
60 setTimeout(dojo.hitch(this, "layout"), 0);
63 if(dojo.isIE && !this.isLeftToRight() && this.tabPosition == "right-h" &&
64 this.tablist && this.tablist.pane2button){
65 //need rectify non-closable tab in IE, only for "right-h" mode
66 for(var pane in this.tablist.pane2button){
67 var tabButton = this.tablist.pane2button[pane];
68 if(!tabButton.closeButton){ continue; }
69 tabButtonStyle = tabButton.closeButtonNode.style;
70 tabButtonStyle.position ="absolute";
72 tabButtonStyle.left = tabButton.domNode.offsetWidth + "px";
74 tabButtonStyle.padding = "0px";
81 // Summary: Configure the content pane to take up all the space except for where the tabs are
82 if(!this.doLayout){ return; }
84 // position and size the titles and the container node
85 var titleAlign = this.tabPosition.replace(/-h/,"");
87 { domNode: this.tablist.domNode, layoutAlign: titleAlign },
88 { domNode: this.containerNode, layoutAlign: "client" }
90 dijit.layout.layoutChildren(this.domNode, this._contentBox, children);
92 // Compute size to make each of my children.
93 // children[1] is the margin-box size of this.containerNode, set by layoutChildren() call above
94 this._containerContentBox = dijit.layout.marginBox2contentBox(this.containerNode, children[1]);
96 if(this.selectedChildWidget){
97 this._showChild(this.selectedChildWidget);
98 if(this.doLayout && this.selectedChildWidget.resize){
99 this.selectedChildWidget.resize(this._containerContentBox);
106 this.tablist.destroy();
108 this.inherited(arguments);
112 //TODO: make private?
113 dojo.declare("dijit.layout.TabController",
114 dijit.layout.StackController,
117 // Set of tabs (the things with titles and a close button, that you click to show a tab panel).
119 // Lets the user select the currently shown pane in a TabContainer or StackContainer.
120 // TabController also monitors the TabContainer, and whenever a pane is
121 // added or deleted updates itself accordingly.
123 templateString: "<div wairole='tablist' dojoAttachEvent='onkeypress:onkeypress'></div>",
125 // tabPosition: String
126 // Defines where tabs go relative to the content.
127 // "top", "bottom", "left-h", "right-h"
131 // TODOC: deprecate doLayout? not sure.
134 // buttonWidget: String
135 // The name of the tab widget to create to correspond to each page
136 buttonWidget: "dijit.layout._TabButton",
138 postMixInProperties: function(){
139 this["class"] = "dijitTabLabels-" + this.tabPosition + (this.doLayout ? "" : " dijitTabNoLayout");
140 this.inherited(arguments);
143 //TODO: can this be accomplished in CSS?
144 _rectifyRtlTabList: function(){
145 //Summary: Rectify the length of all tabs in rtl, otherwise the tab lengths are different in IE
146 if(0 >= this.tabPosition.indexOf('-h')){ return; }
147 if(!this.pane2button){ return; }
150 for(var pane in this.pane2button){
151 maxLen = Math.max(maxLen, dojo.marginBox(this.pane2button[pane].innerDiv).w);
153 //unify the length of all the tabs
154 for(pane in this.pane2button){
155 this.pane2button[pane].innerDiv.style.width = maxLen + 'px';
160 dojo.declare("dijit.layout._TabButton",
161 dijit.layout._StackButton,
164 // A tab (the thing you click to select a pane).
166 // Contains the title of the pane, and optionally a close-button to destroy the pane.
167 // This is an internal widget and should not be instantiated directly.
169 baseClass: "dijitTab",
171 templateString:"<div waiRole=\"presentation\" dojoAttachEvent='onclick:onClick,onmouseenter:_onMouse,onmouseleave:_onMouse'>\n <div waiRole=\"presentation\" class='dijitTabInnerDiv' dojoAttachPoint='innerDiv'>\n <div waiRole=\"presentation\" class='dijitTabContent' dojoAttachPoint='tabContent'>\n\t <span dojoAttachPoint='containerNode,focusNode' class='tabLabel'>${!label}</span>\n\t <span dojoAttachPoint='closeButtonNode' class='closeImage' dojoAttachEvent='onmouseenter:_onMouse, onmouseleave:_onMouse, onclick:onClickCloseButton' stateModifier='CloseButton'>\n\t <span dojoAttachPoint='closeText' class='closeText'>x</span>\n\t </span>\n </div>\n </div>\n</div>\n",
173 postCreate: function(){
174 if(this.closeButton){
175 dojo.addClass(this.innerDiv, "dijitClosable");
177 this.closeButtonNode.style.display="none";
179 this.inherited(arguments);
180 dojo.setSelectable(this.containerNode, false);