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