| 1 |
define([ |
| 2 |
"require", |
| 3 |
"dojo/_base/array", |
| 4 |
"dojo/_base/declare", |
| 5 |
"dojo/_base/fx", |
| 6 |
"dojo/dom", |
| 7 |
"dojo/dom-attr", |
| 8 |
"dojo/dom-class", |
| 9 |
"dojo/dom-construct", |
| 10 |
"dojo/dom-geometry", |
| 11 |
"dojo/keys", |
| 12 |
"dojo/_base/lang", |
| 13 |
"dojo/sniff", |
| 14 |
"dojo/topic", |
| 15 |
"../focus", |
| 16 |
"../_base/manager", |
| 17 |
"dojo/ready", |
| 18 |
"../_Widget", |
| 19 |
"../_Container", |
| 20 |
"../_TemplatedMixin", |
| 21 |
"../_CssStateMixin", |
| 22 |
"./StackContainer", |
| 23 |
"./ContentPane", |
| 24 |
"dojo/text!./templates/AccordionButton.html", |
| 25 |
"../a11yclick" |
| 26 |
], function(require, array, declare, fx, dom, domAttr, domClass, domConstruct, domGeometry, keys, lang, has, topic, |
| 27 |
focus, manager, ready, _Widget, _Container, _TemplatedMixin, _CssStateMixin, StackContainer, ContentPane, template){ |
| 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 |
function size(widget, dim){ |
| 55 |
widget.resize ? widget.resize(dim) : domGeometry.setMarginBox(widget.domNode, dim); |
| 56 |
} |
| 57 |
|
| 58 |
var AccordionButton = declare("dijit.layout._AccordionButton", [_Widget, _TemplatedMixin, _CssStateMixin], { |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
templateString: template, |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
label: "", |
| 70 |
_setLabelAttr: {node: "titleTextNode", type: "innerHTML" }, |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
title: "", |
| 75 |
_setTitleAttr: {node: "titleTextNode", type: "attribute", attribute: "title"}, |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
iconClassAttr: "", |
| 80 |
_setIconClassAttr: { node: "iconNode", type: "class" }, |
| 81 |
|
| 82 |
baseClass: "dijitAccordionTitle", |
| 83 |
|
| 84 |
getParent: function(){ |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
return this.parent; |
| 90 |
}, |
| 91 |
|
| 92 |
buildRendering: function(){ |
| 93 |
this.inherited(arguments); |
| 94 |
var titleTextNodeId = this.id.replace(' ', '_'); |
| 95 |
domAttr.set(this.titleTextNode, "id", titleTextNodeId + "_title"); |
| 96 |
this.focusNode.setAttribute("aria-labelledby", domAttr.get(this.titleTextNode, "id")); |
| 97 |
dom.setSelectable(this.domNode, false); |
| 98 |
}, |
| 99 |
|
| 100 |
getTitleHeight: function(){ |
| 101 |
|
| 102 |
|
| 103 |
return domGeometry.getMarginSize(this.domNode).h; |
| 104 |
}, |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
_onTitleClick: function(){ |
| 109 |
|
| 110 |
|
| 111 |
var parent = this.getParent(); |
| 112 |
parent.selectChild(this.contentWidget, true); |
| 113 |
focus.focus(this.focusNode); |
| 114 |
}, |
| 115 |
|
| 116 |
_onTitleKeyDown: function( evt){ |
| 117 |
return this.getParent()._onKeyDown(evt, this.contentWidget); |
| 118 |
}, |
| 119 |
|
| 120 |
_setSelectedAttr: function( isSelected){ |
| 121 |
this._set("selected", isSelected); |
| 122 |
this.focusNode.setAttribute("aria-expanded", isSelected ? "true" : "false"); |
| 123 |
this.focusNode.setAttribute("aria-selected", isSelected ? "true" : "false"); |
| 124 |
this.focusNode.setAttribute("tabIndex", isSelected ? "0" : "-1"); |
| 125 |
} |
| 126 |
}); |
| 127 |
|
| 128 |
if(has("dojo-bidi")){ |
| 129 |
AccordionButton.extend({ |
| 130 |
_setLabelAttr: function(label){ |
| 131 |
this._set("label", label); |
| 132 |
domAttr.set(this.titleTextNode, "innerHTML", label); |
| 133 |
this.applyTextDir(this.titleTextNode); |
| 134 |
}, |
| 135 |
|
| 136 |
_setTitleAttr: function(title){ |
| 137 |
this._set("title", title); |
| 138 |
domAttr.set(this.titleTextNode, "title", title); |
| 139 |
this.applyTextDir(this.titleTextNode); |
| 140 |
} |
| 141 |
}); |
| 142 |
} |
| 143 |
|
| 144 |
var AccordionInnerContainer = declare("dijit.layout._AccordionInnerContainer" + (has("dojo-bidi") ? "_NoBidi" : ""), [_Widget, _CssStateMixin], { |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
baseClass: "dijitAccordionInnerContainer", |
| 165 |
|
| 166 |
|
| 167 |
isLayoutContainer: true, |
| 168 |
|
| 169 |
buildRendering: function(){ |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
this.domNode = domConstruct.place("<div class='" + this.baseClass + |
| 180 |
"' role='presentation'>", this.contentWidget.domNode, "after"); |
| 181 |
|
| 182 |
|
| 183 |
var child = this.contentWidget, |
| 184 |
cls = lang.isString(this.buttonWidget) ? lang.getObject(this.buttonWidget) : this.buttonWidget; |
| 185 |
this.button = child._buttonWidget = (new cls({ |
| 186 |
contentWidget: child, |
| 187 |
label: child.title, |
| 188 |
title: child.tooltip, |
| 189 |
dir: child.dir, |
| 190 |
lang: child.lang, |
| 191 |
textDir: child.textDir || this.textDir, |
| 192 |
iconClass: child.iconClass, |
| 193 |
id: child.id + "_button", |
| 194 |
parent: this.parent |
| 195 |
})).placeAt(this.domNode); |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
this.containerNode = domConstruct.place("<div class='dijitAccordionChildWrapper' role='tabpanel' style='display:none'>", this.domNode); |
| 200 |
this.containerNode.setAttribute("aria-labelledby", this.button.id); |
| 201 |
|
| 202 |
domConstruct.place(this.contentWidget.domNode, this.containerNode); |
| 203 |
}, |
| 204 |
|
| 205 |
postCreate: function(){ |
| 206 |
this.inherited(arguments); |
| 207 |
|
| 208 |
|
| 209 |
var button = this.button, |
| 210 |
cw = this.contentWidget; |
| 211 |
this._contentWidgetWatches = [ |
| 212 |
cw.watch('title', lang.hitch(this, function(name, oldValue, newValue){ |
| 213 |
button.set("label", newValue); |
| 214 |
})), |
| 215 |
cw.watch('tooltip', lang.hitch(this, function(name, oldValue, newValue){ |
| 216 |
button.set("title", newValue); |
| 217 |
})), |
| 218 |
cw.watch('iconClass', lang.hitch(this, function(name, oldValue, newValue){ |
| 219 |
button.set("iconClass", newValue); |
| 220 |
})) |
| 221 |
]; |
| 222 |
}, |
| 223 |
|
| 224 |
_setSelectedAttr: function( isSelected){ |
| 225 |
this._set("selected", isSelected); |
| 226 |
this.button.set("selected", isSelected); |
| 227 |
if(isSelected){ |
| 228 |
var cw = this.contentWidget; |
| 229 |
if(cw.onSelected){ |
| 230 |
cw.onSelected(); |
| 231 |
} |
| 232 |
} |
| 233 |
}, |
| 234 |
|
| 235 |
startup: function(){ |
| 236 |
|
| 237 |
this.contentWidget.startup(); |
| 238 |
}, |
| 239 |
|
| 240 |
destroy: function(){ |
| 241 |
this.button.destroyRecursive(); |
| 242 |
|
| 243 |
array.forEach(this._contentWidgetWatches || [], function(w){ |
| 244 |
w.unwatch(); |
| 245 |
}); |
| 246 |
|
| 247 |
delete this.contentWidget._buttonWidget; |
| 248 |
delete this.contentWidget._wrapperWidget; |
| 249 |
|
| 250 |
this.inherited(arguments); |
| 251 |
}, |
| 252 |
|
| 253 |
destroyDescendants: function( preserveDom){ |
| 254 |
|
| 255 |
this.contentWidget.destroyRecursive(preserveDom); |
| 256 |
} |
| 257 |
}); |
| 258 |
|
| 259 |
if(has("dojo-bidi")){ |
| 260 |
AccordionInnerContainer = declare("dijit.layout._AccordionInnerContainer", AccordionInnerContainer, { |
| 261 |
postCreate: function(){ |
| 262 |
this.inherited(arguments); |
| 263 |
|
| 264 |
|
| 265 |
var button = this.button; |
| 266 |
this._contentWidgetWatches.push( |
| 267 |
this.contentWidget.watch("textDir", function(name, oldValue, newValue){ |
| 268 |
button.set("textDir", newValue); |
| 269 |
}) |
| 270 |
); |
| 271 |
} |
| 272 |
}); |
| 273 |
} |
| 274 |
|
| 275 |
var AccordionContainer = declare("dijit.layout.AccordionContainer", StackContainer, { |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
duration: manager.defaultDuration, |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
buttonWidget: AccordionButton, |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
baseClass: "dijitAccordionContainer", |
| 303 |
|
| 304 |
buildRendering: function(){ |
| 305 |
this.inherited(arguments); |
| 306 |
this.domNode.style.overflow = "hidden"; |
| 307 |
this.domNode.setAttribute("role", "tablist"); |
| 308 |
}, |
| 309 |
|
| 310 |
startup: function(){ |
| 311 |
if(this._started){ |
| 312 |
return; |
| 313 |
} |
| 314 |
this.inherited(arguments); |
| 315 |
if(this.selectedChildWidget){ |
| 316 |
this.selectedChildWidget._wrapperWidget.set("selected", true); |
| 317 |
} |
| 318 |
}, |
| 319 |
|
| 320 |
layout: function(){ |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
var openPane = this.selectedChildWidget; |
| 325 |
|
| 326 |
if(!openPane){ |
| 327 |
return; |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
var wrapperDomNode = openPane._wrapperWidget.domNode, |
| 332 |
wrapperDomNodeMargin = domGeometry.getMarginExtents(wrapperDomNode), |
| 333 |
wrapperDomNodePadBorder = domGeometry.getPadBorderExtents(wrapperDomNode), |
| 334 |
wrapperContainerNode = openPane._wrapperWidget.containerNode, |
| 335 |
wrapperContainerNodeMargin = domGeometry.getMarginExtents(wrapperContainerNode), |
| 336 |
wrapperContainerNodePadBorder = domGeometry.getPadBorderExtents(wrapperContainerNode), |
| 337 |
mySize = this._contentBox; |
| 338 |
|
| 339 |
|
| 340 |
var totalCollapsedHeight = 0; |
| 341 |
array.forEach(this.getChildren(), function(child){ |
| 342 |
if(child != openPane){ |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
totalCollapsedHeight += domGeometry.getMarginSize(child._wrapperWidget.domNode).h; |
| 347 |
} |
| 348 |
}); |
| 349 |
this._verticalSpace = mySize.h - totalCollapsedHeight - wrapperDomNodeMargin.h |
| 350 |
- wrapperDomNodePadBorder.h - wrapperContainerNodeMargin.h - wrapperContainerNodePadBorder.h |
| 351 |
- openPane._buttonWidget.getTitleHeight(); |
| 352 |
|
| 353 |
|
| 354 |
this._containerContentBox = { |
| 355 |
h: this._verticalSpace, |
| 356 |
w: this._contentBox.w - wrapperDomNodeMargin.w - wrapperDomNodePadBorder.w |
| 357 |
- wrapperContainerNodeMargin.w - wrapperContainerNodePadBorder.w |
| 358 |
}; |
| 359 |
|
| 360 |
if(openPane){ |
| 361 |
size(openPane, this._containerContentBox); |
| 362 |
} |
| 363 |
}, |
| 364 |
|
| 365 |
_setupChild: function(child){ |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
child._wrapperWidget = AccordionInnerContainer({ |
| 370 |
contentWidget: child, |
| 371 |
buttonWidget: this.buttonWidget, |
| 372 |
id: child.id + "_wrapper", |
| 373 |
dir: child.dir, |
| 374 |
lang: child.lang, |
| 375 |
textDir: child.textDir || this.textDir, |
| 376 |
parent: this |
| 377 |
}); |
| 378 |
|
| 379 |
this.inherited(arguments); |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
domConstruct.place(child.domNode, child._wrapper, "replace"); |
| 384 |
}, |
| 385 |
|
| 386 |
removeChild: function(child){ |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
if(child._wrapperWidget){ |
| 394 |
domConstruct.place(child.domNode, child._wrapperWidget.domNode, "after"); |
| 395 |
child._wrapperWidget.destroy(); |
| 396 |
delete child._wrapperWidget; |
| 397 |
} |
| 398 |
|
| 399 |
domClass.remove(child.domNode, "dijitHidden"); |
| 400 |
|
| 401 |
this.inherited(arguments); |
| 402 |
}, |
| 403 |
|
| 404 |
getChildren: function(){ |
| 405 |
|
| 406 |
return array.map(this.inherited(arguments), function(child){ |
| 407 |
return child.declaredClass == "dijit.layout._AccordionInnerContainer" ? child.contentWidget : child; |
| 408 |
}, this); |
| 409 |
}, |
| 410 |
|
| 411 |
destroy: function(){ |
| 412 |
if(this._animation){ |
| 413 |
this._animation.stop(); |
| 414 |
} |
| 415 |
array.forEach(this.getChildren(), function(child){ |
| 416 |
|
| 417 |
|
| 418 |
if(child._wrapperWidget){ |
| 419 |
child._wrapperWidget.destroy(); |
| 420 |
}else{ |
| 421 |
child.destroyRecursive(); |
| 422 |
} |
| 423 |
}); |
| 424 |
this.inherited(arguments); |
| 425 |
}, |
| 426 |
|
| 427 |
_showChild: function(child){ |
| 428 |
|
| 429 |
child._wrapperWidget.containerNode.style.display = "block"; |
| 430 |
return this.inherited(arguments); |
| 431 |
}, |
| 432 |
|
| 433 |
_hideChild: function(child){ |
| 434 |
|
| 435 |
child._wrapperWidget.containerNode.style.display = "none"; |
| 436 |
this.inherited(arguments); |
| 437 |
}, |
| 438 |
|
| 439 |
_transition: function( newWidget, oldWidget, animate){ |
| 440 |
|
| 441 |
|
| 442 |
if(has("ie") < 8){ |
| 443 |
|
| 444 |
animate = false; |
| 445 |
} |
| 446 |
|
| 447 |
if(this._animation){ |
| 448 |
|
| 449 |
this._animation.stop(true); |
| 450 |
delete this._animation; |
| 451 |
} |
| 452 |
|
| 453 |
var self = this; |
| 454 |
|
| 455 |
if(newWidget){ |
| 456 |
newWidget._wrapperWidget.set("selected", true); |
| 457 |
|
| 458 |
var d = this._showChild(newWidget); |
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
if(this.doLayout){ |
| 464 |
size(newWidget, this._containerContentBox); |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
if(oldWidget){ |
| 469 |
oldWidget._wrapperWidget.set("selected", false); |
| 470 |
if(!animate){ |
| 471 |
this._hideChild(oldWidget); |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
if(animate){ |
| 476 |
var newContents = newWidget._wrapperWidget.containerNode, |
| 477 |
oldContents = oldWidget._wrapperWidget.containerNode; |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
var wrapperContainerNode = newWidget._wrapperWidget.containerNode, |
| 483 |
wrapperContainerNodeMargin = domGeometry.getMarginExtents(wrapperContainerNode), |
| 484 |
wrapperContainerNodePadBorder = domGeometry.getPadBorderExtents(wrapperContainerNode), |
| 485 |
animationHeightOverhead = wrapperContainerNodeMargin.h + wrapperContainerNodePadBorder.h; |
| 486 |
|
| 487 |
oldContents.style.height = (self._verticalSpace - animationHeightOverhead) + "px"; |
| 488 |
|
| 489 |
this._animation = new fx.Animation({ |
| 490 |
node: newContents, |
| 491 |
duration: this.duration, |
| 492 |
curve: [1, this._verticalSpace - animationHeightOverhead - 1], |
| 493 |
onAnimate: function(value){ |
| 494 |
value = Math.floor(value); |
| 495 |
newContents.style.height = value + "px"; |
| 496 |
oldContents.style.height = (self._verticalSpace - animationHeightOverhead - value) + "px"; |
| 497 |
}, |
| 498 |
onEnd: function(){ |
| 499 |
delete self._animation; |
| 500 |
newContents.style.height = "auto"; |
| 501 |
oldWidget._wrapperWidget.containerNode.style.display = "none"; |
| 502 |
oldContents.style.height = "auto"; |
| 503 |
self._hideChild(oldWidget); |
| 504 |
} |
| 505 |
}); |
| 506 |
this._animation.onStop = this._animation.onEnd; |
| 507 |
this._animation.play(); |
| 508 |
} |
| 509 |
|
| 510 |
return d; |
| 511 |
}, |
| 512 |
|
| 513 |
|
| 514 |
_onKeyDown: function( e, fromTitle){ |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
if(this.disabled || e.altKey || !(fromTitle || e.ctrlKey)){ |
| 522 |
return; |
| 523 |
} |
| 524 |
var c = e.keyCode; |
| 525 |
if((fromTitle && (c == keys.LEFT_ARROW || c == keys.UP_ARROW)) || |
| 526 |
(e.ctrlKey && c == keys.PAGE_UP)){ |
| 527 |
this._adjacent(false)._buttonWidget._onTitleClick(); |
| 528 |
e.stopPropagation(); |
| 529 |
e.preventDefault(); |
| 530 |
}else if((fromTitle && (c == keys.RIGHT_ARROW || c == keys.DOWN_ARROW)) || |
| 531 |
(e.ctrlKey && (c == keys.PAGE_DOWN || c == keys.TAB))){ |
| 532 |
this._adjacent(true)._buttonWidget._onTitleClick(); |
| 533 |
e.stopPropagation(); |
| 534 |
e.preventDefault(); |
| 535 |
} |
| 536 |
} |
| 537 |
}); |
| 538 |
|
| 539 |
|
| 540 |
if(has("dijit-legacy-requires")){ |
| 541 |
ready(0, function(){ |
| 542 |
var requires = ["dijit/layout/AccordionPane"]; |
| 543 |
require(requires); |
| 544 |
}); |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
AccordionContainer._InnerContainer = AccordionInnerContainer; |
| 549 |
AccordionContainer._Button = AccordionButton; |
| 550 |
|
| 551 |
return AccordionContainer; |
| 552 |
}); |