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