| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/dom-class", |
| 6 |
"dojo/dom-construct", |
| 7 |
"dojo/dom-style", |
| 8 |
"dojo/dom-attr", |
| 9 |
"dijit/registry", |
| 10 |
"dijit/_WidgetBase", |
| 11 |
"./iconUtils", |
| 12 |
"./_ItemBase", |
| 13 |
"./ProgressIndicator", |
| 14 |
"dojo/has", |
| 15 |
"dojo/has!dojo-bidi?dojox/mobile/bidi/ListItem" |
| 16 |
], function(array, declare, lang, domClass, domConstruct, domStyle, domAttr, registry, WidgetBase, iconUtils, ItemBase, ProgressIndicator, has, BidiListItem){ |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
var ListItem = declare(has("dojo-bidi") ? "dojox.mobile.NonBidiListItem" : "dojox.mobile.ListItem", ItemBase, { |
| 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 |
rightText: "", |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
rightIcon: "", |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
rightIcon2: "", |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
deleteIcon: "", |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
anchorLabel: false, |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
noArrow: false, |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
checked: false, |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
arrowClass: "", |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
checkClass: "", |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
uncheckClass: "", |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
variableHeight: false, |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
rightIconTitle: "", |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
rightIcon2Title: "", |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
header: false, |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
tag: "li", |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
busy: false, |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
progStyle: "", |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
layoutOnResize: false, |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
paramsToInherit: "variableHeight,transition,deleteIcon,icon,rightIcon,rightIcon2,uncheckIcon,arrowClass,checkClass,uncheckClass,deleteIconTitle,deleteIconRole", |
| 143 |
baseClass: "mblListItem", |
| 144 |
|
| 145 |
_selStartMethod: "touch", |
| 146 |
_selEndMethod: "timer", |
| 147 |
_delayedSelection: true, |
| 148 |
|
| 149 |
_selClass: "mblListItemSelected", |
| 150 |
|
| 151 |
buildRendering: function(){ |
| 152 |
this._templated = !!this.templateString; |
| 153 |
if(!this._templated){ |
| 154 |
|
| 155 |
this.domNode = this.containerNode = this.srcNodeRef || domConstruct.create(this.tag); |
| 156 |
} |
| 157 |
this.inherited(arguments); |
| 158 |
|
| 159 |
if(this.selected){ |
| 160 |
domClass.add(this.domNode, this._selClass); |
| 161 |
} |
| 162 |
if(this.header){ |
| 163 |
domClass.replace(this.domNode, "mblEdgeToEdgeCategory", this.baseClass); |
| 164 |
} |
| 165 |
|
| 166 |
if(!this._templated){ |
| 167 |
this.labelNode = |
| 168 |
domConstruct.create("div", {className:"mblListItemLabel"}); |
| 169 |
var ref = this.srcNodeRef; |
| 170 |
if(ref && ref.childNodes.length === 1 && ref.firstChild.nodeType === 3){ |
| 171 |
|
| 172 |
this.labelNode.appendChild(ref.firstChild); |
| 173 |
} |
| 174 |
this.domNode.appendChild(this.labelNode); |
| 175 |
} |
| 176 |
this._layoutChildren = []; |
| 177 |
}, |
| 178 |
|
| 179 |
startup: function(){ |
| 180 |
if(this._started){ return; } |
| 181 |
var parent = this.getParent(); |
| 182 |
var opts = this.getTransOpts(); |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
if((!this._templated || this.labelNode) && this.anchorLabel){ |
| 187 |
this.labelNode.style.display = "inline"; |
| 188 |
this.labelNode.style.cursor = "pointer"; |
| 189 |
this.connect(this.labelNode, "onclick", "_onClick"); |
| 190 |
this.onTouchStart = function(e){ |
| 191 |
return (e.target !== this.labelNode); |
| 192 |
}; |
| 193 |
} |
| 194 |
|
| 195 |
this.inherited(arguments); |
| 196 |
|
| 197 |
if(domClass.contains(this.domNode, "mblVariableHeight")){ |
| 198 |
this.variableHeight = true; |
| 199 |
} |
| 200 |
if(this.variableHeight){ |
| 201 |
domClass.add(this.domNode, "mblVariableHeight"); |
| 202 |
this.defer("layoutVariableHeight"); |
| 203 |
} |
| 204 |
|
| 205 |
if(!this._isOnLine){ |
| 206 |
this._isOnLine = true; |
| 207 |
this.set({ |
| 208 |
|
| 209 |
|
| 210 |
icon: this._pending_icon !== undefined ? this._pending_icon : this.icon, |
| 211 |
deleteIcon: this._pending_deleteIcon !== undefined ? this._pending_deleteIcon : this.deleteIcon, |
| 212 |
rightIcon: this._pending_rightIcon !== undefined ? this._pending_rightIcon : this.rightIcon, |
| 213 |
rightIcon2: this._pending_rightIcon2 !== undefined ? this._pending_rightIcon2 : this.rightIcon2, |
| 214 |
uncheckIcon: this._pending_uncheckIcon !== undefined ? this._pending_uncheckIcon : this.uncheckIcon |
| 215 |
}); |
| 216 |
|
| 217 |
delete this._pending_icon; |
| 218 |
delete this._pending_deleteIcon; |
| 219 |
delete this._pending_rightIcon; |
| 220 |
delete this._pending_rightIcon2; |
| 221 |
delete this._pending_uncheckIcon; |
| 222 |
} |
| 223 |
if(parent && parent.select){ |
| 224 |
|
| 225 |
|
| 226 |
this.set("checked", this._pendingChecked !== undefined ? this._pendingChecked : this.checked); |
| 227 |
domAttr.set(this.domNode, "role", "option"); |
| 228 |
if(this._pendingChecked || this.checked){ |
| 229 |
domAttr.set(this.domNode, "aria-selected", "true"); |
| 230 |
} |
| 231 |
|
| 232 |
delete this._pendingChecked; |
| 233 |
} |
| 234 |
this.setArrow(); |
| 235 |
this.layoutChildren(); |
| 236 |
}, |
| 237 |
|
| 238 |
_updateHandles: function(){ |
| 239 |
|
| 240 |
|
| 241 |
var parent = this.getParent(); |
| 242 |
var opts = this.getTransOpts(); |
| 243 |
if(opts.moveTo || opts.href || opts.url || this.clickable || (parent && parent.select)){ |
| 244 |
if(!this._keydownHandle){ |
| 245 |
this._keydownHandle = this.connect(this.domNode, "onkeydown", "_onClick"); |
| 246 |
} |
| 247 |
this._handleClick = true; |
| 248 |
}else{ |
| 249 |
if(this._keydownHandle){ |
| 250 |
this.disconnect(this._keydownHandle); |
| 251 |
this._keydownHandle = null; |
| 252 |
} |
| 253 |
this._handleClick = false; |
| 254 |
} |
| 255 |
this.inherited(arguments); |
| 256 |
}, |
| 257 |
|
| 258 |
layoutChildren: function(){ |
| 259 |
var centerNode; |
| 260 |
array.forEach(this.domNode.childNodes, function(n){ |
| 261 |
if(n.nodeType !== 1){ return; } |
| 262 |
var layout = n.getAttribute("layout") || |
| 263 |
n.getAttribute("data-mobile-layout") || |
| 264 |
(registry.byNode(n) || {}).layout; |
| 265 |
if(layout){ |
| 266 |
domClass.add(n, "mblListItemLayout" + |
| 267 |
layout.charAt(0).toUpperCase() + layout.substring(1)); |
| 268 |
this._layoutChildren.push(n); |
| 269 |
if(layout === "center"){ centerNode = n; } |
| 270 |
} |
| 271 |
}, this); |
| 272 |
if(centerNode){ |
| 273 |
this.domNode.insertBefore(centerNode, this.domNode.firstChild); |
| 274 |
} |
| 275 |
}, |
| 276 |
|
| 277 |
resize: function(){ |
| 278 |
if(this.layoutOnResize && this.variableHeight){ |
| 279 |
this.layoutVariableHeight(); |
| 280 |
} |
| 281 |
|
| 282 |
if(!this._templated || this.labelNode){ |
| 283 |
|
| 284 |
this.labelNode.style.display = this.labelNode.firstChild ? "block" : "inline"; |
| 285 |
} |
| 286 |
}, |
| 287 |
|
| 288 |
_onTouchStart: function(e){ |
| 289 |
|
| 290 |
|
| 291 |
if(e.target.getAttribute("preventTouch") || |
| 292 |
e.target.getAttribute("data-mobile-prevent-touch") || |
| 293 |
(registry.getEnclosingWidget(e.target) || {}).preventTouch){ |
| 294 |
return; |
| 295 |
} |
| 296 |
this.inherited(arguments); |
| 297 |
}, |
| 298 |
|
| 299 |
_onClick: function(e){ |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
if(this.getParent().isEditing || e && e.type === "keydown" && e.keyCode !== 13){ return; } |
| 305 |
if(this.onClick(e) === false){ return; } |
| 306 |
var n = this.labelNode; |
| 307 |
|
| 308 |
if((this._templated || n) && this.anchorLabel && e.currentTarget === n){ |
| 309 |
domClass.add(n, "mblListItemLabelSelected"); |
| 310 |
this.defer(function(){ |
| 311 |
domClass.remove(n, "mblListItemLabelSelected"); |
| 312 |
}, this._duration); |
| 313 |
this.onAnchorLabelClicked(e); |
| 314 |
return; |
| 315 |
} |
| 316 |
var parent = this.getParent(); |
| 317 |
if(parent.select){ |
| 318 |
if(parent.select === "single"){ |
| 319 |
if(!this.checked){ |
| 320 |
this.set("checked", true); |
| 321 |
} |
| 322 |
}else if(parent.select === "multiple"){ |
| 323 |
this.set("checked", !this.checked); |
| 324 |
} |
| 325 |
} |
| 326 |
this.defaultClickAction(e); |
| 327 |
}, |
| 328 |
|
| 329 |
onClick: function( ){ |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
}, |
| 335 |
|
| 336 |
onAnchorLabelClicked: function(e){ |
| 337 |
|
| 338 |
|
| 339 |
}, |
| 340 |
|
| 341 |
layoutVariableHeight: function(){ |
| 342 |
|
| 343 |
|
| 344 |
var h = this.domNode.offsetHeight; |
| 345 |
if(h === this.domNodeHeight){ return; } |
| 346 |
this.domNodeHeight = h; |
| 347 |
array.forEach(this._layoutChildren.concat([ |
| 348 |
this.rightTextNode, |
| 349 |
this.rightIcon2Node, |
| 350 |
this.rightIconNode, |
| 351 |
this.uncheckIconNode, |
| 352 |
this.iconNode, |
| 353 |
this.deleteIconNode, |
| 354 |
this.knobIconNode |
| 355 |
]), function(n){ |
| 356 |
if(n){ |
| 357 |
var domNode = this.domNode; |
| 358 |
var f = function(){ |
| 359 |
var t = Math.round((domNode.offsetHeight - n.offsetHeight) / 2) - |
| 360 |
domStyle.get(domNode, "paddingTop"); |
| 361 |
n.style.marginTop = t + "px"; |
| 362 |
}; |
| 363 |
if(n.offsetHeight === 0 && n.tagName === "IMG"){ |
| 364 |
n.onload = f; |
| 365 |
}else{ |
| 366 |
f(); |
| 367 |
} |
| 368 |
} |
| 369 |
}, this); |
| 370 |
}, |
| 371 |
|
| 372 |
setArrow: function(){ |
| 373 |
|
| 374 |
|
| 375 |
if(this.checked){ return; } |
| 376 |
var c = ""; |
| 377 |
var parent = this.getParent(); |
| 378 |
var opts = this.getTransOpts(); |
| 379 |
if(opts.moveTo || opts.href || opts.url || this.clickable){ |
| 380 |
if(!this.noArrow && !(parent && parent.selectOne)){ |
| 381 |
c = this.arrowClass || "mblDomButtonArrow"; |
| 382 |
domAttr.set(this.domNode, "role", "button"); |
| 383 |
} |
| 384 |
} |
| 385 |
if(c){ |
| 386 |
this._setRightIconAttr(c); |
| 387 |
} |
| 388 |
}, |
| 389 |
|
| 390 |
_findRef: function(type){ |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
var i, node, list = ["deleteIcon", "icon", "rightIcon", "uncheckIcon", "rightIcon2", "rightText"]; |
| 396 |
for(i = array.indexOf(list, type) + 1; i < list.length; i++){ |
| 397 |
node = this[list[i] + "Node"]; |
| 398 |
if(node){ return node; } |
| 399 |
} |
| 400 |
for(i = list.length - 1; i >= 0; i--){ |
| 401 |
node = this[list[i] + "Node"]; |
| 402 |
if(node){ return node.nextSibling; } |
| 403 |
} |
| 404 |
return this.domNode.firstChild; |
| 405 |
}, |
| 406 |
|
| 407 |
_setIcon: function(icon, type){ |
| 408 |
|
| 409 |
|
| 410 |
if(!this._isOnLine){ |
| 411 |
|
| 412 |
this["_pending_" + type] = icon; |
| 413 |
return; |
| 414 |
} |
| 415 |
this._set(type, icon); |
| 416 |
this[type + "Node"] = iconUtils.setIcon(icon, this[type + "Pos"], |
| 417 |
this[type + "Node"], this[type + "Title"] || this.alt, this.domNode, this._findRef(type), "before"); |
| 418 |
if(this[type + "Node"]){ |
| 419 |
var cap = type.charAt(0).toUpperCase() + type.substring(1); |
| 420 |
domClass.add(this[type + "Node"], "mblListItem" + cap); |
| 421 |
} |
| 422 |
var role = this[type + "Role"]; |
| 423 |
if(role){ |
| 424 |
this[type + "Node"].setAttribute("role", role); |
| 425 |
} |
| 426 |
}, |
| 427 |
|
| 428 |
_setDeleteIconAttr: function(icon){ |
| 429 |
|
| 430 |
|
| 431 |
this._setIcon(icon, "deleteIcon"); |
| 432 |
}, |
| 433 |
|
| 434 |
_setIconAttr: function(icon){ |
| 435 |
|
| 436 |
|
| 437 |
this._setIcon(icon, "icon"); |
| 438 |
}, |
| 439 |
|
| 440 |
_setRightTextAttr: function(text){ |
| 441 |
|
| 442 |
|
| 443 |
if(!this._templated && !this.rightTextNode){ |
| 444 |
|
| 445 |
this.rightTextNode = domConstruct.create("div", {className:"mblListItemRightText"}, this.labelNode, "before"); |
| 446 |
} |
| 447 |
this.rightText = text; |
| 448 |
this.rightTextNode.innerHTML = this._cv ? this._cv(text) : text; |
| 449 |
}, |
| 450 |
|
| 451 |
_setRightIconAttr: function(icon){ |
| 452 |
|
| 453 |
|
| 454 |
this._setIcon(icon, "rightIcon"); |
| 455 |
}, |
| 456 |
|
| 457 |
_setUncheckIconAttr: function(icon){ |
| 458 |
|
| 459 |
|
| 460 |
this._setIcon(icon, "uncheckIcon"); |
| 461 |
}, |
| 462 |
|
| 463 |
_setRightIcon2Attr: function(icon){ |
| 464 |
|
| 465 |
|
| 466 |
this._setIcon(icon, "rightIcon2"); |
| 467 |
}, |
| 468 |
|
| 469 |
_setCheckedAttr: function(checked){ |
| 470 |
|
| 471 |
|
| 472 |
if(!this._isOnLine){ |
| 473 |
|
| 474 |
this._pendingChecked = checked; |
| 475 |
return; |
| 476 |
} |
| 477 |
var parent = this.getParent(); |
| 478 |
if(parent && parent.select === "single" && checked){ |
| 479 |
array.forEach(parent.getChildren(), function(child){ |
| 480 |
child !== this && child.checked && child.set("checked", false) && domAttr.set(child.domNode, "aria-selected", "false"); |
| 481 |
}, this); |
| 482 |
} |
| 483 |
this._setRightIconAttr(this.checkClass || "mblDomButtonCheck"); |
| 484 |
this._setUncheckIconAttr(this.uncheckClass); |
| 485 |
|
| 486 |
domClass.toggle(this.domNode, "mblListItemChecked", checked); |
| 487 |
domClass.toggle(this.domNode, "mblListItemUnchecked", !checked); |
| 488 |
domClass.toggle(this.domNode, "mblListItemHasUncheck", !!this.uncheckIconNode); |
| 489 |
this.rightIconNode.style.position = (this.uncheckIconNode && !checked) ? "absolute" : ""; |
| 490 |
|
| 491 |
if(parent && this.checked !== checked){ |
| 492 |
parent.onCheckStateChanged(this, checked); |
| 493 |
} |
| 494 |
this._set("checked", checked); |
| 495 |
domAttr.set(this.domNode, "aria-selected", checked ? "true" : "false"); |
| 496 |
}, |
| 497 |
|
| 498 |
_setBusyAttr: function(busy){ |
| 499 |
|
| 500 |
|
| 501 |
var prog = this._prog; |
| 502 |
if(busy){ |
| 503 |
if(!this._progNode){ |
| 504 |
this._progNode = domConstruct.create("div", {className:"mblListItemIcon"}); |
| 505 |
prog = this._prog = new ProgressIndicator({size:25, center:false, removeOnStop:false}); |
| 506 |
domClass.add(prog.domNode, this.progStyle); |
| 507 |
this._progNode.appendChild(prog.domNode); |
| 508 |
} |
| 509 |
if(this.iconNode){ |
| 510 |
this.domNode.replaceChild(this._progNode, this.iconNode); |
| 511 |
}else{ |
| 512 |
domConstruct.place(this._progNode, this._findRef("icon"), "before"); |
| 513 |
} |
| 514 |
prog.start(); |
| 515 |
}else if(this._progNode){ |
| 516 |
if(this.iconNode){ |
| 517 |
this.domNode.replaceChild(this.iconNode, this._progNode); |
| 518 |
}else{ |
| 519 |
this.domNode.removeChild(this._progNode); |
| 520 |
} |
| 521 |
prog.stop(); |
| 522 |
} |
| 523 |
this._set("busy", busy); |
| 524 |
}, |
| 525 |
|
| 526 |
_setSelectedAttr: function(selected){ |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
this.inherited(arguments); |
| 532 |
domClass.toggle(this.domNode, this._selClass, selected); |
| 533 |
}, |
| 534 |
|
| 535 |
_setClickableAttr: function(clickable){ |
| 536 |
|
| 537 |
|
| 538 |
this._set("clickable", clickable); |
| 539 |
this._updateHandles(); |
| 540 |
}, |
| 541 |
|
| 542 |
_setMoveToAttr: function(moveTo){ |
| 543 |
|
| 544 |
|
| 545 |
this._set("moveTo", moveTo); |
| 546 |
this._updateHandles(); |
| 547 |
}, |
| 548 |
|
| 549 |
_setHrefAttr: function(href){ |
| 550 |
|
| 551 |
|
| 552 |
this._set("href", href); |
| 553 |
this._updateHandles(); |
| 554 |
}, |
| 555 |
|
| 556 |
_setUrlAttr: function(url){ |
| 557 |
|
| 558 |
|
| 559 |
this._set("url", url); |
| 560 |
this._updateHandles(); |
| 561 |
} |
| 562 |
}); |
| 563 |
|
| 564 |
ListItem.ChildWidgetProperties = { |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
layout: "", |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
preventTouch: false |
| 575 |
}; |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
lang.extend(WidgetBase, ListItem.ChildWidgetProperties); |
| 581 |
|
| 582 |
return has("dojo-bidi") ? declare("dojox.mobile.ListItem", [ListItem, BidiListItem]) : ListItem; |
| 583 |
}); |