| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/cookie", |
| 4 |
"dojo/_base/declare", |
| 5 |
"dojo/dom-class", |
| 6 |
"dojo/dom-construct", |
| 7 |
"dojo/dom-geometry", |
| 8 |
"dojo/dom-style", |
| 9 |
"dojo/keys", |
| 10 |
"dojo/_base/lang", |
| 11 |
"dojo/on", |
| 12 |
"dojo/touch", |
| 13 |
"../_WidgetBase", |
| 14 |
"../_Widget", |
| 15 |
"../_TemplatedMixin", |
| 16 |
"./LayoutContainer", |
| 17 |
"./utils" |
| 18 |
], function(array, cookie, declare, domClass, domConstruct, domGeometry, domStyle, keys, lang, on, touch, |
| 19 |
_WidgetBase, _Widget, _TemplatedMixin, LayoutContainer, layoutUtils){ |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
var _Splitter = declare("dijit.layout._Splitter", [_Widget, _TemplatedMixin ], { |
| 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 |
|
| 51 |
live: true, |
| 52 |
|
| 53 |
templateString: '<div class="dijitSplitter" data-dojo-attach-event="onkeydown:_onKeyDown,press:_startDrag,onmouseenter:_onMouse,onmouseleave:_onMouse" tabIndex="0" role="separator"><div class="dijitSplitterThumb"></div></div>', |
| 54 |
|
| 55 |
constructor: function(){ |
| 56 |
this._handlers = []; |
| 57 |
}, |
| 58 |
|
| 59 |
postMixInProperties: function(){ |
| 60 |
this.inherited(arguments); |
| 61 |
|
| 62 |
this.horizontal = /top|bottom/.test(this.region); |
| 63 |
this._factor = /top|left/.test(this.region) ? 1 : -1; |
| 64 |
this._cookieName = this.container.id + "_" + this.region; |
| 65 |
}, |
| 66 |
|
| 67 |
buildRendering: function(){ |
| 68 |
this.inherited(arguments); |
| 69 |
|
| 70 |
domClass.add(this.domNode, "dijitSplitter" + (this.horizontal ? "H" : "V")); |
| 71 |
|
| 72 |
if(this.container.persist){ |
| 73 |
|
| 74 |
var persistSize = this._getPersistentSplit(); |
| 75 |
if(persistSize){ |
| 76 |
this.child.domNode.style[this.horizontal ? "height" : "width"] = persistSize; |
| 77 |
} |
| 78 |
} |
| 79 |
}, |
| 80 |
|
| 81 |
_computeMaxSize: function(){ |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
var dim = this.horizontal ? 'h' : 'w', |
| 86 |
childSize = domGeometry.getMarginBox(this.child.domNode)[dim], |
| 87 |
center = array.filter(this.container.getChildren(), function(child){ |
| 88 |
return child.region == "center"; |
| 89 |
})[0]; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
var spaceAvailable = domGeometry.getContentBox(center.domNode)[dim] - 10; |
| 94 |
|
| 95 |
return Math.min(this.child.maxSize, childSize + spaceAvailable); |
| 96 |
}, |
| 97 |
|
| 98 |
_startDrag: function(e){ |
| 99 |
if(!this.cover){ |
| 100 |
this.cover = domConstruct.place("<div class=dijitSplitterCover></div>", this.child.domNode, "after"); |
| 101 |
} |
| 102 |
domClass.add(this.cover, "dijitSplitterCoverActive"); |
| 103 |
|
| 104 |
|
| 105 |
if(this.fake){ |
| 106 |
domConstruct.destroy(this.fake); |
| 107 |
} |
| 108 |
if(!(this._resize = this.live)){ |
| 109 |
|
| 110 |
(this.fake = this.domNode.cloneNode(true)).removeAttribute("id"); |
| 111 |
domClass.add(this.domNode, "dijitSplitterShadow"); |
| 112 |
domConstruct.place(this.fake, this.domNode, "after"); |
| 113 |
} |
| 114 |
domClass.add(this.domNode, "dijitSplitterActive dijitSplitter" + (this.horizontal ? "H" : "V") + "Active"); |
| 115 |
if(this.fake){ |
| 116 |
domClass.remove(this.fake, "dijitSplitterHover dijitSplitter" + (this.horizontal ? "H" : "V") + "Hover"); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
var factor = this._factor, |
| 121 |
isHorizontal = this.horizontal, |
| 122 |
axis = isHorizontal ? "pageY" : "pageX", |
| 123 |
pageStart = e[axis], |
| 124 |
splitterStyle = this.domNode.style, |
| 125 |
dim = isHorizontal ? 'h' : 'w', |
| 126 |
childCS = domStyle.getComputedStyle(this.child.domNode), |
| 127 |
childStart = domGeometry.getMarginBox(this.child.domNode, childCS)[dim], |
| 128 |
max = this._computeMaxSize(), |
| 129 |
min = Math.max(this.child.minSize, domGeometry.getPadBorderExtents(this.child.domNode, childCS)[dim] + 10), |
| 130 |
region = this.region, |
| 131 |
splitterAttr = region == "top" || region == "bottom" ? "top" : "left", |
| 132 |
splitterStart = parseInt(splitterStyle[splitterAttr], 10), |
| 133 |
resize = this._resize, |
| 134 |
layoutFunc = lang.hitch(this.container, "_layoutChildren", this.child.id), |
| 135 |
de = this.ownerDocument; |
| 136 |
|
| 137 |
this._handlers = this._handlers.concat([ |
| 138 |
on(de, touch.move, this._drag = function(e, forceResize){ |
| 139 |
var delta = e[axis] - pageStart, |
| 140 |
childSize = factor * delta + childStart, |
| 141 |
boundChildSize = Math.max(Math.min(childSize, max), min); |
| 142 |
|
| 143 |
if(resize || forceResize){ |
| 144 |
layoutFunc(boundChildSize); |
| 145 |
} |
| 146 |
|
| 147 |
splitterStyle[splitterAttr] = delta + splitterStart + factor * (boundChildSize - childSize) + "px"; |
| 148 |
}), |
| 149 |
on(de, "dragstart", function(e){ |
| 150 |
e.stopPropagation(); |
| 151 |
e.preventDefault(); |
| 152 |
}), |
| 153 |
on(this.ownerDocumentBody, "selectstart", function(e){ |
| 154 |
e.stopPropagation(); |
| 155 |
e.preventDefault(); |
| 156 |
}), |
| 157 |
on(de, touch.release, lang.hitch(this, "_stopDrag")) |
| 158 |
]); |
| 159 |
e.stopPropagation(); |
| 160 |
e.preventDefault(); |
| 161 |
}, |
| 162 |
|
| 163 |
_onMouse: function(e){ |
| 164 |
|
| 165 |
|
| 166 |
var o = (e.type == "mouseover" || e.type == "mouseenter"); |
| 167 |
domClass.toggle(this.domNode, "dijitSplitterHover", o); |
| 168 |
domClass.toggle(this.domNode, "dijitSplitter" + (this.horizontal ? "H" : "V") + "Hover", o); |
| 169 |
}, |
| 170 |
|
| 171 |
_getPersistentSplit: function() { |
| 172 |
return cookie(this._cookieName); |
| 173 |
}, |
| 174 |
|
| 175 |
_setPersistentSplit: function(value) { |
| 176 |
cookie(this._cookieName, value, {expires: 365}); |
| 177 |
}, |
| 178 |
|
| 179 |
_stopDrag: function(e){ |
| 180 |
try{ |
| 181 |
if(this.cover){ |
| 182 |
domClass.remove(this.cover, "dijitSplitterCoverActive"); |
| 183 |
} |
| 184 |
if(this.fake){ |
| 185 |
domConstruct.destroy(this.fake); |
| 186 |
} |
| 187 |
domClass.remove(this.domNode, "dijitSplitterActive dijitSplitter" |
| 188 |
+ (this.horizontal ? "H" : "V") + "Active dijitSplitterShadow"); |
| 189 |
this._drag(e); |
| 190 |
this._drag(e, true); |
| 191 |
}finally{ |
| 192 |
this._cleanupHandlers(); |
| 193 |
delete this._drag; |
| 194 |
} |
| 195 |
|
| 196 |
if(this.container.persist){ |
| 197 |
this._setPersistentSplit(this.child.domNode.style[this.horizontal ? "height" : "width"]); |
| 198 |
} |
| 199 |
}, |
| 200 |
|
| 201 |
_cleanupHandlers: function(){ |
| 202 |
var h; |
| 203 |
while(h = this._handlers.pop()){ |
| 204 |
h.remove(); |
| 205 |
} |
| 206 |
}, |
| 207 |
|
| 208 |
_onKeyDown: function( e){ |
| 209 |
|
| 210 |
this._resize = true; |
| 211 |
var horizontal = this.horizontal; |
| 212 |
var tick = 1; |
| 213 |
switch(e.keyCode){ |
| 214 |
case horizontal ? keys.UP_ARROW : keys.LEFT_ARROW: |
| 215 |
tick *= -1; |
| 216 |
|
| 217 |
case horizontal ? keys.DOWN_ARROW : keys.RIGHT_ARROW: |
| 218 |
break; |
| 219 |
default: |
| 220 |
|
| 221 |
return; |
| 222 |
} |
| 223 |
var childSize = domGeometry.getMarginSize(this.child.domNode)[ horizontal ? 'h' : 'w' ] + this._factor * tick; |
| 224 |
this.container._layoutChildren(this.child.id, Math.max(Math.min(childSize, this._computeMaxSize()), this.child.minSize)); |
| 225 |
e.stopPropagation(); |
| 226 |
e.preventDefault(); |
| 227 |
}, |
| 228 |
|
| 229 |
destroy: function(){ |
| 230 |
this._cleanupHandlers(); |
| 231 |
delete this.child; |
| 232 |
delete this.container; |
| 233 |
delete this.cover; |
| 234 |
delete this.fake; |
| 235 |
this.inherited(arguments); |
| 236 |
} |
| 237 |
}); |
| 238 |
|
| 239 |
var _Gutter = declare("dijit.layout._Gutter", [_Widget, _TemplatedMixin], { |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
templateString: '<div class="dijitGutter" role="presentation"></div>', |
| 250 |
|
| 251 |
postMixInProperties: function(){ |
| 252 |
this.inherited(arguments); |
| 253 |
this.horizontal = /top|bottom/.test(this.region); |
| 254 |
}, |
| 255 |
|
| 256 |
buildRendering: function(){ |
| 257 |
this.inherited(arguments); |
| 258 |
domClass.add(this.domNode, "dijitGutter" + (this.horizontal ? "H" : "V")); |
| 259 |
} |
| 260 |
}); |
| 261 |
|
| 262 |
var BorderContainer = declare("dijit.layout.BorderContainer", LayoutContainer, { |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
gutters: true, |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
liveSplitters: true, |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
persist: false, |
| 288 |
|
| 289 |
baseClass: "dijitBorderContainer", |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
_splitterClass: _Splitter, |
| 294 |
|
| 295 |
postMixInProperties: function(){ |
| 296 |
|
| 297 |
|
| 298 |
if(!this.gutters){ |
| 299 |
this.baseClass += "NoGutter"; |
| 300 |
} |
| 301 |
this.inherited(arguments); |
| 302 |
}, |
| 303 |
|
| 304 |
_setupChild: function( child){ |
| 305 |
|
| 306 |
|
| 307 |
this.inherited(arguments); |
| 308 |
|
| 309 |
var region = child.region, ltr = child.isLeftToRight(); |
| 310 |
if(region == "leading"){ |
| 311 |
region = ltr ? "left" : "right"; |
| 312 |
} |
| 313 |
if(region == "trailing"){ |
| 314 |
region = ltr ? "right" : "left"; |
| 315 |
} |
| 316 |
|
| 317 |
if(region){ |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
if(region != "center" && (child.splitter || this.gutters) && !child._splitterWidget){ |
| 322 |
var _Splitter = child.splitter ? this._splitterClass : _Gutter; |
| 323 |
if(lang.isString(_Splitter)){ |
| 324 |
_Splitter = lang.getObject(_Splitter); |
| 325 |
} |
| 326 |
var splitter = new _Splitter({ |
| 327 |
id: child.id + "_splitter", |
| 328 |
container: this, |
| 329 |
child: child, |
| 330 |
region: region, |
| 331 |
live: this.liveSplitters |
| 332 |
}); |
| 333 |
splitter.isSplitter = true; |
| 334 |
child._splitterWidget = splitter; |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
var before = region == "bottom" || region == (this.isLeftToRight() ? "right" : "left"); |
| 339 |
domConstruct.place(splitter.domNode, child.domNode, before ? "before" : "after"); |
| 340 |
|
| 341 |
|
| 342 |
splitter.startup(); |
| 343 |
} |
| 344 |
} |
| 345 |
}, |
| 346 |
|
| 347 |
layout: function(){ |
| 348 |
|
| 349 |
this._layoutChildren(); |
| 350 |
}, |
| 351 |
|
| 352 |
removeChild: function( child){ |
| 353 |
|
| 354 |
|
| 355 |
var splitter = child._splitterWidget; |
| 356 |
if(splitter){ |
| 357 |
splitter.destroy(); |
| 358 |
delete child._splitterWidget; |
| 359 |
} |
| 360 |
|
| 361 |
this.inherited(arguments); |
| 362 |
}, |
| 363 |
|
| 364 |
getChildren: function(){ |
| 365 |
|
| 366 |
return array.filter(this.inherited(arguments), function(widget){ |
| 367 |
return !widget.isSplitter; |
| 368 |
}); |
| 369 |
}, |
| 370 |
|
| 371 |
|
| 372 |
getSplitter: function(region){ |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
return array.filter(this.getChildren(), function(child){ |
| 378 |
return child.region == region; |
| 379 |
})[0]._splitterWidget; |
| 380 |
}, |
| 381 |
|
| 382 |
resize: function(newSize, currentSize){ |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
if(!this.cs || !this.pe){ |
| 388 |
var node = this.domNode; |
| 389 |
this.cs = domStyle.getComputedStyle(node); |
| 390 |
this.pe = domGeometry.getPadExtents(node, this.cs); |
| 391 |
this.pe.r = domStyle.toPixelValue(node, this.cs.paddingRight); |
| 392 |
this.pe.b = domStyle.toPixelValue(node, this.cs.paddingBottom); |
| 393 |
|
| 394 |
domStyle.set(node, "padding", "0px"); |
| 395 |
} |
| 396 |
|
| 397 |
this.inherited(arguments); |
| 398 |
}, |
| 399 |
|
| 400 |
_layoutChildren: function( changedChildId, changedChildSize){ |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
if(!this._borderBox || !this._borderBox.h){ |
| 416 |
|
| 417 |
|
| 418 |
return; |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
var childrenAndSplitters = []; |
| 423 |
array.forEach(this._getOrderedChildren(), function(pane){ |
| 424 |
childrenAndSplitters.push(pane); |
| 425 |
if(pane._splitterWidget){ |
| 426 |
childrenAndSplitters.push(pane._splitterWidget); |
| 427 |
} |
| 428 |
}); |
| 429 |
|
| 430 |
|
| 431 |
var dim = { |
| 432 |
l: this.pe.l, |
| 433 |
t: this.pe.t, |
| 434 |
w: this._borderBox.w - this.pe.w, |
| 435 |
h: this._borderBox.h - this.pe.h |
| 436 |
}; |
| 437 |
|
| 438 |
|
| 439 |
layoutUtils.layoutChildren(this.domNode, dim, childrenAndSplitters, |
| 440 |
changedChildId, changedChildSize); |
| 441 |
}, |
| 442 |
|
| 443 |
destroyRecursive: function(){ |
| 444 |
|
| 445 |
array.forEach(this.getChildren(), function(child){ |
| 446 |
var splitter = child._splitterWidget; |
| 447 |
if(splitter){ |
| 448 |
splitter.destroy(); |
| 449 |
} |
| 450 |
delete child._splitterWidget; |
| 451 |
}); |
| 452 |
|
| 453 |
|
| 454 |
this.inherited(arguments); |
| 455 |
} |
| 456 |
}); |
| 457 |
|
| 458 |
BorderContainer.ChildWidgetProperties = { |
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
splitter: false, |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
minSize: 0, |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
maxSize: Infinity |
| 475 |
}; |
| 476 |
lang.mixin(BorderContainer.ChildWidgetProperties, LayoutContainer.ChildWidgetProperties); |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
lang.extend(_WidgetBase, BorderContainer.ChildWidgetProperties); |
| 482 |
|
| 483 |
|
| 484 |
BorderContainer._Splitter = _Splitter; |
| 485 |
BorderContainer._Gutter = _Gutter; |
| 486 |
|
| 487 |
return BorderContainer; |
| 488 |
}); |