source: Dev/branches/rest-dojo-ui/client/dijit/layout/TabController.js @ 256

Last change on this file since 256 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: 5.0 KB
Line 
1define([
2        "dojo/_base/declare", // declare
3        "dojo/dom", // dom.setSelectable
4        "dojo/dom-attr", // domAttr.attr
5        "dojo/dom-class", // domClass.toggle
6        "dojo/i18n", // i18n.getLocalization
7        "dojo/_base/lang", // lang.hitch lang.trim
8        "./StackController",
9        "../Menu",
10        "../MenuItem",
11        "dojo/text!./templates/_TabButton.html",
12        "dojo/i18n!../nls/common"
13], function(declare, dom, domAttr, domClass, i18n, lang, StackController, Menu, MenuItem, template){
14
15/*=====
16        var StackController = dijit.layout.StackController;
17        var Menu = dijit.Menu;
18        var MenuItem = dijit.MenuItem;
19=====*/
20
21        // module:
22        //              dijit/layout/TabController
23        // summary:
24        //              Set of tabs (the things with titles and a close button, that you click to show a tab panel).
25        //              Used internally by `dijit.layout.TabContainer`.
26
27        var TabButton = declare("dijit.layout._TabButton", StackController.StackButton, {
28                // summary:
29                //              A tab (the thing you click to select a pane).
30                // description:
31                //              Contains the title of the pane, and optionally a close-button to destroy the pane.
32                //              This is an internal widget and should not be instantiated directly.
33                // tags:
34                //              private
35
36                // baseClass: String
37                //              The CSS class applied to the domNode.
38                baseClass: "dijitTab",
39
40                // Apply dijitTabCloseButtonHover when close button is hovered
41                cssStateNodes: {
42                        closeNode: "dijitTabCloseButton"
43                },
44
45                templateString: template,
46
47                // Override _FormWidget.scrollOnFocus.
48                // Don't scroll the whole tab container into view when the button is focused.
49                scrollOnFocus: false,
50
51                buildRendering: function(){
52                        this.inherited(arguments);
53
54                        dom.setSelectable(this.containerNode, false);
55                },
56
57                startup: function(){
58                        this.inherited(arguments);
59                        var n = this.domNode;
60
61                        // Required to give IE6 a kick, as it initially hides the
62                        // tabs until they are focused on.
63                        setTimeout(function(){
64                                n.className = n.className;
65                        }, 1);
66                },
67
68                _setCloseButtonAttr: function(/*Boolean*/ disp){
69                        // summary:
70                        //              Hide/show close button
71                        this._set("closeButton", disp);
72                        domClass.toggle(this.innerDiv, "dijitClosable", disp);
73                        this.closeNode.style.display = disp ? "" : "none";
74                        if(disp){
75                                var _nlsResources = i18n.getLocalization("dijit", "common");
76                                if(this.closeNode){
77                                        domAttr.set(this.closeNode,"title", _nlsResources.itemClose);
78                                }
79                                // add context menu onto title button
80                                this._closeMenu = new Menu({
81                                        id: this.id+"_Menu",
82                                        dir: this.dir,
83                                        lang: this.lang,
84                                        textDir: this.textDir,
85                                        targetNodeIds: [this.domNode]
86                                });
87
88                                this._closeMenu.addChild(new MenuItem({
89                                        label: _nlsResources.itemClose,
90                                        dir: this.dir,
91                                        lang: this.lang,
92                                        textDir: this.textDir,
93                                        onClick: lang.hitch(this, "onClickCloseButton")
94                                }));
95                        }else{
96                                if(this._closeMenu){
97                                        this._closeMenu.destroyRecursive();
98                                        delete this._closeMenu;
99                                }
100                        }
101                },
102                _setLabelAttr: function(/*String*/ content){
103                        // summary:
104                        //              Hook for set('label', ...) to work.
105                        // description:
106                        //              takes an HTML string.
107                        //              Inherited ToggleButton implementation will Set the label (text) of the button;
108                        //              Need to set the alt attribute of icon on tab buttons if no label displayed
109                        this.inherited(arguments);
110                        if(!this.showLabel && !this.params.title){
111                                this.iconNode.alt = lang.trim(this.containerNode.innerText || this.containerNode.textContent || '');
112                        }
113                },
114
115                destroy: function(){
116                        if(this._closeMenu){
117                                this._closeMenu.destroyRecursive();
118                                delete this._closeMenu;
119                        }
120                        this.inherited(arguments);
121                }
122        });
123
124        var TabController = declare("dijit.layout.TabController", StackController, {
125                // summary:
126                //              Set of tabs (the things with titles and a close button, that you click to show a tab panel).
127                //              Used internally by `dijit.layout.TabContainer`.
128                // description:
129                //              Lets the user select the currently shown pane in a TabContainer or StackContainer.
130                //              TabController also monitors the TabContainer, and whenever a pane is
131                //              added or deleted updates itself accordingly.
132                // tags:
133                //              private
134
135                baseClass: "dijitTabController",
136
137                templateString: "<div role='tablist' data-dojo-attach-event='onkeypress:onkeypress'></div>",
138
139                // tabPosition: String
140                //              Defines where tabs go relative to the content.
141                //              "top", "bottom", "left-h", "right-h"
142                tabPosition: "top",
143
144                // buttonWidget: Constructor
145                //              The tab widget to create to correspond to each page
146                buttonWidget: TabButton,
147
148                _rectifyRtlTabList: function(){
149                        // summary:
150                        //              For left/right TabContainer when page is RTL mode, rectify the width of all tabs to be equal, otherwise the tab widths are different in IE
151
152                        if(0 >= this.tabPosition.indexOf('-h')){ return; }
153                        if(!this.pane2button){ return; }
154
155                        var maxWidth = 0;
156                        for(var pane in this.pane2button){
157                                var ow = this.pane2button[pane].innerDiv.scrollWidth;
158                                maxWidth = Math.max(maxWidth, ow);
159                        }
160                        //unify the length of all the tabs
161                        for(pane in this.pane2button){
162                                this.pane2button[pane].innerDiv.style.width = maxWidth + 'px';
163                        }
164                }
165        });
166
167        TabController.TabButton = TabButton;    // for monkey patching
168
169        return TabController;
170});
Note: See TracBrowser for help on using the repository browser.