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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
//>>built
define("dojox/mobile/ListItem", [
"dojo/_base/array",
"dojo/_base/connect",
"dojo/_base/declare",
"dojo/_base/lang",
"dojo/dom-class",
"dojo/dom-construct",
"dojo/has",
"./common",
"./_ItemBase",
"./TransitionEvent"
], function(array, connect, declare, lang, domClass, domConstruct, has, common, ItemBase, TransitionEvent){
/*=====
var ItemBase = dojox.mobile._ItemBase;
=====*/
// module:
// dojox/mobile/ListItem
// summary:
// An item of either RoundRectList or EdgeToEdgeList.
return declare("dojox.mobile.ListItem", ItemBase, {
// summary:
// An item of either RoundRectList or EdgeToEdgeList.
// description:
// ListItem represents an item of either RoundRectList or
// EdgeToEdgeList. There are three ways to move to a different
// view, moveTo, href, and url. You can choose only one of them.
// rightText: String
// A right-aligned text to display on the item.
rightText: "",
// rightIcon: String
// An icon to display at the right hand side of the item. The value
// can be either a path for an image file or a class name of a DOM
// button.
rightIcon: "",
// rightIcon2: String
// An icon to display at the left of the rightIcon. The value can
// be either a path for an image file or a class name of a DOM
// button.
rightIcon2: "",
// anchorLabel: Boolean
// If true, the label text becomes a clickable anchor text. When
// the user clicks on the text, the onAnchorLabelClicked handler is
// called. You can override or connect to the handler and implement
// any action. The handler has no default action.
anchorLabel: false,
// noArrow: Boolean
// If true, the right hand side arrow is not displayed.
noArrow: false,
// selected: Boolean
// If true, the item is highlighted to indicate it is selected.
selected: false,
// checked: Boolean
// If true, a check mark is displayed at the right of the item.
checked: false,
// arrowClass: String
// An icon to display as an arrow. The value can be either a path
// for an image file or a class name of a DOM button.
arrowClass: "mblDomButtonArrow",
// checkClass: String
// An icon to display as a check mark. The value can be either a
// path for an image file or a class name of a DOM button.
checkClass: "mblDomButtonCheck",
// variableHeight: Boolean
// If true, the height of the item varies according to its
// content. In dojo 1.6 or older, the "mblVariableHeight" class was
// used for this purpose. In dojo 1.7, adding the mblVariableHeight
// class still works for backward compatibility.
variableHeight: false,
// rightIconTitle: String
// An alt text for the right icon.
rightIconTitle: "",
// rightIcon2Title: String
// An alt text for the right icon2.
rightIcon2Title: "",
// btnClass: String
// Deprecated. For backward compatibility.
btnClass: "",
// btnClass2: String
// Deprecated. For backward compatibility.
btnClass2: "",
// tag: String
// A name of html tag to create as domNode.
tag: "li",
postMixInProperties: function(){
// for backward compatibility
if(this.btnClass){
this.rightIcon = this.btnClass;
}
this._setBtnClassAttr = this._setRightIconAttr;
this._setBtnClass2Attr = this._setRightIcon2Attr;
},
buildRendering: function(){
this.domNode = this.srcNodeRef || domConstruct.create(this.tag);
this.inherited(arguments);
this.domNode.className = "mblListItem" + (this.selected ? " mblItemSelected" : "");
// label
var box = this.box = domConstruct.create("DIV");
box.className = "mblListItemTextBox";
if(this.anchorLabel){
box.style.cursor = "pointer";
}
var r = this.srcNodeRef;
if(r && !this.label){
this.label = "";
for(var i = 0, len = r.childNodes.length; i < len; i++){
var n = r.firstChild;
if(n.nodeType === 3 && lang.trim(n.nodeValue) !== ""){
n.nodeValue = this._cv ? this._cv(n.nodeValue) : n.nodeValue;
this.labelNode = domConstruct.create("SPAN", {className:"mblListItemLabel"});
this.labelNode.appendChild(n);
n = this.labelNode;
}
box.appendChild(n);
}
}
if(!this.labelNode){
this.labelNode = domConstruct.create("SPAN", {className:"mblListItemLabel"}, box);
}
if(this.anchorLabel){
box.style.display = "inline"; // to narrow the text region
}
var a = this.anchorNode = domConstruct.create("A");
a.className = "mblListItemAnchor";
this.domNode.appendChild(a);
a.appendChild(box);
},
startup: function(){
if(this._started){ return; }
this.inheritParams();
var parent = this.getParent();
if(this.moveTo || this.href || this.url || this.clickable || (parent && parent.select)){
this._onClickHandle = this.connect(this.anchorNode, "onclick", "onClick");
}
this.setArrow();
if(domClass.contains(this.domNode, "mblVariableHeight")){
this.variableHeight = true;
}
if(this.variableHeight){
domClass.add(this.domNode, "mblVariableHeight");
setTimeout(lang.hitch(this, "layoutVariableHeight"));
}
this.set("icon", this.icon); // _setIconAttr may be called twice but this is necessary for offline instantiation
if(!this.checked && this.checkClass.indexOf(',') !== -1){
this.set("checked", this.checked);
}
this.inherited(arguments);
},
resize: function(){
if(this.variableHeight){
this.layoutVariableHeight();
}
},
onClick: function(e){
var a = e.currentTarget;
var li = a.parentNode;
if(domClass.contains(li, "mblItemSelected")){ return; } // already selected
if(this.anchorLabel){
for(var p = e.target; p.tagName !== this.tag.toUpperCase(); p = p.parentNode){
if(p.className == "mblListItemTextBox"){
domClass.add(p, "mblListItemTextBoxSelected");
setTimeout(function(){
domClass.remove(p, "mblListItemTextBoxSelected");
}, has("android") ? 300 : 1000);
this.onAnchorLabelClicked(e);
return;
}
}
}
var parent = this.getParent();
if(parent.select){
if(parent.select === "single"){
if(!this.checked){
this.set("checked", true);
}
}else if(parent.select === "multiple"){
this.set("checked", !this.checked);
}
}
this.select();
if (this.href && this.hrefTarget) {
common.openWindow(this.href, this.hrefTarget);
return;
}
var transOpts;
if(this.moveTo || this.href || this.url || this.scene){
transOpts = {moveTo: this.moveTo, href: this.href, url: this.url, scene: this.scene, transition: this.transition, transitionDir: this.transitionDir};
}else if(this.transitionOptions){
transOpts = this.transitionOptions;
}
if(transOpts){
this.setTransitionPos(e);
return new TransitionEvent(this.domNode,transOpts,e).dispatch();
}
},
select: function(){
// summary:
// Makes this widget in the selected state.
var parent = this.getParent();
if(parent.stateful){
parent.deselectAll();
}else{
var _this = this;
setTimeout(function(){
_this.deselect();
}, has("android") ? 300 : 1000);
}
domClass.add(this.domNode, "mblItemSelected");
},
deselect: function(){
// summary:
// Makes this widget in the deselected state.
domClass.remove(this.domNode, "mblItemSelected");
},
onAnchorLabelClicked: function(e){
// summary:
// Stub function to connect to from your application.
},
layoutVariableHeight: function(){
var h = this.anchorNode.offsetHeight;
if(h === this.anchorNodeHeight){ return; }
this.anchorNodeHeight = h;
array.forEach([
this.rightTextNode,
this.rightIcon2Node,
this.rightIconNode,
this.iconNode
], function(n){
if(n){
var t = Math.round((h - n.offsetHeight) / 2);
n.style.marginTop = t + "px";
}
});
},
setArrow: function(){
// summary:
// Sets the arrow icon if necessary.
if(this.checked){ return; }
var c = "";
var parent = this.getParent();
if(this.moveTo || this.href || this.url || this.clickable){
if(!this.noArrow && !(parent && parent.stateful)){
c = this.arrowClass;
}
}
if(c){
this._setRightIconAttr(c);
}
},
_setIconAttr: function(icon){
if(!this.getParent()){ return; } // icon may be invalid because inheritParams is not called yet
this.icon = icon;
var a = this.anchorNode;
if(!this.iconNode){
if(icon){
var ref = this.rightIconNode || this.rightIcon2Node || this.rightTextNode || this.box;
this.iconNode = domConstruct.create("DIV", {className:"mblListItemIcon"}, ref, "before");
}
}else{
domConstruct.empty(this.iconNode);
}
if(icon && icon !== "none"){
common.createIcon(icon, this.iconPos, null, this.alt, this.iconNode);
if(this.iconPos){
domClass.add(this.iconNode.firstChild, "mblListItemSpriteIcon");
}
domClass.remove(a, "mblListItemAnchorNoIcon");
}else{
domClass.add(a, "mblListItemAnchorNoIcon");
}
},
_setCheckedAttr: function(/*Boolean*/checked){
var parent = this.getParent();
if(parent && parent.select === "single" && checked){
array.forEach(parent.getChildren(), function(child){
child.set("checked", false);
});
}
this._setRightIconAttr(this.checkClass);
var icons = this.rightIconNode.childNodes;
if(icons.length === 1){
this.rightIconNode.style.display = checked ? "" : "none";
}else{
icons[0].style.display = checked ? "" : "none";
icons[1].style.display = !checked ? "" : "none";
}
domClass.toggle(this.domNode, "mblListItemChecked", checked);
if(parent && this.checked !== checked){
parent.onCheckStateChanged(this, checked);
}
this.checked = checked;
},
_setRightTextAttr: function(/*String*/text){
if(!this.rightTextNode){
this.rightTextNode = domConstruct.create("DIV", {className:"mblListItemRightText"}, this.box, "before");
}
this.rightText = text;
this.rightTextNode.innerHTML = this._cv ? this._cv(text) : text;
},
_setRightIconAttr: function(/*String*/icon){
if(!this.rightIconNode){
var ref = this.rightIcon2Node || this.rightTextNode || this.box;
this.rightIconNode = domConstruct.create("DIV", {className:"mblListItemRightIcon"}, ref, "before");
}else{
domConstruct.empty(this.rightIconNode);
}
this.rightIcon = icon;
var arr = (icon || "").split(/,/);
if(arr.length === 1){
common.createIcon(icon, null, null, this.rightIconTitle, this.rightIconNode);
}else{
common.createIcon(arr[0], null, null, this.rightIconTitle, this.rightIconNode);
common.createIcon(arr[1], null, null, this.rightIconTitle, this.rightIconNode);
}
},
_setRightIcon2Attr: function(/*String*/icon){
if(!this.rightIcon2Node){
var ref = this.rightTextNode || this.box;
this.rightIcon2Node = domConstruct.create("DIV", {className:"mblListItemRightIcon2"}, ref, "before");
}else{
domConstruct.empty(this.rightIcon2Node);
}
this.rightIcon2 = icon;
common.createIcon(icon, null, null, this.rightIcon2Title, this.rightIcon2Node);
},
_setLabelAttr: function(/*String*/text){
this.label = text;
this.labelNode.innerHTML = this._cv ? this._cv(text) : text;
}
});
});
|