source: Dev/trunk/src/client/dijit/layout/_TabContainerBase.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 4.7 KB
Line 
1define([
2        "dojo/text!./templates/TabContainer.html",
3        "./StackContainer",
4        "./utils", // marginBox2contextBox, layoutChildren
5        "../_TemplatedMixin",
6        "dojo/_base/declare", // declare
7        "dojo/dom-class", // domClass.add
8        "dojo/dom-geometry", // domGeometry.contentBox
9        "dojo/dom-style" // domStyle.style
10], function(template, StackContainer, layoutUtils, _TemplatedMixin, declare, domClass, domGeometry, domStyle){
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                startup: function(){
83                        if(this._started){
84                                return;
85                        }
86
87                        // wire up the tablist and its tabs
88                        this.tablist.startup();
89
90                        this.inherited(arguments);
91                },
92
93                layout: function(){
94                        // Overrides StackContainer.layout().
95                        // Configure the content pane to take up all the space except for where the tabs are
96
97                        if(!this._contentBox || typeof(this._contentBox.l) == "undefined"){
98                                return;
99                        }
100
101                        var sc = this.selectedChildWidget;
102
103                        if(this.doLayout){
104                                // position and size the titles and the container node
105                                var titleAlign = this.tabPosition.replace(/-h/, "");
106                                this.tablist.region = titleAlign;
107                                var children = [this.tablist, {
108                                        domNode: this.tablistSpacer,
109                                        region: titleAlign
110                                }, {
111                                        domNode: this.containerNode,
112                                        region: "center"
113                                }];
114                                layoutUtils.layoutChildren(this.domNode, this._contentBox, children);
115
116                                // Compute size to make each of my children.
117                                // children[2] is the margin-box size of this.containerNode, set by layoutChildren() call above
118                                this._containerContentBox = layoutUtils.marginBox2contentBox(this.containerNode, children[2]);
119
120                                if(sc && sc.resize){
121                                        sc.resize(this._containerContentBox);
122                                }
123                        }else{
124                                // just layout the tab controller, so it can position left/right buttons etc.
125                                if(this.tablist.resize){
126                                        //make the tabs zero width so that they don't interfere with width calc, then reset
127                                        var s = this.tablist.domNode.style;
128                                        s.width = "0";
129                                        var width = domGeometry.getContentBox(this.domNode).w;
130                                        s.width = "";
131                                        this.tablist.resize({w: width});
132                                }
133
134                                // and call resize() on the selected pane just to tell it that it's been made visible
135                                if(sc && sc.resize){
136                                        sc.resize();
137                                }
138                        }
139                },
140
141                destroy: function(preserveDom){
142                        if(this.tablist){
143                                this.tablist.destroy(preserveDom);
144                        }
145                        this.inherited(arguments);
146                }
147        });
148});
Note: See TracBrowser for help on using the repository browser.