source: Dev/branches/rest-dojo-ui/client/dijit/layout/_TabContainerBase.js @ 274

Last change on this file since 274 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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