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