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