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