| 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 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
closable: true, |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
dockable: true, |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
resizable: false, |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
maxable: false, |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
resizeAxis: "xy", |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
title: "", |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
dockTo: "", |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
duration: 400, |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
contentClass: "dojoxFloatingPaneContent", |
| 65 |
|
| 66 |
|
| 67 |
_showAnim: null, |
| 68 |
_hideAnim: null, |
| 69 |
|
| 70 |
_dockNode: null, |
| 71 |
|
| 72 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 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 |
|
| 155 |
this.minimize(); |
| 156 |
} |
| 157 |
} |
| 158 |
this.connect(this.focusNode, touch.press,"bringToTop"); |
| 159 |
this.connect(this.domNode, touch.press,"bringToTop"); |
| 160 |
|
| 161 |
|
| 162 |
this.resize(domGeom.position(this.domNode)); |
| 163 |
|
| 164 |
this._started = true; |
| 165 |
}, |
| 166 |
|
| 167 |
setTitle: function( title){ |
| 168 |
|
| 169 |
|
| 170 |
kernel.deprecated("pane.setTitle", "Use pane.set('title', someTitle)", "2.0"); |
| 171 |
this.set("title", title); |
| 172 |
}, |
| 173 |
|
| 174 |
close: function(){ |
| 175 |
|
| 176 |
|
| 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( callback){ |
| 185 |
|
| 186 |
|
| 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(callback){ |
| 204 |
|
| 205 |
|
| 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 |
|
| 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(); |
| 223 |
}, |
| 224 |
|
| 225 |
minimize: function(){ |
| 226 |
|
| 227 |
|
| 228 |
if(!this._isDocked){ this.hide(lang.hitch(this,"_dock")); } |
| 229 |
}, |
| 230 |
|
| 231 |
maximize: function(){ |
| 232 |
|
| 233 |
|
| 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(dim){ |
| 261 |
|
| 262 |
|
| 263 |
dim = dim || this._naturalState; |
| 264 |
this._naturalState = dim; |
| 265 |
|
| 266 |
|
| 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 |
|
| 276 |
var mbCanvas = { l: 0, t: 0, w: dim.w, h: (dim.h - this.focusNode.offsetHeight) }; |
| 277 |
domGeom.setMarginBox(this.canvas, mbCanvas); |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
this._checkIfSingleChild(); |
| 282 |
if(this._singleChild && this._singleChild.resize){ |
| 283 |
this._singleChild.resize(mbCanvas); |
| 284 |
} |
| 285 |
}, |
| 286 |
|
| 287 |
bringToTop: function(){ |
| 288 |
|
| 289 |
|
| 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 |
|
| 310 |
|
| 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 |
}); |