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