| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/sniff", |
| 6 |
"dojo/dom-class", |
| 7 |
"dojo/dom-construct", |
| 8 |
"dojo/dom-attr", |
| 9 |
"dijit/_Contained", |
| 10 |
"dijit/_Container", |
| 11 |
"dijit/_WidgetBase", |
| 12 |
"./iconUtils", |
| 13 |
"./lazyLoadUtils", |
| 14 |
"./_css3", |
| 15 |
"./common", |
| 16 |
"require", |
| 17 |
"dojo/has!dojo-bidi?dojox/mobile/bidi/Accordion" |
| 18 |
], function(array, declare, lang, has, domClass, domConstruct, domAttr, Contained, Container, WidgetBase, iconUtils, lazyLoadUtils, css3, common, require, BidiAccordion){ |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
var _AccordionTitle = declare([WidgetBase, Contained], { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
label: "Label", |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
icon1: "", |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
icon2: "", |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
iconPos1: "", |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
iconPos2: "", |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
selected: false, |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
baseClass: "mblAccordionTitle", |
| 65 |
|
| 66 |
buildRendering: function(){ |
| 67 |
this.inherited(arguments); |
| 68 |
|
| 69 |
var a = this.anchorNode = domConstruct.create("a", { |
| 70 |
className: "mblAccordionTitleAnchor", |
| 71 |
role: "presentation" |
| 72 |
}, this.domNode); |
| 73 |
|
| 74 |
|
| 75 |
this.textBoxNode = domConstruct.create("div", {className:"mblAccordionTitleTextBox"}, a); |
| 76 |
this.labelNode = domConstruct.create("span", { |
| 77 |
className: "mblAccordionTitleLabel", |
| 78 |
innerHTML: this._cv ? this._cv(this.label) : this.label |
| 79 |
}, this.textBoxNode); |
| 80 |
this._isOnLine = this.inheritParams(); |
| 81 |
|
| 82 |
domAttr.set(this.textBoxNode, "role", "tab"); |
| 83 |
domAttr.set(this.textBoxNode, "tabindex", "0"); |
| 84 |
}, |
| 85 |
|
| 86 |
postCreate: function(){ |
| 87 |
this.connect(this.domNode, "onclick", "_onClick"); |
| 88 |
common.setSelectable(this.domNode, false); |
| 89 |
}, |
| 90 |
|
| 91 |
inheritParams: function(){ |
| 92 |
var parent = this.getParent(); |
| 93 |
if(parent){ |
| 94 |
if(this.icon1 && parent.iconBase && |
| 95 |
parent.iconBase.charAt(parent.iconBase.length - 1) === '/'){ |
| 96 |
this.icon1 = parent.iconBase + this.icon1; |
| 97 |
} |
| 98 |
if(!this.icon1){ this.icon1 = parent.iconBase; } |
| 99 |
if(!this.iconPos1){ this.iconPos1 = parent.iconPos; } |
| 100 |
if(this.icon2 && parent.iconBase && |
| 101 |
parent.iconBase.charAt(parent.iconBase.length - 1) === '/'){ |
| 102 |
this.icon2 = parent.iconBase + this.icon2; |
| 103 |
} |
| 104 |
if(!this.icon2){ this.icon2 = parent.iconBase || this.icon1; } |
| 105 |
if(!this.iconPos2){ this.iconPos2 = parent.iconPos || this.iconPos1; } |
| 106 |
} |
| 107 |
return !!parent; |
| 108 |
}, |
| 109 |
|
| 110 |
_setIcon: function(icon, n){ |
| 111 |
|
| 112 |
|
| 113 |
if(!this.getParent()){ return; } |
| 114 |
this._set("icon" + n, icon); |
| 115 |
if(!this["iconParentNode" + n]){ |
| 116 |
this["iconParentNode" + n] = domConstruct.create("div", |
| 117 |
{className:"mblAccordionIconParent mblAccordionIconParent" + n}, this.anchorNode, "first"); |
| 118 |
} |
| 119 |
this["iconNode" + n] = iconUtils.setIcon(icon, this["iconPos" + n], |
| 120 |
this["iconNode" + n], this.alt, this["iconParentNode" + n]); |
| 121 |
this["icon" + n] = icon; |
| 122 |
domClass.toggle(this.domNode, "mblAccordionHasIcon", icon && icon !== "none"); |
| 123 |
if(has("dojo-bidi") && !this.getParent().isLeftToRight()){ |
| 124 |
this.getParent()._setIconDir(this["iconParentNode" + n]); |
| 125 |
} |
| 126 |
}, |
| 127 |
|
| 128 |
_setIcon1Attr: function(icon){ |
| 129 |
|
| 130 |
|
| 131 |
this._setIcon(icon, 1); |
| 132 |
}, |
| 133 |
|
| 134 |
_setIcon2Attr: function(icon){ |
| 135 |
|
| 136 |
|
| 137 |
this._setIcon(icon, 2); |
| 138 |
}, |
| 139 |
|
| 140 |
startup: function(){ |
| 141 |
if(this._started){ return; } |
| 142 |
if(!this._isOnLine){ |
| 143 |
this.inheritParams(); |
| 144 |
} |
| 145 |
if(!this._isOnLine){ |
| 146 |
this.set({ |
| 147 |
icon1: this.icon1, |
| 148 |
icon2: this.icon2 |
| 149 |
}); |
| 150 |
} |
| 151 |
this.inherited(arguments); |
| 152 |
}, |
| 153 |
|
| 154 |
_onClick: function(e){ |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
if(this.onClick(e) === false){ return; } |
| 160 |
var p = this.getParent(); |
| 161 |
if(!p.fixedHeight && this.contentWidget.domNode.style.display !== "none"){ |
| 162 |
p.collapse(this.contentWidget, !p.animation); |
| 163 |
}else{ |
| 164 |
p.expand(this.contentWidget, !p.animation); |
| 165 |
} |
| 166 |
}, |
| 167 |
|
| 168 |
onClick: function( ){ |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
}, |
| 174 |
|
| 175 |
_setSelectedAttr: function(selected){ |
| 176 |
|
| 177 |
|
| 178 |
domClass.toggle(this.domNode, "mblAccordionTitleSelected", selected); |
| 179 |
this._set("selected", selected); |
| 180 |
} |
| 181 |
}); |
| 182 |
|
| 183 |
var Accordion = declare(has("dojo-bidi") ? "dojox.mobile.NonBidiAccordion" : "dojox.mobile.Accordion", [WidgetBase, Container, Contained], { |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
iconBase: "", |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
iconPos: "", |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
fixedHeight: false, |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
singleOpen: false, |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
animation: true, |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
roundRect: false, |
| 221 |
|
| 222 |
|
| 223 |
duration: .3, |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
baseClass: "mblAccordion", |
| 228 |
|
| 229 |
|
| 230 |
_openSpace: 1, |
| 231 |
|
| 232 |
buildRendering: function(){ |
| 233 |
this.inherited(arguments); |
| 234 |
domAttr.set(this.domNode, "role", "tablist"); |
| 235 |
domAttr.set(this.domNode, "aria-multiselectable", !this.singleOpen); |
| 236 |
}, |
| 237 |
|
| 238 |
startup: function(){ |
| 239 |
if(this._started){ return; } |
| 240 |
|
| 241 |
if(domClass.contains(this.domNode, "mblAccordionRoundRect")){ |
| 242 |
this.roundRect = true; |
| 243 |
}else if(this.roundRect){ |
| 244 |
domClass.add(this.domNode, "mblAccordionRoundRect"); |
| 245 |
} |
| 246 |
|
| 247 |
if(this.fixedHeight){ |
| 248 |
this.singleOpen = true; |
| 249 |
} |
| 250 |
var children = this.getChildren(); |
| 251 |
array.forEach(children, this._setupChild, this); |
| 252 |
var sel; |
| 253 |
var posinset = 1; |
| 254 |
array.forEach(children, function(child){ |
| 255 |
child.startup(); |
| 256 |
child._at.startup(); |
| 257 |
this.collapse(child, true); |
| 258 |
domAttr.set(child._at.textBoxNode, "aria-setsize", children.length); |
| 259 |
domAttr.set(child._at.textBoxNode, "aria-posinset", posinset++); |
| 260 |
if(child.selected){ |
| 261 |
sel = child; |
| 262 |
} |
| 263 |
}, this); |
| 264 |
if(!sel && this.fixedHeight){ |
| 265 |
sel = children[children.length - 1]; |
| 266 |
} |
| 267 |
if(sel){ |
| 268 |
this.expand(sel, true); |
| 269 |
}else{ |
| 270 |
this._updateLast(); |
| 271 |
} |
| 272 |
this.defer(function(){ this.resize(); }); |
| 273 |
|
| 274 |
this._started = true; |
| 275 |
}, |
| 276 |
|
| 277 |
_setupChild: function( child){ |
| 278 |
|
| 279 |
|
| 280 |
if(child.domNode.style.overflow != "hidden"){ |
| 281 |
child.domNode.style.overflow = this.fixedHeight ? "auto" : "hidden"; |
| 282 |
} |
| 283 |
child._at = new _AccordionTitle({ |
| 284 |
label: child.label, |
| 285 |
alt: child.alt, |
| 286 |
icon1: child.icon1, |
| 287 |
icon2: child.icon2, |
| 288 |
iconPos1: child.iconPos1, |
| 289 |
iconPos2: child.iconPos2, |
| 290 |
contentWidget: child |
| 291 |
}); |
| 292 |
domConstruct.place(child._at.domNode, child.domNode, "before"); |
| 293 |
domClass.add(child.domNode, "mblAccordionPane"); |
| 294 |
domAttr.set(child._at.textBoxNode, "aria-controls", child.domNode.id); |
| 295 |
domAttr.set(child.domNode, "role", "tabpanel"); |
| 296 |
domAttr.set(child.domNode, "aria-labelledby", child._at.id); |
| 297 |
}, |
| 298 |
|
| 299 |
addChild: function( widget, insertIndex){ |
| 300 |
this.inherited(arguments); |
| 301 |
if(this._started){ |
| 302 |
this._setupChild(widget); |
| 303 |
widget._at.startup(); |
| 304 |
if(widget.selected){ |
| 305 |
this.expand(widget, true); |
| 306 |
this.defer(function(){ |
| 307 |
widget.domNode.style.height = ""; |
| 308 |
}); |
| 309 |
}else{ |
| 310 |
this.collapse(widget); |
| 311 |
} |
| 312 |
this._addChildAriaAttrs(); |
| 313 |
} |
| 314 |
}, |
| 315 |
|
| 316 |
removeChild: function( widget){ |
| 317 |
if(typeof widget == "number"){ |
| 318 |
widget = this.getChildren()[widget]; |
| 319 |
} |
| 320 |
if(widget){ |
| 321 |
widget._at.destroy(); |
| 322 |
} |
| 323 |
this.inherited(arguments); |
| 324 |
this._addChildAriaAttrs(); |
| 325 |
}, |
| 326 |
|
| 327 |
_addChildAriaAttrs: function(){ |
| 328 |
var posinset = 1; |
| 329 |
var children = this.getChildren(); |
| 330 |
array.forEach(children, function(child){ |
| 331 |
domAttr.set(child._at.textBoxNode, "aria-posinset", posinset++); |
| 332 |
domAttr.set(child._at.textBoxNode, "aria-setsize", children.length); |
| 333 |
}); |
| 334 |
}, |
| 335 |
|
| 336 |
getChildren: function(){ |
| 337 |
return array.filter(this.inherited(arguments), function(child){ |
| 338 |
return !(child instanceof _AccordionTitle); |
| 339 |
}); |
| 340 |
}, |
| 341 |
|
| 342 |
getSelectedPanes: function(){ |
| 343 |
return array.filter(this.getChildren(), function(pane){ |
| 344 |
return pane.domNode.style.display != "none"; |
| 345 |
}); |
| 346 |
}, |
| 347 |
|
| 348 |
resize: function(){ |
| 349 |
if(this.fixedHeight){ |
| 350 |
var panes = array.filter(this.getChildren(), function(child){ |
| 351 |
return child._at.domNode.style.display != "none"; |
| 352 |
}); |
| 353 |
var openSpace = this.domNode.clientHeight; |
| 354 |
array.forEach(panes, function(child){ |
| 355 |
openSpace -= child._at.domNode.offsetHeight; |
| 356 |
}); |
| 357 |
this._openSpace = openSpace > 0 ? openSpace : 0; |
| 358 |
var sel = this.getSelectedPanes()[0]; |
| 359 |
sel.domNode.style[css3.name("transition")] = ""; |
| 360 |
sel.domNode.style.height = this._openSpace + "px"; |
| 361 |
} |
| 362 |
}, |
| 363 |
|
| 364 |
_updateLast: function(){ |
| 365 |
|
| 366 |
|
| 367 |
var children = this.getChildren(); |
| 368 |
array.forEach(children, function(c, i){ |
| 369 |
|
| 370 |
domClass.toggle(c._at.domNode, "mblAccordionTitleLast", |
| 371 |
i === children.length - 1 && !domClass.contains(c._at.domNode, "mblAccordionTitleSelected")) |
| 372 |
}, this); |
| 373 |
}, |
| 374 |
|
| 375 |
expand: function(pane, noAnimation){ |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
if(pane.lazy){ |
| 383 |
lazyLoadUtils.instantiateLazyWidgets(pane.containerNode, pane.requires); |
| 384 |
pane.lazy = false; |
| 385 |
} |
| 386 |
var children = this.getChildren(); |
| 387 |
array.forEach(children, function(c, i){ |
| 388 |
c.domNode.style[css3.name("transition")] = noAnimation ? "" : "height "+this.duration+"s linear"; |
| 389 |
if(c === pane){ |
| 390 |
c.domNode.style.display = ""; |
| 391 |
var h; |
| 392 |
if(this.fixedHeight){ |
| 393 |
h = this._openSpace; |
| 394 |
}else{ |
| 395 |
h = parseInt(c.height || c.domNode.getAttribute("height")); |
| 396 |
if(!h){ |
| 397 |
c.domNode.style.height = ""; |
| 398 |
h = c.domNode.offsetHeight; |
| 399 |
c.domNode.style.height = "0px"; |
| 400 |
} |
| 401 |
} |
| 402 |
this.defer(function(){ |
| 403 |
c.domNode.style.height = h + "px"; |
| 404 |
}); |
| 405 |
this.select(pane); |
| 406 |
}else if(this.singleOpen){ |
| 407 |
this.collapse(c, noAnimation); |
| 408 |
} |
| 409 |
}, this); |
| 410 |
this._updateLast(); |
| 411 |
domAttr.set(pane.domNode, "aria-expanded", "true"); |
| 412 |
domAttr.set(pane.domNode, "aria-hidden", "false"); |
| 413 |
}, |
| 414 |
|
| 415 |
collapse: function(pane, noAnimation){ |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
if(pane.domNode.style.display === "none"){ return; } |
| 423 |
pane.domNode.style[css3.name("transition")] = noAnimation ? "" : "height "+this.duration+"s linear"; |
| 424 |
pane.domNode.style.height = "0px"; |
| 425 |
if(!has("css3-animations") || noAnimation){ |
| 426 |
pane.domNode.style.display = "none"; |
| 427 |
this._updateLast(); |
| 428 |
}else{ |
| 429 |
|
| 430 |
|
| 431 |
var _this = this; |
| 432 |
_this.defer(function(){ |
| 433 |
pane.domNode.style.display = "none"; |
| 434 |
_this._updateLast(); |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
if(!_this.fixedHeight && _this.singleOpen){ |
| 441 |
for(var v = _this.getParent(); v; v = v.getParent()){ |
| 442 |
if(domClass.contains(v.domNode, "mblView")){ |
| 443 |
if(v && v.resize){ v.resize(); } |
| 444 |
break; |
| 445 |
} |
| 446 |
} |
| 447 |
} |
| 448 |
}, this.duration*1000); |
| 449 |
} |
| 450 |
this.deselect(pane); |
| 451 |
domAttr.set(pane.domNode, "aria-expanded", "false"); |
| 452 |
domAttr.set(pane.domNode, "aria-hidden", "true"); |
| 453 |
}, |
| 454 |
|
| 455 |
select: function(pane){ |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
pane._at.set("selected", true); |
| 461 |
domAttr.set(pane._at.textBoxNode, "aria-selected", "true"); |
| 462 |
}, |
| 463 |
|
| 464 |
deselect: function(pane){ |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
pane._at.set("selected", false); |
| 470 |
domAttr.set(pane._at.textBoxNode, "aria-selected", "false"); |
| 471 |
} |
| 472 |
}); |
| 473 |
|
| 474 |
Accordion.ChildWidgetProperties = { |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
alt: "", |
| 481 |
|
| 482 |
|
| 483 |
label: "", |
| 484 |
|
| 485 |
|
| 486 |
icon1: "", |
| 487 |
|
| 488 |
|
| 489 |
icon2: "", |
| 490 |
|
| 491 |
|
| 492 |
iconPos1: "", |
| 493 |
|
| 494 |
|
| 495 |
iconPos2: "", |
| 496 |
|
| 497 |
|
| 498 |
selected: false, |
| 499 |
|
| 500 |
|
| 501 |
lazy: false |
| 502 |
}; |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
lang.extend(WidgetBase, Accordion.ChildWidgetProperties); |
| 508 |
|
| 509 |
return has("dojo-bidi") ? declare("dojox.mobile.Accordion", [Accordion, BidiAccordion]) : Accordion; |
| 510 |
}); |