fix layout resize and show on dialogs
[roojs1] / Roo / bootstrap / layout / Manager.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11
12 /**
13  * @class Roo.bootstrap.layout.Manager
14  * @extends Roo.bootstrap.Component
15  * @abstract
16  * Base class for layout managers.
17  */
18 Roo.bootstrap.layout.Manager = function(config)
19 {
20     this.monitorWindowResize = true; // do this before we apply configuration.
21     
22     Roo.bootstrap.layout.Manager.superclass.constructor.call(this,config);
23
24
25
26
27
28     /** false to disable window resize monitoring @type Boolean */
29     
30     this.regions = {};
31     this.addEvents({
32         /**
33          * @event layout
34          * Fires when a layout is performed.
35          * @param {Roo.LayoutManager} this
36          */
37         "layout" : true,
38         /**
39          * @event regionresized
40          * Fires when the user resizes a region.
41          * @param {Roo.LayoutRegion} region The resized region
42          * @param {Number} newSize The new size (width for east/west, height for north/south)
43          */
44         "regionresized" : true,
45         /**
46          * @event regioncollapsed
47          * Fires when a region is collapsed.
48          * @param {Roo.LayoutRegion} region The collapsed region
49          */
50         "regioncollapsed" : true,
51         /**
52          * @event regionexpanded
53          * Fires when a region is expanded.
54          * @param {Roo.LayoutRegion} region The expanded region
55          */
56         "regionexpanded" : true
57     });
58     this.updating = false;
59
60     if (config.el) {
61         this.el = Roo.get(config.el);
62         this.initEvents();
63     }
64
65 };
66
67 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
68
69
70     regions : null,
71
72     monitorWindowResize : true,
73
74
75     updating : false,
76
77
78     onRender : function(ct, position)
79     {
80         if(!this.el){
81             this.el = Roo.get(ct);
82             this.initEvents();
83         }
84         //this.fireEvent('render',this);
85     },
86
87
88     initEvents: function()
89     {
90
91
92         // ie scrollbar fix
93         if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
94             document.body.scroll = "no";
95         }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
96             this.el.position('relative');
97         }
98         this.id = this.el.id;
99         this.el.addClass("roo-layout-container");
100         Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
101         if(this.el.dom != document.body ) {
102             this.el.on('resize', this.layout,this);
103             this.el.on('show', this.layout,this);
104         }
105
106     },
107
108     /**
109      * Returns true if this layout is currently being updated
110      * @return {Boolean}
111      */
112     isUpdating : function(){
113         return this.updating;
114     },
115
116     /**
117      * Suspend the LayoutManager from doing auto-layouts while
118      * making multiple add or remove calls
119      */
120     beginUpdate : function(){
121         this.updating = true;
122     },
123
124     /**
125      * Restore auto-layouts and optionally disable the manager from performing a layout
126      * @param {Boolean} noLayout true to disable a layout update
127      */
128     endUpdate : function(noLayout){
129         this.updating = false;
130         if(!noLayout){
131             this.layout();
132         }
133     },
134
135     layout: function(){
136         // abstract...
137     },
138
139     onRegionResized : function(region, newSize){
140         this.fireEvent("regionresized", region, newSize);
141         this.layout();
142     },
143
144     onRegionCollapsed : function(region){
145         this.fireEvent("regioncollapsed", region);
146     },
147
148     onRegionExpanded : function(region){
149         this.fireEvent("regionexpanded", region);
150     },
151
152     /**
153      * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
154      * performs box-model adjustments.
155      * @return {Object} The size as an object {width: (the width), height: (the height)}
156      */
157     getViewSize : function()
158     {
159         var size;
160         if(this.el.dom != document.body){
161             size = this.el.getSize();
162         }else{
163             size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
164         }
165         size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
166         size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
167         return size;
168     },
169
170     /**
171      * Returns the Element this layout is bound to.
172      * @return {Roo.Element}
173      */
174     getEl : function(){
175         return this.el;
176     },
177
178     /**
179      * Returns the specified region.
180      * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
181      * @return {Roo.LayoutRegion}
182      */
183     getRegion : function(target){
184         return this.regions[target.toLowerCase()];
185     },
186
187     onWindowResize : function(){
188         if(this.monitorWindowResize){
189             this.layout();
190         }
191     }
192 });