Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dijit.TitlePane"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dijit.TitlePane"] = true;
3
dojo.provide("dijit.TitlePane");
4
 
5
dojo.require("dojo.fx");
6
 
7
dojo.require("dijit._Templated");
8
dojo.require("dijit.layout.ContentPane");
9
 
10
dojo.declare(
11
	"dijit.TitlePane",
12
	[dijit.layout.ContentPane, dijit._Templated],
13
{
14
	// summary
15
	//		A pane with a title on top, that can be opened or collapsed.
16
	//
17
	// title: String
18
	//		Title of the pane
19
	title: "",
20
 
21
	// open: Boolean
22
	//		Whether pane is opened or closed.
23
	open: true,
24
 
25
	// duration: Integer
26
	//		Time in milliseconds to fade in/fade out
27
	duration: 250,
28
 
29
	// baseClass: String
30
	//	the root className to use for the various states of this widget
31
	baseClass: "dijitTitlePane",
32
 
33
	templateString:"<div class=\"dijitTitlePane\">\n\t<div dojoAttachEvent=\"onclick:toggle,onkeypress: _onTitleKey,onfocus:_handleFocus,onblur:_handleFocus\" tabindex=\"0\"\n\t\t\twaiRole=\"button\" class=\"dijitTitlePaneTitle\" dojoAttachPoint=\"focusNode\">\n\t\t<div dojoAttachPoint=\"arrowNode\" class=\"dijitInline dijitArrowNode\"><span dojoAttachPoint=\"arrowNodeInner\" class=\"dijitArrowNodeInner\"></span></div>\n\t\t<div dojoAttachPoint=\"titleNode\" class=\"dijitTitlePaneTextNode\"></div>\n\t</div>\n\t<div class=\"dijitTitlePaneContentOuter\" dojoAttachPoint=\"hideNode\">\n\t\t<div class=\"dijitReset\" dojoAttachPoint=\"wipeNode\">\n\t\t\t<div class=\"dijitTitlePaneContentInner\" dojoAttachPoint=\"containerNode\" waiRole=\"region\" tabindex=\"-1\">\n\t\t\t\t<!-- nested divs because wipeIn()/wipeOut() doesn't work right on node w/padding etc.  Put padding on inner div. -->\n\t\t\t</div>\n\t\t</div>\n\t</div>\n</div>\n",
34
 
35
	postCreate: function(){
36
		this.setTitle(this.title);
37
		if(!this.open){
38
			this.hideNode.style.display = this.wipeNode.style.display = "none";
39
		}
40
		this._setCss();
41
		dojo.setSelectable(this.titleNode, false);
42
		this.inherited("postCreate",arguments);
43
		dijit.setWaiState(this.containerNode, "labelledby", this.titleNode.id);
44
		dijit.setWaiState(this.focusNode, "haspopup", "true");
45
 
46
		// setup open/close animations
47
		var hideNode = this.hideNode, wipeNode = this.wipeNode;
48
		this._wipeIn = dojo.fx.wipeIn({
49
			node: this.wipeNode,
50
			duration: this.duration,
51
			beforeBegin: function(){
52
				hideNode.style.display="";
53
			}
54
		});
55
		this._wipeOut = dojo.fx.wipeOut({
56
			node: this.wipeNode,
57
			duration: this.duration,
58
			onEnd: function(){
59
				hideNode.style.display="none";
60
			}
61
		});
62
	},
63
 
64
	setContent: function(content){
65
		// summary
66
		// 		Typically called when an href is loaded.  Our job is to make the animation smooth
67
		if(this._wipeOut.status() == "playing"){
68
			// we are currently *closing* the pane, so just let that continue
69
			this.inherited("setContent",arguments);
70
		}else{
71
			if(this._wipeIn.status() == "playing"){
72
				this._wipeIn.stop();
73
			}
74
 
75
			// freeze container at current height so that adding new content doesn't make it jump
76
			dojo.marginBox(this.wipeNode, {h: dojo.marginBox(this.wipeNode).h});
77
 
78
			// add the new content (erasing the old content, if any)
79
			this.inherited("setContent",arguments);
80
 
81
			// call _wipeIn.play() to animate from current height to new height
82
			this._wipeIn.play();
83
		}
84
	},
85
 
86
	toggle: function(){
87
		// summary: switches between opened and closed state
88
		dojo.forEach([this._wipeIn, this._wipeOut], function(animation){
89
			if(animation.status() == "playing"){
90
				animation.stop();
91
			}
92
		});
93
 
94
		this[this.open ? "_wipeOut" : "_wipeIn"].play();
95
		this.open =! this.open;
96
 
97
		// load content (if this is the first time we are opening the TitlePane
98
		// and content is specified as an href, or we have setHref when hidden)
99
		this._loadCheck();
100
 
101
		this._setCss();
102
	},
103
 
104
	_setCss: function(){
105
		// summary: set the open/close css state for the TitlePane
106
		var classes = ["dijitClosed", "dijitOpen"];
107
		var boolIndex = this.open;
108
		dojo.removeClass(this.focusNode, classes[!boolIndex+0]);
109
		this.focusNode.className += " " + classes[boolIndex+0];
110
 
111
		// provide a character based indicator for images-off mode
112
		this.arrowNodeInner.innerHTML = this.open ? "-" : "+";
113
	},
114
 
115
	_onTitleKey: function(/*Event*/ e){
116
		// summary: callback when user hits a key
117
		if(e.keyCode == dojo.keys.ENTER || e.charCode == dojo.keys.SPACE){
118
			this.toggle();
119
		}
120
		else if(e.keyCode == dojo.keys.DOWN_ARROW){
121
			if(this.open){
122
				this.containerNode.focus();
123
				e.preventDefault();
124
			}
125
	 	}
126
	},
127
 
128
	_handleFocus: function(/*Event*/ e){
129
		// summary: handle blur and focus for this widget
130
 
131
		// add/removeClass is safe to call without hasClass in this case
132
		dojo[(e.type=="focus" ? "addClass" : "removeClass")](this.focusNode,this.baseClass+"Focused");
133
	},
134
 
135
	setTitle: function(/*String*/ title){
136
		// summary: sets the text of the title
137
		this.titleNode.innerHTML=title;
138
	}
139
});
140
 
141
}