Debian Codegraph @

dijit/layout/_TabContainerBase.js

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