Debian Codegraph @

dojox/layout/FloatingPane.js

raw symbols SCIP
1 define(["dojo/_base/kernel", "dojo/_base/lang", "dojo/_base/window", "dojo/_base/declare",
2 "dojo/_base/fx", "dojo/_base/connect", "dojo/_base/array", "dojo/_base/sniff",
3 "dojo/window", "dojo/dom", "dojo/dom-class", "dojo/dom-geometry", "dojo/dom-construct", "dojo/touch",
4 "dijit/_TemplatedMixin", "dijit/_Widget", "dijit/BackgroundIframe",
5 "dijit/registry", "dojo/dnd/Moveable", "./ContentPane", "./ResizeHandle", "dojo/text!./resources/FloatingPane.html","./Dock"
6 ], function(
7 kernel, lang, winUtil, declare, baseFx, connectUtil, arrayUtil,
8 has, windowLib, dom, domClass, domGeom, domConstruct, touch, TemplatedMixin, Widget, BackgroundIframe,
9 registry, Moveable, ContentPane, ResizeHandle, template, Dock){
10
11 kernel.experimental("dojox.layout.FloatingPane");
12
13 return declare("dojox.layout.FloatingPane", [ ContentPane, TemplatedMixin ],{
14 // summary:
15 // A non-modal Floating window.
16 // description:
17 // Makes a `dojox.layout.ContentPane` float and draggable by it's title [similar to TitlePane]
18 // and over-rides onClick to onDblClick for wipeIn/Out of containerNode
19 // provides minimize(dock) / show() and hide() methods, and resize [almost]
20
21 // closable: Boolean
22 // Allow closure of this Node
23 closable: true,
24
25 // dockable: Boolean
26 // Allow minimizing of pane if true
27 dockable: true,
28
29 // resizable: Boolean
30 // Allow resizing of pane true if true
31 resizable: false,
32
33 // maxable: Boolean
34 // Horrible param name for "Can you maximize this floating pane?"
35 maxable: false,
36
37 // resizeAxis: String
38 // One of: x | xy | y to limit pane's sizing direction
39 resizeAxis: "xy",
40
41 // title: String
42 // Title to use in the header
43 title: "",
44
45 // dockTo: DomNode?
46 // if empty, will create private layout.Dock that scrolls with viewport
47 // on bottom span of viewport.
48 dockTo: "",
49
50 // duration: Integer
51 // Time is MS to spend toggling in/out node
52 duration: 400,
53
54 /*=====
55 // iconSrc: String
56 // [not implemented yet] will be either icon in titlepane to left
57 // of Title, and/or icon show when docked in a fisheye-like dock
58 // or maybe dockIcon would be better?
59 iconSrc: null,
60 =====*/
61
62 // contentClass: String
63 // The className to give to the inner node which has the content
64 contentClass: "dojoxFloatingPaneContent",
65
66 // animation holders for toggle
67 _showAnim: null,
68 _hideAnim: null,
69 // node in the dock (if docked)
70 _dockNode: null,
71
72 // privates:
73 _restoreState: {},
74 _allFPs: [],
75 _startZ: 100,
76
77 templateString: template,
78
79 attributeMap: lang.delegate(Widget.prototype.attributeMap, {
80 title: { type:"innerHTML", node:"titleNode" }
81 }),
82
83 postCreate: function(){
84 this.inherited(arguments);
85 new Moveable(this.domNode,{ handle: this.focusNode });
86 //this._listener = dojo.subscribe("/dnd/move/start",this,"bringToTop");
87
88 if(!this.dockable){ this.dockNode.style.display = "none"; }
89 if(!this.closable){ this.closeNode.style.display = "none"; }
90 if(!this.maxable){
91 this.maxNode.style.display = "none";
92 this.restoreNode.style.display = "none";
93 }
94 if(!this.resizable){
95 this.resizeHandle.style.display = "none";
96 }else{
97 this.domNode.style.width = domGeom.getMarginBox(this.domNode).w + "px";
98 }
99 this._allFPs.push(this);
100 this.domNode.style.position = "absolute";
101
102 this.bgIframe = new BackgroundIframe(this.domNode);
103 this._naturalState = domGeom.position(this.domNode);
104 },
105
106 startup: function(){
107 if(this._started){ return; }
108
109 this.inherited(arguments);
110
111 if(this.resizable){
112 if(has("ie")){
113 this.canvas.style.overflow = "auto";
114 }else{
115 this.containerNode.style.overflow = "auto";
116 }
117
118 this._resizeHandle = new ResizeHandle({
119 targetId: this.id,
120 resizeAxis: this.resizeAxis
121 },this.resizeHandle);
122
123 }
124
125 if(this.dockable){
126 // FIXME: argh.
127 var tmpName = this.dockTo;
128
129 if(this.dockTo){
130 this.dockTo = registry.byId(this.dockTo);
131 }else{
132 this.dockTo = registry.byId('dojoxGlobalFloatingDock');
133 }
134
135 if(!this.dockTo){
136 var tmpId, tmpNode;
137 // we need to make our dock node, and position it against
138 // .dojoxDockDefault .. this is a lot. either dockto="node"
139 // and fail if node doesn't exist or make the global one
140 // once, and use it on empty OR invalid dockTo="" node?
141 if(tmpName){
142 tmpId = tmpName;
143 tmpNode = dom.byId(tmpName);
144 }else{
145 tmpNode = domConstruct.create('div', null, winUtil.body());
146 domClass.add(tmpNode,"dojoxFloatingDockDefault");
147 tmpId = 'dojoxGlobalFloatingDock';
148 }
149 this.dockTo = new Dock({ id: tmpId, autoPosition: "south" }, tmpNode);
150 this.dockTo.startup();
151 }
152
153 if((this.domNode.style.display == "none")||(this.domNode.style.visibility == "hidden")){
154 // If the FP is created dockable and non-visible, start up docked.
155 this.minimize();
156 }
157 }
158 this.connect(this.focusNode, touch.press,"bringToTop");
159 this.connect(this.domNode, touch.press,"bringToTop");
160
161 // Initial resize to give child the opportunity to lay itself out
162 this.resize(domGeom.position(this.domNode));
163
164 this._started = true;
165 },
166
167 setTitle: function(/* String */ title){
168 // summary:
169 // Update the Title bar with a new string
170 kernel.deprecated("pane.setTitle", "Use pane.set('title', someTitle)", "2.0");
171 this.set("title", title);
172 },
173
174 close: function(){
175 // summary:
176 // Close and destroy this widget
177 if(!this.closable){ return; }
178 connectUtil.unsubscribe(this._listener);
179 this.hide(lang.hitch(this,function(){
180 this.destroyRecursive();
181 }));
182 },
183
184 hide: function(/* Function? */ callback){
185 // summary:
186 // Close, but do not destroy this FloatingPane
187 baseFx.fadeOut({
188 node:this.domNode,
189 duration:this.duration,
190 onEnd: lang.hitch(this,function() {
191 this.domNode.style.display = "none";
192 this.domNode.style.visibility = "hidden";
193 if(this.dockTo && this.dockable){
194 this.dockTo._positionDock(null);
195 }
196 if(callback){
197 callback();
198 }
199 })
200 }).play();
201 },
202
203 show: function(/* Function? */callback){
204 // summary:
205 // Show the FloatingPane
206 var anim = baseFx.fadeIn({node:this.domNode, duration:this.duration,
207 beforeBegin: lang.hitch(this,function(){
208 this.domNode.style.display = "";
209 this.domNode.style.visibility = "visible";
210 if (this.dockTo && this.dockable) { this.dockTo._positionDock(null); }
211 if (typeof callback == "function") { callback(); }
212 this._isDocked = false;
213 if (this._dockNode) {
214 this._dockNode.destroy();
215 this._dockNode = null;
216 }
217 })
218 }).play();
219 // use w / h from content box dimensions and x / y from position
220 var contentBox = domGeom.getContentBox(this.domNode);
221 this.resize(lang.mixin(domGeom.position(this.domNode), {w: contentBox.w, h: contentBox.h}));
222 this._onShow(); // lazy load trigger
223 },
224
225 minimize: function(){
226 // summary:
227 // Hide and dock the FloatingPane
228 if(!this._isDocked){ this.hide(lang.hitch(this,"_dock")); }
229 },
230
231 maximize: function(){
232 // summary:
233 // Make this FloatingPane full-screen (viewport)
234 if(this._maximized){ return; }
235 this._naturalState = domGeom.position(this.domNode);
236 if(this._isDocked){
237 this.show();
238 setTimeout(lang.hitch(this,"maximize"),this.duration);
239 }
240 domClass.add(this.focusNode,"floatingPaneMaximized");
241 this.resize(windowLib.getBox());
242 this._maximized = true;
243 },
244
245 _restore: function(){
246 if(this._maximized){
247 this.resize(this._naturalState);
248 domClass.remove(this.focusNode,"floatingPaneMaximized");
249 this._maximized = false;
250 }
251 },
252
253 _dock: function(){
254 if(!this._isDocked && this.dockable){
255 this._dockNode = this.dockTo.addNode(this);
256 this._isDocked = true;
257 }
258 },
259
260 resize: function(/* Object */dim){
261 // summary:
262 // Size the FloatingPane and place accordingly
263 dim = dim || this._naturalState;
264 this._naturalState = dim;
265
266 // From the ResizeHandle we only get width and height information
267 var dns = this.domNode.style;
268 if("t" in dim){ dns.top = dim.t + "px"; }
269 else if("y" in dim){ dns.top = dim.y + "px"; }
270 if("l" in dim){ dns.left = dim.l + "px"; }
271 else if("x" in dim){ dns.left = dim.x + "px"; }
272 dns.width = dim.w + "px";
273 dns.height = dim.h + "px";
274
275 // Now resize canvas
276 var mbCanvas = { l: 0, t: 0, w: dim.w, h: (dim.h - this.focusNode.offsetHeight) };
277 domGeom.setMarginBox(this.canvas, mbCanvas);
278
279 // If the single child can resize, forward resize event to it so it can
280 // fit itself properly into the content area
281 this._checkIfSingleChild();
282 if(this._singleChild && this._singleChild.resize){
283 this._singleChild.resize(mbCanvas);
284 }
285 },
286
287 bringToTop: function(){
288 // summary:
289 // bring this FloatingPane above all other panes
290 var windows = arrayUtil.filter(
291 this._allFPs,
292 function(i){
293 return i !== this;
294 },
295 this);
296 windows.sort(function(a, b){
297 return a.domNode.style.zIndex - b.domNode.style.zIndex;
298 });
299 windows.push(this);
300
301 arrayUtil.forEach(windows, function(w, x){
302 w.domNode.style.zIndex = this._startZ + (x * 2);
303 domClass.remove(w.domNode, "dojoxFloatingPaneFg");
304 }, this);
305 domClass.add(this.domNode, "dojoxFloatingPaneFg");
306 },
307
308 destroy: function(){
309 // summary:
310 // Destroy this FloatingPane completely
311 this._allFPs.splice(arrayUtil.indexOf(this._allFPs, this), 1);
312 if(this._resizeHandle){
313 this._resizeHandle.destroy();
314 }
315 this.inherited(arguments);
316 }
317 });
318
319 });