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: TitlePane's MUST be first-children of a TitleGroup. only used by |
---|
14 | // `dojox.widget.TitleGroup`. Finds a possible parent TitleGroup of a TitlePane |
---|
15 | var n = this.domNode.parentNode; |
---|
16 | if(n){ |
---|
17 | n = registry.getEnclosingWidget(n); |
---|
18 | return n && n instanceof dojox.widget.TitleGroup && n; |
---|
19 | } |
---|
20 | return n; |
---|
21 | }; |
---|
22 | |
---|
23 | // if we click our own title, hide everyone |
---|
24 | dojo.connect(tp, "_onTitleClick", lookup); |
---|
25 | dojo.connect(tp, "_onTitleKey", function(e){ |
---|
26 | // if we're tabbing through the items in a group, don't do toggles. |
---|
27 | // if we hit enter, let it happen. |
---|
28 | if(!(e && e.type && e.type == "keypress" && e.charOrCode == dojo.keys.TAB)){ |
---|
29 | lookup.apply(this, arguments); |
---|
30 | } |
---|
31 | }); |
---|
32 | |
---|
33 | return dojo.declare("dojox.widget.TitleGroup", dijit._Widget, { |
---|
34 | // summary: A container which controls a series of `dijit.TitlePane`s, |
---|
35 | // allowing one to be visible and hiding siblings |
---|
36 | // |
---|
37 | // description: |
---|
38 | // A container which controls a series of `dijit.TitlePane`s, |
---|
39 | // allowing one to be visible and hiding siblings. Behaves similarly |
---|
40 | // to a `dijit.layout.AccordionContainer` in that the children |
---|
41 | // are all stacked, though merges the TitlePane behavior of |
---|
42 | // variable height |
---|
43 | // |
---|
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: Add a passed widget reference to this container at an optional |
---|
53 | // position index. |
---|
54 | // |
---|
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: Remove the passed widget from this container. Does not destroy |
---|
64 | // child. |
---|
65 | |
---|
66 | this.domNode.removeChild(widget.domNode); |
---|
67 | return widget; |
---|
68 | }, |
---|
69 | |
---|
70 | selectChild: function(widget){ |
---|
71 | // summary: close all found titlePanes within this group, excluding |
---|
72 | // the one the we pass to select |
---|
73 | widget && dojo.query("> .dijitTitlePane", this.domNode).forEach(function(n){ |
---|
74 | var tp = registry.byNode(n); |
---|
75 | tp && tp !== widget && tp.open && tp.toggle(); // could race if open is set onEnd of slide |
---|
76 | }); |
---|
77 | return widget; // dijit.TitlePane |
---|
78 | } |
---|
79 | |
---|
80 | }); |
---|
81 | |
---|
82 | }); |
---|