TitleGroup.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. define("dojox/widget/TitleGroup", ["dojo", "dijit/registry", "dijit/_Widget", "dijit/TitlePane"], function(dojo, registry, widget, titlepane){
  2. var tp = titlepane.prototype,
  3. lookup = function(){
  4. // generic handler function for click and keypress
  5. var parent = this._dxfindParent && this._dxfindParent();
  6. parent && parent.selectChild(this);
  7. }
  8. ;
  9. // this might hide this uberprivate function from the docparser.
  10. tp._dxfindParent = function(){
  11. // summary: TitlePane's MUST be first-children of a TitleGroup. only used by
  12. // `dojox.widget.TitleGroup`. Finds a possible parent TitleGroup of a TitlePane
  13. var n = this.domNode.parentNode;
  14. if(n){
  15. n = registry.getEnclosingWidget(n);
  16. return n && n instanceof dojox.widget.TitleGroup && n;
  17. }
  18. return n;
  19. };
  20. // if we click our own title, hide everyone
  21. dojo.connect(tp, "_onTitleClick", lookup);
  22. dojo.connect(tp, "_onTitleKey", function(e){
  23. // if we're tabbing through the items in a group, don't do toggles.
  24. // if we hit enter, let it happen.
  25. if(!(e && e.type && e.type == "keypress" && e.charOrCode == dojo.keys.TAB)){
  26. lookup.apply(this, arguments);
  27. }
  28. });
  29. return dojo.declare("dojox.widget.TitleGroup", dijit._Widget, {
  30. // summary: A container which controls a series of `dijit.TitlePane`s,
  31. // allowing one to be visible and hiding siblings
  32. //
  33. // description:
  34. // A container which controls a series of `dijit.TitlePane`s,
  35. // allowing one to be visible and hiding siblings. Behaves similarly
  36. // to a `dijit.layout.AccordionContainer` in that the children
  37. // are all stacked, though merges the TitlePane behavior of
  38. // variable height
  39. //
  40. // example:
  41. // | var group = new dojox.widget.TitleGroup().placeAt(dojo.body());
  42. // | new dijit.TitlePane({ title:"One" }, "fromsource").placeAt(group);
  43. // | new dijit.TitlePane({ title:"Remote", href:"foo.html" }).placeAt(group);
  44. "class":"dojoxTitleGroup",
  45. addChild: function(widget, position){
  46. // summary: Add a passed widget reference to this container at an optional
  47. // position index.
  48. //
  49. // widget: dijit.TitlePane
  50. // A widget reference to add
  51. // position: String?|Int?
  52. // An optional index or position to pass. defaults to "last"
  53. return widget.placeAt(this.domNode, position); // dijit.TitlePane
  54. },
  55. removeChild: function(widget){
  56. // summary: Remove the passed widget from this container. Does not destroy
  57. // child.
  58. this.domNode.removeChild(widget.domNode);
  59. return widget;
  60. },
  61. selectChild: function(widget){
  62. // summary: close all found titlePanes within this group, excluding
  63. // the one the we pass to select
  64. widget && dojo.query("> .dijitTitlePane", this.domNode).forEach(function(n){
  65. var tp = registry.byNode(n);
  66. tp && tp !== widget && tp.open && tp.toggle(); // could race if open is set onEnd of slide
  67. });
  68. return widget; // dijit.TitlePane
  69. }
  70. });
  71. });