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