TitleGroup.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.widget.TitleGroup"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.widget.TitleGroup"] = true;
  8. dojo.provide("dojox.widget.TitleGroup");
  9. dojo.require("dijit._Widget");
  10. dojo.require("dijit.TitlePane");
  11. (function(d){
  12. var tp = dijit.TitlePane.prototype,
  13. lookup = function(){
  14. // generic handler function for click and keypress
  15. var parent = this._dxfindParent && this._dxfindParent();
  16. parent && parent.selectChild(this);
  17. }
  18. ;
  19. // this might hide this uberprivate function from the docparser.
  20. tp._dxfindParent = function(){
  21. // summary: TitlePane's MUST be first-children of a TitleGroup. only used by
  22. // `dojox.widget.TitleGroup`. Find a possible parent TitleGroup of a TitlePane
  23. var n = this.domNode.parentNode;
  24. if(n){
  25. n = dijit.getEnclosingWidget(n);
  26. return n && n instanceof dojox.widget.TitleGroup && n;
  27. }
  28. return n;
  29. };
  30. // if we click our own title, hide everyone
  31. d.connect(tp, "_onTitleClick", lookup);
  32. d.connect(tp, "_onTitleKey", function(e){
  33. // if we're tabbing through the items in a group, don't do toggles.
  34. // if we hit enter, let it happen.
  35. if(!(e && e.type && e.type == "keypress" && e.charOrCode == d.keys.TAB)){
  36. lookup.apply(this, arguments);
  37. }
  38. });
  39. d.declare("dojox.widget.TitleGroup", dijit._Widget, {
  40. // summary: A container which controls a series of `dijit.TitlePane`s,
  41. // allowing one to be visible and hiding siblings
  42. //
  43. // description:
  44. // A container which controls a series of `dijit.TitlePane`s,
  45. // allowing one to be visible and hiding siblings. Behaves similarly
  46. // to a `dijit.layout.AccordionContainer` in that the children
  47. // are all stacked, though merges the TitlePane behavior of
  48. // variable height
  49. //
  50. // example:
  51. // | var group = new dojox.widget.TitleGroup().placeAt(dojo.body());
  52. // | new dijit.TitlePane({ title:"One" }, "fromsource").placeAt(group);
  53. // | new dijit.TitlePane({ title:"Remote", href:"foo.html" }).placeAt(group);
  54. "class":"dojoxTitleGroup",
  55. addChild: function(widget, position){
  56. // summary: Add a passed widget reference to this container at an optional
  57. // position index.
  58. //
  59. // widget: dijit.TitlePane
  60. // A widget reference to add
  61. // position: String?|Int?
  62. // An optional index or position to pass. defaults to "last"
  63. return widget.placeAt(this.domNode, position); // dijit.TitlePane
  64. },
  65. removeChild: function(widget){
  66. // summary: Remove the passed widget from this container. Does not destroy
  67. // child.
  68. this.domNode.removeChild(widget.domNode);
  69. return widget;
  70. },
  71. selectChild: function(widget){
  72. // summary: close all found titlePanes within this group, excluding
  73. // the one the we pass to select
  74. widget && dojo.query("> .dijitTitlePane", this.domNode).forEach(function(n){
  75. var tp = dijit.getEnclosingWidget(n);
  76. tp && tp !== widget && tp.open && tp.set("open", false);
  77. });
  78. return widget; // dijit.TitlePane
  79. }
  80. });
  81. })(dojo);
  82. }