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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
/*
Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
dojo._xdResourceLoaded(function(dojo, dijit, dojox){
return {depends: [["provide", "dojox.mobile.TabBar"],
["require", "dojox.mobile"]],
defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.mobile.TabBar"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.mobile.TabBar"] = true;
dojo.provide("dojox.mobile.TabBar");
dojo.require("dojox.mobile");
dojo.declare(
"dojox.mobile.TabBar",
dijit._WidgetBase,
{
iconBase: "",
iconPos: "",
barType: "tabBar", // "tabBar"(default) or "segmentedControl"
inHeading: false,
_fixedButtonWidth: 76,
_fixedButtonMargin: 17,
_largeScreenWidth: 500,
buildRendering: function(){
this._clsName = this.barType == "segmentedControl" ? "mblTabButton" : "mblTabBarButton";
this.domNode = this.containerNode = this.srcNodeRef || dojo.doc.createElement("H1");
this.domNode.className = this.barType == "segmentedControl" ? "mblTabPanelHeader" : "mblTabBar";
},
postCreate: function(){
if(dojo.global.onorientationchange !== undefined){
this.connect(dojo.global, "onorientationchange", "onResize");
}else{
this.connect(dojo.global, "onresize", "onResize");
}
},
startup: function(){
var _this = this;
setTimeout(function(){ // to get proper dimension
_this.onResize();
}, 0);
},
onResize: function(){
var i;
var w = dojo.marginBox(this.domNode.parentNode).w;
var bw = this._fixedButtonWidth;
var bm = this._fixedButtonMargin;
var children = this.containerNode.childNodes;
var arr = [];
for(i = 0; i < children.length; i++){
var c = children[i];
if(c.nodeType != 1){ continue; }
if(dojo.hasClass(c, this._clsName)){
arr.push(c);
}
}
var margin;
if(this.barType == "segmentedControl"){
margin = w;
var totalW = 0; // total width of all the buttons
for(i = 0; i < arr.length; i++){
margin -= dojo.marginBox(arr[i]).w;
arr[i].style.marginTop = "3px";
totalW += arr[i].offsetWidth;
}
margin = Math.floor(margin/2);
var parent = dijit.getEnclosingWidget(this.domNode.parentNode);
var inHeading = this.inHeading || parent instanceof dojox.mobile.Heading;
this.containerNode.style.padding = "3px 0px 0px " + (inHeading ? 0 : margin) + "px";
if(inHeading){
dojo.style(this.domNode, {
background: "none",
border: "none",
width: totalW + 2 + "px"
});
}
}else{
margin = Math.floor((w - (bw + bm * 2) * arr.length) / 2);
if(w < this._largeScreenWidth || margin < 0){
// If # of buttons is 4, for example, assign "25%" to each button.
// More precisely, 1%(left margin) + 98%(bar width) + 1%(right margin)
for(i = 0; i < arr.length; i++){
arr[i].style.width = Math.round(98/arr.length) + "%";
arr[i].style.margin = "0px";
}
this.containerNode.style.padding = "0px 0px 0px 1%";
}else{
// Fixed width buttons. Mainly for larger screen such as iPad.
for(i = 0; i < arr.length; i++){
arr[i].style.width = bw + "px";
arr[i].style.margin = "0 " + bm + "px";
}
this.containerNode.style.padding = "0px 0px 0px " + margin + "px";
}
}
}
});
dojo.declare(
"dojox.mobile.TabBarButton",
dojox.mobile.AbstractItem,
{
icon1: "", // unselected (dark) icon
icon2: "", // selected (highlight) icon
iconPos1: "", // unselected (dark) icon position
iconPos2: "", // selected (highlight) icon position
selected: false,
transition: "none",
tag: "LI",
selectOne: true,
inheritParams: function(){
var parent = this.getParentWidget();
this.parent = parent;
if(parent){
if(!this.transition){ this.transition = parent.transition; }
if(!this.icon1){ this.icon1 = parent.iconBase; }
if(!this.iconPos1){ this.iconPos1 = parent.iconPos; }
if(!this.icon2){ this.icon2 = parent.iconBase || this.icon1; }
if(!this.iconPos2){ this.iconPos2 = parent.iconPos || this.iconPos1; }
}
},
buildRendering: function(){
this.inheritParams();
this.anchorNode = dojo.create("A", {className:"mblTabBarButtonAnchor"});
var a = this.anchorNode;
this.connect(a, "onclick", "onClick");
var div = dojo.create("DIV", {className:"mblTabBarButtonDiv"}, a);
var divInner = dojo.create("DIV", {className:"mblTabBarButtonDiv mblTabBarButtonDivInner"}, div);
this.img1 = dojo.create("IMG", {className:"mblTabBarButtonIcon", src:this.icon1}, divInner);
this.img1.style.visibility = this.selected ? "hidden" : "";
dojox.mobile.setupIcon(this.img1, this.iconPos1);
this.img1.onload = function(){
// iPhone and Windows Safari sometimes fail to draw icon images.
// For some reason, this code solves the problem.
// Other browsers, including Chrome, do not have this problem.
this.style.width = this.width + "px";
this.style.height = this.height + "px";
};
this.img2 = dojo.create("IMG", {className:"mblTabBarButtonIcon", src:this.icon2}, divInner);
this.img2.style.visibility = this.selected ? "" : "hidden";
dojox.mobile.setupIcon(this.img2, this.iconPos2);
this.img2.onload = function(){
this.style.width = this.width + "px";
this.style.height = this.height + "px";
};
this.box = dojo.create("DIV", {className:"mblTabBarButtonTextBox"}, a);
var box = this.box;
var r = this.srcNodeRef;
if(r){
for(var i = 0, len = r.childNodes.length; i < len; i++){
box.appendChild(r.firstChild);
}
}
if(this.label){
box.appendChild(dojo.doc.createTextNode(this.label));
}
this.domNode = this.srcNodeRef || dojo.create(this.tag);
this.containerNode = this.domNode;
var _clsName = this.parent ? this.parent._clsName : "mblTabBarButton";
dojo.addClass(this.domNode, _clsName + (this.selected ? " mblTabButtonSelected" : ""));
this.domNode.appendChild(a);
this.createDomButton(this.domNode, a);
},
startup: function(){
var parent = this.getParentWidget();
this.parent = parent;
if(parent && parent.barType == "segmentedControl"){
// proper className may not be set when created dynamically
dojo.removeClass(this.domNode, "mblTabBarButton");
dojo.addClass(this.domNode, parent._clsName);
this.box.className = "";
}
},
select: function(deselect){
if(deselect){
this.selected = false;
dojo.removeClass(this.domNode, "mblTabButtonSelected");
}else{
this.selected = true;
dojo.addClass(this.domNode, "mblTabButtonSelected");
for(var i = 0, c = this.domNode.parentNode.childNodes; i < c.length; i++){
if(c[i].nodeType != 1){ continue; }
var w = dijit.byNode(c[i]); // sibling widget
if(w && w != this){
w.select(true);
}
}
}
this.img1.style.visibility = this.selected ? "hidden" : "";
this.img2.style.visibility = this.selected ? "" : "hidden";
},
onClick: function(e){
this.defaultClickAction();
}
});
}
}};});
|