3
* Copyright(c) 2006-2008, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.LayoutRegion
11
* @extends Ext.BasicLayoutRegion
12
* This class represents a region in a layout manager.
13
* @cfg {Boolean} collapsible False to disable collapsing (defaults to true)
14
* @cfg {Boolean} collapsed True to set the initial display to collapsed (defaults to false)
15
* @cfg {Boolean} floatable False to disable floating (defaults to true)
16
* @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
17
* @cfg {Object} cmargins Margins for the element when collapsed (defaults to: north/south {top: 2, left: 0, right:0, bottom: 2} or east/west {top: 0, left: 2, right:2, bottom: 0})
18
* @cfg {String} tabPosition "top" or "bottom" (defaults to "bottom")
19
* @cfg {String} collapsedTitle Optional string message to display in the collapsed block of a north or south region
20
* @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
21
* @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
22
* @cfg {Boolean} titlebar True to display a title bar (defaults to true)
23
* @cfg {String} title The title for the region (overrides panel titles)
24
* @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
25
* @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
26
* @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
27
* @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
28
* @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
29
* @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
30
* the space available, similar to FireFox 1.5 tabs (defaults to false)
31
* @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
32
* @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
33
* @cfg {Boolean} showPin True to show a pin button
34
* @cfg {Boolean} hidden True to start the region hidden (defaults to false)
35
* @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
36
* @cfg {Boolean} disableTabTips True to disable tab tooltips
38
Ext.LayoutRegion = function(mgr, config, pos){
39
Ext.LayoutRegion.superclass.constructor.call(this, mgr, config, pos, true);
40
var dh = Ext.DomHelper;
41
/** This region's container element @type Ext.Element */
42
this.el = dh.append(mgr.el.dom, {tag: "div", cls: "x-layout-panel x-layout-panel-" + this.position}, true);
43
/** This region's title element @type Ext.Element */
45
this.titleEl = dh.append(this.el.dom, {tag: "div", unselectable: "on", cls: "x-unselectable x-layout-panel-hd x-layout-title-"+this.position, children:[
46
{tag: "span", cls: "x-unselectable x-layout-panel-hd-text", unselectable: "on", html: " "},
47
{tag: "div", cls: "x-unselectable x-layout-panel-hd-tools", unselectable: "on"}
49
this.titleEl.enableDisplayMode();
50
/** This region's title text element @type HTMLElement */
51
this.titleTextEl = this.titleEl.dom.firstChild;
52
this.tools = Ext.get(this.titleEl.dom.childNodes[1], true);
53
this.closeBtn = this.createTool(this.tools.dom, "x-layout-close");
54
this.closeBtn.enableDisplayMode();
55
this.closeBtn.on("click", this.closeClicked, this);
58
this.createBody(config);
60
this.collapsed = false;
62
if(config.hideWhenEmpty){
64
this.on("paneladded", this.validateVisibility, this);
65
this.on("panelremoved", this.validateVisibility, this);
67
this.applyConfig(config);
70
Ext.extend(Ext.LayoutRegion, Ext.BasicLayoutRegion, {
72
createBody : function(){
73
/** This region's body element @type Ext.Element */
74
this.bodyEl = this.el.createChild({tag: "div", cls: "x-layout-panel-body"});
77
applyConfig : function(c){
78
if(c.collapsible && this.position != "center" && !this.collapsedEl){
79
var dh = Ext.DomHelper;
80
if(c.titlebar !== false){
81
this.collapseBtn = this.createTool(this.tools.dom, "x-layout-collapse-"+this.position);
82
this.collapseBtn.on("click", this.collapse, this);
83
this.collapseBtn.enableDisplayMode();
85
if(c.showPin === true || this.showPin){
86
this.stickBtn = this.createTool(this.tools.dom, "x-layout-stick");
87
this.stickBtn.enableDisplayMode();
88
this.stickBtn.on("click", this.expand, this);
92
/** This region's collapsed element @type Ext.Element */
93
this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
94
{cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
96
if(c.floatable !== false){
97
this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
98
this.collapsedEl.on("click", this.collapseClick, this);
101
if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
102
this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
103
id: "message", unselectable: "on", style:{"float":"left"}});
104
this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
106
this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
107
this.expandBtn.on("click", this.expand, this);
109
if(this.collapseBtn){
110
this.collapseBtn.setVisible(c.collapsible == true);
112
this.cmargins = c.cmargins || this.cmargins ||
113
(this.position == "west" || this.position == "east" ?
114
{top: 0, left: 2, right:2, bottom: 0} :
115
{top: 2, left: 0, right:0, bottom: 2});
116
this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
117
this.bottomTabs = c.tabPosition != "top";
118
this.autoScroll = c.autoScroll || false;
120
this.bodyEl.setStyle("overflow", "auto");
122
this.bodyEl.setStyle("overflow", "hidden");
124
//if(c.titlebar !== false){
125
if((!c.titlebar && !c.title) || c.titlebar === false){
130
this.titleTextEl.innerHTML = c.title;
134
this.duration = c.duration || .30;
135
this.slideDuration = c.slideDuration || .45;
145
* Returns true if this region is currently visible.
148
isVisible : function(){
153
* Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
154
* @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, " ")
156
setCollapsedTitle : function(title){
157
title = title || " ";
158
if(this.collapsedTitleTextEl){
159
this.collapsedTitleTextEl.innerHTML = title;
166
b = this.el.getBox(false, true);
168
b = this.collapsedEl.getBox(false, true);
173
getMargins : function(){
174
return this.collapsed ? this.cmargins : this.margins;
177
highlight : function(){
178
this.el.addClass("x-layout-panel-dragover");
181
unhighlight : function(){
182
this.el.removeClass("x-layout-panel-dragover");
185
updateBox : function(box){
188
this.el.dom.style.left = box.x + "px";
189
this.el.dom.style.top = box.y + "px";
190
this.updateBody(box.width, box.height);
192
this.collapsedEl.dom.style.left = box.x + "px";
193
this.collapsedEl.dom.style.top = box.y + "px";
194
this.collapsedEl.setSize(box.width, box.height);
197
this.tabs.autoSizeTabs();
201
updateBody : function(w, h){
204
w -= this.el.getBorderWidth("rl");
205
if(this.config.adjustments){
206
w += this.config.adjustments[0];
210
this.el.setHeight(h);
211
h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
212
h -= this.el.getBorderWidth("tb");
213
if(this.config.adjustments){
214
h += this.config.adjustments[1];
216
this.bodyEl.setHeight(h);
218
h = this.tabs.syncHeight(h);
222
w = w !== null ? w : this.panelSize.width;
223
h = h !== null ? h : this.panelSize.height;
225
if(this.activePanel){
226
var el = this.activePanel.getEl();
227
w = w !== null ? w : el.getWidth();
228
h = h !== null ? h : el.getHeight();
229
this.panelSize = {width: w, height: h};
230
this.activePanel.setSize(w, h);
232
if(Ext.isIE && this.tabs){
233
this.tabs.el.repaint();
238
* Returns the container element for this region.
239
* @return {Ext.Element}
250
this.el.dom.style.left = "-2000px";
253
this.collapsedEl.dom.style.left = "-2000px";
254
this.collapsedEl.hide();
256
this.visible = false;
257
this.fireEvent("visibilitychange", this, false);
261
* Shows this region if it was previously hidden.
267
this.collapsedEl.show();
270
this.fireEvent("visibilitychange", this, true);
273
closeClicked : function(){
274
if(this.activePanel){
275
this.remove(this.activePanel);
279
collapseClick : function(e){
290
* Collapses this region.
291
* @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
293
collapse : function(skipAnim){
294
if(this.collapsed) return;
295
this.collapsed = true;
297
this.split.el.hide();
299
if(this.config.animate && skipAnim !== true){
300
this.fireEvent("invalidated", this);
301
this.animateCollapse();
303
this.el.setLocation(-20000,-20000);
305
this.collapsedEl.show();
306
this.fireEvent("collapsed", this);
307
this.fireEvent("invalidated", this);
311
animateCollapse : function(){
316
* Expands this region if it was previously collapsed.
317
* @param {Ext.EventObject} e The event that triggered the expand (or null if calling manually)
318
* @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
320
expand : function(e, skipAnim){
321
if(e) e.stopPropagation();
322
if(!this.collapsed || this.el.hasActiveFx()) return;
327
this.collapsed = false;
328
if(this.config.animate && skipAnim !== true){
329
this.animateExpand();
333
this.split.el.show();
335
this.collapsedEl.setLocation(-2000,-2000);
336
this.collapsedEl.hide();
337
this.fireEvent("invalidated", this);
338
this.fireEvent("expanded", this);
342
animateExpand : function(){
346
initTabs : function(){
347
this.bodyEl.setStyle("overflow", "hidden");
348
var ts = new Ext.TabPanel(this.bodyEl.dom, {
349
tabPosition: this.bottomTabs ? 'bottom' : 'top',
350
disableTooltips: this.config.disableTabTips
352
if(this.config.hideTabs){
353
ts.stripWrap.setDisplayed(false);
356
ts.resizeTabs = this.config.resizeTabs === true;
357
ts.minTabWidth = this.config.minTabWidth || 40;
358
ts.maxTabWidth = this.config.maxTabWidth || 250;
359
ts.preferredTabWidth = this.config.preferredTabWidth || 150;
360
ts.monitorResize = false;
361
ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
362
ts.bodyEl.addClass('x-layout-tabs-body');
363
this.panels.each(this.initPanelAsTab, this);
366
initPanelAsTab : function(panel){
367
var ti = this.tabs.addTab(panel.getEl().id, panel.getTitle(), null,
368
this.config.closeOnTab && panel.isClosable());
369
if(panel.tabTip !== undefined){
370
ti.setTooltip(panel.tabTip);
372
ti.on("activate", function(){
373
this.setActivePanel(panel);
375
if(this.config.closeOnTab){
376
ti.on("beforeclose", function(t, e){
384
updatePanelTitle : function(panel, title){
385
if(this.activePanel == panel){
386
this.updateTitle(title);
389
var ti = this.tabs.getTab(panel.getEl().id);
391
if(panel.tabTip !== undefined){
392
ti.setTooltip(panel.tabTip);
397
updateTitle : function(title){
398
if(this.titleTextEl && !this.config.title){
399
this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
403
setActivePanel : function(panel){
404
panel = this.getPanel(panel);
405
if(this.activePanel && this.activePanel != panel){
406
this.activePanel.setActiveState(false);
408
this.activePanel = panel;
409
panel.setActiveState(true);
411
panel.setSize(this.panelSize.width, this.panelSize.height);
414
this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
416
this.updateTitle(panel.getTitle());
418
this.fireEvent("invalidated", this);
420
this.fireEvent("panelactivated", this, panel);
424
* Shows the specified panel.
425
* @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
426
* @return {Ext.ContentPanel} The shown panel, or null if a panel could not be found from panelId
428
showPanel : function(panel){
429
if(panel = this.getPanel(panel)){
431
var tab = this.tabs.getTab(panel.getEl().id);
433
this.tabs.unhideTab(tab.id);
437
this.setActivePanel(panel);
444
* Get the active panel for this region.
445
* @return {Ext.ContentPanel} The active panel or null
447
getActivePanel : function(){
448
return this.activePanel;
451
validateVisibility : function(){
452
if(this.panels.getCount() < 1){
453
this.updateTitle(" ");
454
this.closeBtn.hide();
457
if(!this.isVisible()){
464
* Adds the passed ContentPanel(s) to this region.
465
* @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
466
* @return {Ext.ContentPanel} The panel added (if only one was added; null otherwise)
468
add : function(panel){
469
if(arguments.length > 1){
470
for(var i = 0, len = arguments.length; i < len; i++) {
471
this.add(arguments[i]);
475
if(this.hasPanel(panel)){
476
this.showPanel(panel);
479
panel.setRegion(this);
480
this.panels.add(panel);
481
if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
482
this.bodyEl.dom.appendChild(panel.getEl().dom);
483
if(panel.background !== true){
484
this.setActivePanel(panel);
486
this.fireEvent("paneladded", this, panel);
492
this.initPanelAsTab(panel);
494
if(panel.background !== true){
495
this.tabs.activate(panel.getEl().id);
497
this.fireEvent("paneladded", this, panel);
502
* Hides the tab for the specified panel.
503
* @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
505
hidePanel : function(panel){
506
if(this.tabs && (panel = this.getPanel(panel))){
507
this.tabs.hideTab(panel.getEl().id);
512
* Unhides the tab for a previously hidden panel.
513
* @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
515
unhidePanel : function(panel){
516
if(this.tabs && (panel = this.getPanel(panel))){
517
this.tabs.unhideTab(panel.getEl().id);
521
clearPanels : function(){
522
while(this.panels.getCount() > 0){
523
this.remove(this.panels.first());
528
* Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
529
* @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
530
* @param {Boolean} preservePanel Overrides the config preservePanel option
531
* @return {Ext.ContentPanel} The panel that was removed
533
remove : function(panel, preservePanel){
534
panel = this.getPanel(panel);
539
this.fireEvent("beforeremove", this, panel, e);
540
if(e.cancel === true){
543
preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
544
var panelId = panel.getId();
545
this.panels.removeKey(panelId);
547
document.body.appendChild(panel.getEl().dom);
550
this.tabs.removeTab(panel.getEl().id);
551
}else if (!preservePanel){
552
this.bodyEl.dom.removeChild(panel.getEl().dom);
554
if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
555
var p = this.panels.first();
556
var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
557
tempEl.appendChild(p.getEl().dom);
558
this.bodyEl.update("");
559
this.bodyEl.dom.appendChild(p.getEl().dom);
561
this.updateTitle(p.getTitle());
563
this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
564
this.setActivePanel(p);
566
panel.setRegion(null);
567
if(this.activePanel == panel){
568
this.activePanel = null;
570
if(this.config.autoDestroy !== false && preservePanel !== true){
571
try{panel.destroy();}catch(e){}
573
this.fireEvent("panelremoved", this, panel);
578
* Returns the TabPanel component used by this region
579
* @return {Ext.TabPanel}
581
getTabs : function(){
585
createTool : function(parentEl, className){
586
var btn = Ext.DomHelper.append(parentEl, {tag: "div", cls: "x-layout-tools-button",
587
children: [{tag: "div", cls: "x-layout-tools-button-inner " + className, html: " "}]}, true);
588
btn.addClassOnOver("x-layout-tools-button-over");
b'\\ No newline at end of file'