Roo/bootstrap/layout/Manager.js
[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.util.Observable
15  * Base class for layout managers.
16  */
17 Roo.bootstrap.layout.Manager = function(config)
18 {
19     Roo.bootstrap.layout.Manager.superclass.constructor.call(this);
20     this.el = Roo.get(config.el);
21     // ie scrollbar fix
22     if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
23         document.body.scroll = "no";
24     }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
25         this.el.position('relative');
26     }
27     
28     this.id = this.el.id;
29     this.el.addClass("roo-layout-container");
30     /** false to disable window resize monitoring @type Boolean */
31     this.monitorWindowResize = true;
32     this.regions = {};
33     this.addEvents({
34         /**
35          * @event layout
36          * Fires when a layout is performed. 
37          * @param {Roo.LayoutManager} this
38          */
39         "layout" : true,
40         /**
41          * @event regionresized
42          * Fires when the user resizes a region. 
43          * @param {Roo.LayoutRegion} region The resized region
44          * @param {Number} newSize The new size (width for east/west, height for north/south)
45          */
46         "regionresized" : true,
47         /**
48          * @event regioncollapsed
49          * Fires when a region is collapsed. 
50          * @param {Roo.LayoutRegion} region The collapsed region
51          */
52         "regioncollapsed" : true,
53         /**
54          * @event regionexpanded
55          * Fires when a region is expanded.  
56          * @param {Roo.LayoutRegion} region The expanded region
57          */
58         "regionexpanded" : true
59     });
60     this.updating = false;
61     Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
62 };
63
64 Roo.extend(Roo.bootstrap.layout.Manager, Roo.util.Observable, {
65     
66     
67     regions : null,
68     
69     monitorWindowResize : true,
70     
71     
72     updating : false,
73     
74     /**
75      * Returns true if this layout is currently being updated
76      * @return {Boolean}
77      */
78     isUpdating : function(){
79         return this.updating; 
80     },
81     
82     /**
83      * Suspend the LayoutManager from doing auto-layouts while
84      * making multiple add or remove calls
85      */
86     beginUpdate : function(){
87         this.updating = true;    
88     },
89     
90     /**
91      * Restore auto-layouts and optionally disable the manager from performing a layout
92      * @param {Boolean} noLayout true to disable a layout update 
93      */
94     endUpdate : function(noLayout){
95         this.updating = false;
96         if(!noLayout){
97             this.layout();
98         }    
99     },
100     
101     layout: function(){
102         // abstract...
103     },
104     
105     onRegionResized : function(region, newSize){
106         this.fireEvent("regionresized", region, newSize);
107         this.layout();
108     },
109     
110     onRegionCollapsed : function(region){
111         this.fireEvent("regioncollapsed", region);
112     },
113     
114     onRegionExpanded : function(region){
115         this.fireEvent("regionexpanded", region);
116     },
117         
118     /**
119      * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
120      * performs box-model adjustments.
121      * @return {Object} The size as an object {width: (the width), height: (the height)}
122      */
123     getViewSize : function(){
124         var size;
125         if(this.el.dom != document.body){
126             size = this.el.getSize();
127         }else{
128             size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
129         }
130         size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
131         size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
132         return size;
133     },
134     
135     /**
136      * Returns the Element this layout is bound to.
137      * @return {Roo.Element}
138      */
139     getEl : function(){
140         return this.el;
141     },
142     
143     /**
144      * Returns the specified region.
145      * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
146      * @return {Roo.LayoutRegion}
147      */
148     getRegion : function(target){
149         return this.regions[target.toLowerCase()];
150     },
151     
152     onWindowResize : function(){
153         if(this.monitorWindowResize){
154             this.layout();
155         }
156     }
157 });