TabSet_wev8.js
4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
Copyright (c) 2004-2005, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.widget.TabSet");
dojo.provide("dojo.widget.html.TabSet");
dojo.provide("dojo.widget.Tab");
dojo.provide("dojo.widget.html.Tab");
dojo.require("dojo.widget.*");
dojo.require("dojo.widget.LayoutPane");
dojo.require("dojo.event.*");
dojo.require("dojo.html");
dojo.require("dojo.style");
//////////////////////////////////////////
// TabSet -- a set of Tabs
//////////////////////////////////////////
dojo.widget.html.TabSet = function() {
dojo.widget.html.LayoutPane.call(this);
}
dojo.inherits(dojo.widget.html.TabSet, dojo.widget.html.LayoutPane);
dojo.lang.extend(dojo.widget.html.TabSet, {
// Constructor arguments
labelPosition: "top",
useVisibility: false, // true-->use visibility:hidden instead of display:none
widgetType: "TabSet",
templateCssPath: dojo.uri.dojoUri("src/widget/templates/HtmlTabSet_wev8.css"),
selectedTab: "", // currently selected tab's widgetId, later widget
fillInTemplate: function(args, frag) {
dojo.widget.html.TabSet.superclass.fillInTemplate.call(this, args, frag);
// TODO: prevent multiple includes of the same CSS file, when there are multiple
// TabSets on the same screen.
dojo.style.insertCssFile(this.templateCssPath);
dojo.html.prependClass(this.domNode, "dojoTabSet");
// Create panel to hold the tab labels (as a <ul> with special formatting)
// TODO: set "bottom" css tag if label is on bottom
this.filterAllowed('labelPosition', ['top', 'bottom']);
this.labelPanel = dojo.widget.fromScript("LayoutPane", {layoutAlign: this.labelPosition});
this.ul = document.createElement("ul");
dojo.html.addClass(this.ul, "tabs");
dojo.html.addClass(this.ul, this.labelPosition);
this.labelPanel.domNode.appendChild(this.ul);
this.addPane(this.labelPanel);
},
registerChild: function(child, insertionIndex){
// registerChild will be called for each tab, and also for the
// top pane (layoutAlign="top") that holds all the tab labels
dojo.widget.html.TabSet.superclass.registerChild.call(this, child, insertionIndex);
if ( child.widgetType == "Tab" ){
this.ul.appendChild(child.li);
if (this.selectedTab==child.widgetId || child.selected) {
this.onSelected(child);
} else {
child.hide();
}
}
},
onSelected: function(tab) {
// Deselect old tab and select new one
if (this.selectedTab && this.selectedTab.widgetId) {
this.selectedTab.hide();
}
this.selectedTab = tab; // becomes widget rather than string
tab.show();
},
onResized: function() {
// If none of the tabs were specified as selected, catch that here
// and just select the first one
if ( !this.selectedTab.widgetId ) {
this.onSelected(this.children[0]);
}
dojo.widget.html.TabSet.superclass.onResized.call(this);
}
});
dojo.widget.tags.addParseTreeHandler("dojo:TabSet");
//////////////////////////////////////////////////////
// Tab - a single tab
//////////////////////////////////////////////////////
dojo.widget.html.Tab = function() {
dojo.widget.html.LayoutPane.call(this);
}
dojo.inherits(dojo.widget.html.Tab, dojo.widget.html.LayoutPane);
dojo.lang.extend(dojo.widget.html.Tab, {
widgetType: "Tab",
label: "",
url: "inline",
handler: "none",
selected: false, // is this tab currently selected?
fillInTemplate: function(args, frag) {
this.layoutAlign = "client";
dojo.widget.html.Tab.superclass.fillInTemplate.call(this, args, frag);
dojo.html.prependClass(this.domNode, "dojoTabPanel");
// Create label
this.li = document.createElement("li");
var span = document.createElement("span");
span.innerHTML = this.label;
this.li.appendChild(span);
dojo.event.connect(this.li, "onclick", this, "onSelected");
},
onSelected: function() {
this.parent.onSelected(this);
},
show: function() {
dojo.html.addClass(this.li, "current");
this.selected=true;
if ( this.parent.useVisibility && !dojo.render.html.ie ) {
this.domNode.style.visibility="visible";
} else {
dojo.widget.html.Tab.superclass.show.call(this);
}
},
hide: function() {
dojo.html.removeClass(this.li, "current");
this.selected=false;
if( this.parent.useVisibility ){
this.domNode.style.visibility="hidden";
}else{
dojo.widget.html.Tab.superclass.hide.call(this);
}
}
});
dojo.widget.tags.addParseTreeHandler("dojo:Tab");