| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/dom", |
| 5 |
"dojo/dom-attr", |
| 6 |
"dojo/dom-class", |
| 7 |
"dojo/dom-geometry", |
| 8 |
"dojo/fx", |
| 9 |
"dojo/has", |
| 10 |
"dojo/_base/kernel", |
| 11 |
"dojo/keys", |
| 12 |
"./_CssStateMixin", |
| 13 |
"./_TemplatedMixin", |
| 14 |
"./layout/ContentPane", |
| 15 |
"dojo/text!./templates/TitlePane.html", |
| 16 |
"./_base/manager", |
| 17 |
"./a11yclick" |
| 18 |
], function(array, declare, dom, domAttr, domClass, domGeometry, fxUtils, has, kernel, keys, |
| 19 |
_CssStateMixin, _TemplatedMixin, ContentPane, template, manager){ |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
var TitlePane = declare("dijit.TitlePane", [ContentPane, _TemplatedMixin, _CssStateMixin], { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
title: "", |
| 51 |
_setTitleAttr: { node: "titleNode", type: "innerHTML" }, |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
open: true, |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
toggleable: true, |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
tabIndex: "0", |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
duration: manager.defaultDuration, |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
baseClass: "dijitTitlePane", |
| 73 |
|
| 74 |
templateString: template, |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
doLayout: false, |
| 82 |
|
| 83 |
|
| 84 |
_setTooltipAttr: {node: "focusNode", type: "attribute", attribute: "title"}, |
| 85 |
|
| 86 |
buildRendering: function(){ |
| 87 |
this.inherited(arguments); |
| 88 |
dom.setSelectable(this.titleNode, false); |
| 89 |
}, |
| 90 |
|
| 91 |
postCreate: function(){ |
| 92 |
this.inherited(arguments); |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
if(this.toggleable){ |
| 98 |
this._trackMouseState(this.titleBarNode, this.baseClass + "Title"); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
var hideNode = this.hideNode, wipeNode = this.wipeNode; |
| 103 |
this._wipeIn = fxUtils.wipeIn({ |
| 104 |
node: wipeNode, |
| 105 |
duration: this.duration, |
| 106 |
beforeBegin: function(){ |
| 107 |
hideNode.style.display = ""; |
| 108 |
} |
| 109 |
}); |
| 110 |
this._wipeOut = fxUtils.wipeOut({ |
| 111 |
node: wipeNode, |
| 112 |
duration: this.duration, |
| 113 |
onEnd: function(){ |
| 114 |
hideNode.style.display = "none"; |
| 115 |
} |
| 116 |
}); |
| 117 |
}, |
| 118 |
|
| 119 |
_setOpenAttr: function( open, animate){ |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
array.forEach([this._wipeIn, this._wipeOut], function(animation){ |
| 126 |
if(animation && animation.status() == "playing"){ |
| 127 |
animation.stop(); |
| 128 |
} |
| 129 |
}); |
| 130 |
|
| 131 |
if(animate){ |
| 132 |
var anim = this[open ? "_wipeIn" : "_wipeOut"]; |
| 133 |
anim.play(); |
| 134 |
}else{ |
| 135 |
this.hideNode.style.display = this.wipeNode.style.display = open ? "" : "none"; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
if(this._started){ |
| 141 |
if(open){ |
| 142 |
this._onShow(); |
| 143 |
}else{ |
| 144 |
this.onHide(); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
this.containerNode.setAttribute("aria-hidden", open ? "false" : "true"); |
| 149 |
this.focusNode.setAttribute("aria-pressed", open ? "true" : "false"); |
| 150 |
|
| 151 |
this._set("open", open); |
| 152 |
|
| 153 |
this._setCss(); |
| 154 |
}, |
| 155 |
|
| 156 |
_setToggleableAttr: function( canToggle){ |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
this.focusNode.setAttribute("role", canToggle ? "button" : "heading"); |
| 163 |
if(canToggle){ |
| 164 |
this.focusNode.setAttribute("aria-controls", this.id + "_pane"); |
| 165 |
this.focusNode.setAttribute("tabIndex", this.tabIndex); |
| 166 |
this.focusNode.setAttribute("aria-pressed", this.open); |
| 167 |
}else{ |
| 168 |
domAttr.remove(this.focusNode, "aria-controls"); |
| 169 |
domAttr.remove(this.focusNode, "tabIndex"); |
| 170 |
domAttr.remove(this.focusNode, "aria-pressed"); |
| 171 |
} |
| 172 |
|
| 173 |
this._set("toggleable", canToggle); |
| 174 |
|
| 175 |
this._setCss(); |
| 176 |
}, |
| 177 |
|
| 178 |
_setContentAttr: function( content){ |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
if(!this.open || !this._wipeOut || this._wipeOut.status() == "playing"){ |
| 184 |
|
| 185 |
this.inherited(arguments); |
| 186 |
}else{ |
| 187 |
if(this._wipeIn && this._wipeIn.status() == "playing"){ |
| 188 |
this._wipeIn.stop(); |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
domGeometry.setMarginBox(this.wipeNode, { h: domGeometry.getMarginBox(this.wipeNode).h }); |
| 193 |
|
| 194 |
|
| 195 |
this.inherited(arguments); |
| 196 |
|
| 197 |
|
| 198 |
if(this._wipeIn){ |
| 199 |
this._wipeIn.play(); |
| 200 |
}else{ |
| 201 |
this.hideNode.style.display = ""; |
| 202 |
} |
| 203 |
} |
| 204 |
}, |
| 205 |
|
| 206 |
toggle: function(){ |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
this._setOpenAttr(!this.open, true); |
| 213 |
}, |
| 214 |
|
| 215 |
_setCss: function(){ |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
var node = this.titleBarNode || this.focusNode; |
| 222 |
var oldCls = this._titleBarClass; |
| 223 |
this._titleBarClass = this.baseClass + "Title" + (this.toggleable ? "" : "Fixed") + (this.open ? "Open" : "Closed"); |
| 224 |
domClass.replace(node, this._titleBarClass, oldCls || ""); |
| 225 |
|
| 226 |
|
| 227 |
domClass.replace(node, this._titleBarClass.replace("TitlePaneTitle", ""), (oldCls || "").replace("TitlePaneTitle", "")); |
| 228 |
|
| 229 |
this.arrowNodeInner.innerHTML = this.open ? "-" : "+"; |
| 230 |
}, |
| 231 |
|
| 232 |
_onTitleKey: function( e){ |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
if(e.keyCode == keys.DOWN_ARROW && this.open){ |
| 239 |
this.containerNode.focus(); |
| 240 |
e.preventDefault(); |
| 241 |
} |
| 242 |
}, |
| 243 |
|
| 244 |
_onTitleClick: function(){ |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
if(this.toggleable){ |
| 250 |
this.toggle(); |
| 251 |
} |
| 252 |
}, |
| 253 |
|
| 254 |
setTitle: function( title){ |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
kernel.deprecated("dijit.TitlePane.setTitle() is deprecated. Use set('title', ...) instead.", "", "2.0"); |
| 260 |
this.set("title", title); |
| 261 |
} |
| 262 |
}); |
| 263 |
|
| 264 |
if(has("dojo-bidi")){ |
| 265 |
TitlePane.extend({ |
| 266 |
_setTitleAttr: function( title){ |
| 267 |
|
| 268 |
this._set("title", title); |
| 269 |
this.titleNode.innerHTML = title; |
| 270 |
this.applyTextDir(this.titleNode); |
| 271 |
}, |
| 272 |
|
| 273 |
_setTooltipAttr: function( tooltip){ |
| 274 |
this._set("tooltip", tooltip); |
| 275 |
if(this.textDir){ |
| 276 |
tooltip = this.enforceTextDirWithUcc(null, tooltip); |
| 277 |
} |
| 278 |
domAttr.set(this.focusNode, "title", tooltip); |
| 279 |
}, |
| 280 |
|
| 281 |
_setTextDirAttr: function(textDir){ |
| 282 |
if(this._created && this.textDir != textDir){ |
| 283 |
this._set("textDir", textDir); |
| 284 |
this.set("title", this.title); |
| 285 |
this.set("tooltip", this.tooltip); |
| 286 |
} |
| 287 |
} |
| 288 |
}); |
| 289 |
} |
| 290 |
|
| 291 |
return TitlePane; |
| 292 |
}); |