Debian Codegraph @

dojox/layout/ExpandoPane.js

raw symbols SCIP
1 define([
2 "dojo/_base/kernel",
3 "dojo/_base/lang",
4 "dojo/_base/declare",
5 "dojo/_base/array",
6 "dojo/_base/connect",
7 "dojo/_base/event",
8 "dojo/_base/fx",
9 "dojo/dom-style",
10 "dojo/dom-class",
11 "dojo/dom-geometry",
12 "dojo/text!./resources/ExpandoPane.html",
13 "dijit/layout/ContentPane",
14 "dijit/_TemplatedMixin",
15 "dijit/_Contained",
16 "dijit/_Container"
17 ], function(kernel,lang,declare,arrayUtil,connectUtil,eventUtil,baseFx,domStyle,domClass,domGeom,
18 template,ContentPane,TemplatedMixin,Contained,Container) {
19 kernel.experimental("dojox.layout.ExpandoPane"); // just to show it can be done?
20
21 return declare("dojox.layout.ExpandoPane", [ContentPane, TemplatedMixin, Contained, Container],{
22 // summary:
23 // An experimental collapsing-pane for dijit.layout.BorderContainer
24 // description:
25 // Works just like a ContentPane inside of a borderContainer. Will expand/collapse on
26 // command, and supports having Layout Children as direct descendants
27
28 //maxHeight: "",
29 //maxWidth: "",
30 //splitter: false,
31 attributeMap: lang.delegate(ContentPane.prototype.attributeMap, {
32 title: { node: "titleNode", type: "innerHTML" }
33 }),
34
35 templateString: template,
36
37 // easeOut: String|Function
38 // easing function used to hide pane
39 easeOut: "dojo._DefaultEasing", // FIXME: This won't work with globalless AMD
40
41 // easeIn: String|Function
42 // easing function use to show pane
43 easeIn: "dojo._DefaultEasing", // FIXME: This won't work with globalless AMD
44
45 // duration: Integer
46 // duration to run show/hide animations
47 duration: 420,
48
49 // startExpanded: Boolean
50 // Does this widget start in an open (true) or closed (false) state
51 startExpanded: true,
52
53 // previewOpacity: Float
54 // A value from 0 .. 1 indicating the opacity to use on the container
55 // when only showing a preview
56 previewOpacity: 0.75,
57
58 // previewOnDblClick: Boolean
59 // If true, will override the default behavior of a double-click calling a full toggle.
60 // If false, a double-click will cause the preview to popup
61 previewOnDblClick: false,
62
63 // tabIndex: String
64 // Order fields are traversed when user hits the tab key
65 tabIndex: "0",
66 _setTabIndexAttr: "iconNode",
67
68 baseClass: "dijitExpandoPane",
69
70 postCreate: function(){
71 this.inherited(arguments);
72 this._animConnects = [];
73
74 this._isHorizontal = true;
75
76 if(lang.isString(this.easeOut)){
77 this.easeOut = lang.getObject(this.easeOut);
78 }
79 if(lang.isString(this.easeIn)){
80 this.easeIn = lang.getObject(this.easeIn);
81 }
82
83 var thisClass = "", rtl = !this.isLeftToRight();
84 if(this.region){
85 switch(this.region){
86 case "trailing" :
87 case "right" :
88 thisClass = rtl ? "Left" : "Right";
89 this._needsPosition = "left";
90 break;
91 case "leading" :
92 case "left" :
93 thisClass = rtl ? "Right" : "Left";
94 break;
95 case "top" :
96 thisClass = "Top";
97 break;
98 case "bottom" :
99 this._needsPosition = "top";
100 thisClass = "Bottom";
101 break;
102 }
103 domClass.add(this.domNode, "dojoxExpando" + thisClass);
104 domClass.add(this.iconNode, "dojoxExpandoIcon" + thisClass);
105 this._isHorizontal = /top|bottom/.test(this.region);
106 }
107 domStyle.set(this.domNode, {
108 overflow: "hidden",
109 padding:0
110 });
111
112 this.connect(this.domNode, "ondblclick", this.previewOnDblClick ? "preview" : "toggle");
113
114 this.iconNode.setAttribute("aria-controls", this.id);
115 this.iconNode.setAttribute("role", "button");
116 this.iconNode.setAttribute("aria-label", this.titleNode.innerHTML);
117
118 if(this.previewOnDblClick){
119 this.connect(this.getParent(), "_layoutChildren", lang.hitch(this, function(){
120 this._isonlypreview = false;
121 }));
122 }
123
124 },
125
126 _startupSizes: function(){
127
128 this._container = this.getParent();
129 this._closedSize = this._titleHeight = domGeom.getMarginBox(this.titleWrapper).h;
130
131 if(this.splitter){
132 // find our splitter and tie into it's drag logic
133 var myid = this.id;
134 arrayUtil.forEach(dijit.registry.toArray(), function(w){
135 if(w && w.child && w.child.id == myid){
136 this.connect(w,"_stopDrag","_afterResize");
137 }
138 }, this);
139 }
140
141 this._currentSize = domGeom.getContentBox(this.domNode); // TODO: can compute this from passed in value to resize(), see _LayoutWidget for example
142 this._showSize = this._currentSize[(this._isHorizontal ? "h" : "w")];
143 this._setupAnims();
144
145 if(this.startExpanded){
146 this._showing = true;
147 }else{
148 this._showing = false;
149 this._hideWrapper();
150 this._hideAnim.gotoPercent(99,true);
151 }
152
153 this.domNode.setAttribute("aria-expanded", this._showing);
154 this._hasSizes = true;
155 },
156
157 _afterResize: function(e){
158 var tmp = this._currentSize; // the old size
159 this._currentSize = domGeom.getMarginBox(this.domNode); // the new size
160 var n = this._currentSize[(this._isHorizontal ? "h" : "w")];
161 if(n > this._titleHeight){
162 if(!this._showing){
163 this._showing = !this._showing;
164 this._showEnd();
165 }
166 this._showSize = n;
167 this._setupAnims();
168 }else{
169 this._showSize = tmp[(this._isHorizontal ? "h" : "w")];
170 this._showing = false;
171 this._hideWrapper();
172 this._hideAnim.gotoPercent(89,true);
173 }
174
175 },
176
177 _setupAnims: function(){
178 // summary:
179 // Create the show and hide animations
180 arrayUtil.forEach(this._animConnects, connectUtil.disconnect);
181
182 var _common = {
183 node:this.domNode,
184 duration:this.duration
185 },
186 isHorizontal = this._isHorizontal,
187 showProps = {},
188 showSize = this._showSize,
189 hideSize = this._closedSize,
190 hideProps = {},
191 dimension = isHorizontal ? "height" : "width",
192 also = this._needsPosition
193 ;
194
195 showProps[dimension] = {
196 end: showSize
197 };
198 hideProps[dimension] = {
199 end: hideSize
200 };
201
202 if(also){
203 showProps[also] = {
204 end: function(n){
205 var c = parseInt(n.style[also], 10);
206 return c - showSize + hideSize;
207 }
208 }
209 hideProps[also] = {
210 end: function(n){
211 var c = parseInt(n.style[also], 10);
212 return c + showSize - hideSize;
213 }
214 }
215 }
216
217 this._showAnim = baseFx.animateProperty(lang.mixin(_common,{
218 easing:this.easeIn,
219 properties: showProps
220 }));
221 this._hideAnim = baseFx.animateProperty(lang.mixin(_common,{
222 easing:this.easeOut,
223 properties: hideProps
224 }));
225
226 this._animConnects = [
227 connectUtil.connect(this._showAnim, "onEnd", this, "_showEnd"),
228 connectUtil.connect(this._hideAnim, "onEnd", this, "_hideEnd")
229 ];
230 },
231
232 preview: function(){
233 // summary:
234 // Expand this pane in preview mode (does not affect surrounding layout)
235
236 if(!this._showing){
237 this._isonlypreview = !this._isonlypreview;
238 }
239 this.toggle();
240 },
241
242 toggle: function(){
243 // summary:
244 // Toggle this pane's visibility
245 if(this._showing){
246 this._hideWrapper();
247 this._showAnim && this._showAnim.stop();
248 this._hideAnim.play();
249 }else{
250 this._hideAnim && this._hideAnim.stop();
251 this._showAnim.play();
252 }
253 this._showing = !this._showing;
254 this.domNode.setAttribute("aria-expanded", this._showing);
255 },
256
257 _hideWrapper: function(){
258 // summary:
259 // Set the Expando state to "closed"
260 domClass.add(this.domNode, "dojoxExpandoClosed");
261
262 domStyle.set(this.cwrapper,{
263 visibility: "hidden",
264 opacity: "0",
265 overflow: "hidden"
266 });
267 },
268
269 _showEnd: function(){
270 // summary:
271 // Common animation onEnd code - "unclose"
272 domStyle.set(this.cwrapper, {
273 opacity: 0,
274 visibility:"visible"
275 });
276 baseFx.anim(this.cwrapper, {
277 opacity: this._isonlypreview ? this.previewOpacity : 1
278 }, 227);
279 domClass.remove(this.domNode, "dojoxExpandoClosed");
280 if(!this._isonlypreview){
281 setTimeout(lang.hitch(this._container, "layout"), 15);
282 }else{
283 this._previewShowing = true;
284 this.resize();
285 }
286 },
287
288 _hideEnd: function(){
289 // summary:
290 // Callback for the hide animation - "close"
291
292 // every time we hide, reset the "only preview" state
293 if(!this._isonlypreview){
294 setTimeout(lang.hitch(this._container, "layout"), 25);
295 }else{
296 this._previewShowing = false;
297 }
298 this._isonlypreview = false;
299
300 },
301
302 resize: function(/*Object?*/newSize){
303 // summary:
304 // we aren't a layout widget, but need to act like one.
305 // newSize: Object
306 // The size object to resize to
307
308 if(!this._hasSizes){ this._startupSizes(newSize); }
309
310 // compute size of container (ie, size left over after title bar)
311 var currentSize = domGeom.getMarginBox(this.domNode);
312 this._contentBox = {
313 w: newSize && "w" in newSize ? newSize.w : currentSize.w,
314 h: (newSize && "h" in newSize ? newSize.h : currentSize.h) - this._titleHeight
315 };
316 domStyle.set(this.containerNode, "height", this._contentBox.h + "px");
317
318 if(newSize){
319 domGeom.setMarginBox(this.domNode, newSize);
320 }
321
322 this._layoutChildren();
323 this._setupAnims();
324 },
325
326 _trap: function(/*Event*/ e){
327 // summary:
328 // Trap stray events
329 eventUtil.stop(e);
330 }
331 });
332 });