summaryrefslogtreecommitdiff
path: root/js/dojo-1.6/dojox/widget/TitleGroup.js
blob: 197a90271b029c7dcceba19a41708d28bf121a01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


if(!dojo._hasResource["dojox.widget.TitleGroup"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.widget.TitleGroup"] = true;
dojo.provide("dojox.widget.TitleGroup");

dojo.require("dijit._Widget");
dojo.require("dijit.TitlePane");

(function(d){
	
	var tp = dijit.TitlePane.prototype,
		lookup = function(){
			// generic handler function for click and keypress
			var parent = this._dxfindParent && this._dxfindParent();
			parent && parent.selectChild(this);
		}
	;
	
	// this might hide this uberprivate function from the docparser.
	tp._dxfindParent = function(){
		// summary: TitlePane's MUST be first-children of a TitleGroup. only used by
		//		`dojox.widget.TitleGroup`. Find a possible parent TitleGroup of a TitlePane
		var n = this.domNode.parentNode;
		if(n){
			n = dijit.getEnclosingWidget(n);
			return n && n instanceof dojox.widget.TitleGroup && n;
		}
		return n;
	};

	// if we click our own title, hide everyone
	d.connect(tp, "_onTitleClick", lookup);
	d.connect(tp, "_onTitleKey", function(e){
		// if we're tabbing through the items in a group, don't do toggles.
		// if we hit enter, let it happen.
		if(!(e && e.type && e.type == "keypress" && e.charOrCode == d.keys.TAB)){
			lookup.apply(this, arguments);
		}
	});
		
	d.declare("dojox.widget.TitleGroup", dijit._Widget, {
		// summary: A container which controls a series of `dijit.TitlePane`s,
		//		allowing one to be visible and hiding siblings
		//
		// description:
		//		A container which controls a series of `dijit.TitlePane`s,
		//		allowing one to be visible and hiding siblings. Behaves similarly
		//		to a `dijit.layout.AccordionContainer` in that the children
		//		are all stacked, though merges the TitlePane behavior of
		//		variable height
		//
		// example:
		//	|	var group = new dojox.widget.TitleGroup().placeAt(dojo.body());
		//	|	new dijit.TitlePane({ title:"One" }, "fromsource").placeAt(group);
		//	|	new dijit.TitlePane({ title:"Remote", href:"foo.html" }).placeAt(group);
		
		"class":"dojoxTitleGroup",

		addChild: function(widget, position){
			// summary: Add a passed widget reference to this container at an optional
			//		position index.
			//
			// widget: dijit.TitlePane
			//		A widget reference to add
			// position: String?|Int?
			//		An optional index or position to pass. defaults to "last"
			return widget.placeAt(this.domNode, position); // dijit.TitlePane
		},
		
		removeChild: function(widget){
			// summary: Remove the passed widget from this container. Does not destroy
			//		child.
			
			this.domNode.removeChild(widget.domNode);
			return widget;
		},
		
		selectChild: function(widget){
			// summary: close all found titlePanes within this group, excluding
			// the one the we pass to select
			widget && dojo.query("> .dijitTitlePane", this.domNode).forEach(function(n){
				var tp = dijit.getEnclosingWidget(n);
				tp && tp !== widget && tp.open && tp.set("open", false);
			});
			return widget; // dijit.TitlePane
		}
	
	});

})(dojo);

}