| 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"); |
| 20 |
|
| 21 |
return declare("dojox.layout.ExpandoPane", [ContentPane, TemplatedMixin, Contained, Container],{ |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
attributeMap: lang.delegate(ContentPane.prototype.attributeMap, { |
| 32 |
title: { node: "titleNode", type: "innerHTML" } |
| 33 |
}), |
| 34 |
|
| 35 |
templateString: template, |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
easeOut: "dojo._DefaultEasing", |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
easeIn: "dojo._DefaultEasing", |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
duration: 420, |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
startExpanded: true, |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
previewOpacity: 0.75, |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
previewOnDblClick: false, |
| 62 |
|
| 63 |
|
| 64 |
|
| 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 |
|
| 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); |
| 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; |
| 159 |
this._currentSize = domGeom.getMarginBox(this.domNode); |
| 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 |
|
| 179 |
|
| 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 |
|
| 234 |
|
| 235 |
|
| 236 |
if(!this._showing){ |
| 237 |
this._isonlypreview = !this._isonlypreview; |
| 238 |
} |
| 239 |
this.toggle(); |
| 240 |
}, |
| 241 |
|
| 242 |
toggle: function(){ |
| 243 |
|
| 244 |
|
| 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 |
|
| 259 |
|
| 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 |
|
| 271 |
|
| 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 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 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(newSize){ |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
if(!this._hasSizes){ this._startupSizes(newSize); } |
| 309 |
|
| 310 |
|
| 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( e){ |
| 327 |
|
| 328 |
|
| 329 |
eventUtil.stop(e); |
| 330 |
} |
| 331 |
}); |
| 332 |
}); |