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