initial import
[roojs1] / Roo / SplitLayoutRegion.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
14 /**
15  * @class Roo.SplitLayoutRegion
16  * @extends Roo.LayoutRegion
17  * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
18  */
19 Roo.SplitLayoutRegion = function(mgr, config, pos, cursor){
20     this.cursor = cursor;
21     Roo.SplitLayoutRegion.superclass.constructor.call(this, mgr, config, pos);
22 };
23
24 Roo.extend(Roo.SplitLayoutRegion, Roo.LayoutRegion, {
25     splitTip : "Drag to resize.",
26     collapsibleSplitTip : "Drag to resize. Double click to hide.",
27     useSplitTips : false,
28
29     applyConfig : function(config){
30         Roo.SplitLayoutRegion.superclass.applyConfig.call(this, config);
31         if(config.split){
32             if(!this.split){
33                 var splitEl = Roo.DomHelper.append(this.mgr.el.dom, 
34                         {tag: "div", id: this.el.id + "-split", cls: "x-layout-split x-layout-split-"+this.position, html: "&#160;"});
35                 /** The SplitBar for this region 
36                 * @type Roo.SplitBar */
37                 this.split = new Roo.SplitBar(splitEl, this.el, this.orientation);
38                 this.split.on("moved", this.onSplitMove, this);
39                 this.split.useShim = config.useShim === true;
40                 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
41                 if(this.useSplitTips){
42                     this.split.el.dom.title = config.collapsible ? this.collapsibleSplitTip : this.splitTip;
43                 }
44                 if(config.collapsible){
45                     this.split.el.on("dblclick", this.collapse,  this);
46                 }
47             }
48             if(typeof config.minSize != "undefined"){
49                 this.split.minSize = config.minSize;
50             }
51             if(typeof config.maxSize != "undefined"){
52                 this.split.maxSize = config.maxSize;
53             }
54             if(config.hideWhenEmpty || config.hidden || config.collapsed){
55                 this.hideSplitter();
56             }
57         }
58     },
59
60     getHMaxSize : function(){
61          var cmax = this.config.maxSize || 10000;
62          var center = this.mgr.getRegion("center");
63          return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
64     },
65
66     getVMaxSize : function(){
67          var cmax = this.config.maxSize || 10000;
68          var center = this.mgr.getRegion("center");
69          return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
70     },
71
72     onSplitMove : function(split, newSize){
73         this.fireEvent("resized", this, newSize);
74     },
75     
76     /** 
77      * Returns the {@link Roo.SplitBar} for this region.
78      * @return {Roo.SplitBar}
79      */
80     getSplitBar : function(){
81         return this.split;
82     },
83     
84     hide : function(){
85         this.hideSplitter();
86         Roo.SplitLayoutRegion.superclass.hide.call(this);
87     },
88
89     hideSplitter : function(){
90         if(this.split){
91             this.split.el.setLocation(-2000,-2000);
92             this.split.el.hide();
93         }
94     },
95
96     show : function(){
97         if(this.split){
98             this.split.el.show();
99         }
100         Roo.SplitLayoutRegion.superclass.show.call(this);
101     },
102     
103     beforeSlide: function(){
104         if(Roo.isGecko){// firefox overflow auto bug workaround
105             this.bodyEl.clip();
106             if(this.tabs) this.tabs.bodyEl.clip();
107             if(this.activePanel){
108                 this.activePanel.getEl().clip();
109                 
110                 if(this.activePanel.beforeSlide){
111                     this.activePanel.beforeSlide();
112                 }
113             }
114         }
115     },
116     
117     afterSlide : function(){
118         if(Roo.isGecko){// firefox overflow auto bug workaround
119             this.bodyEl.unclip();
120             if(this.tabs) this.tabs.bodyEl.unclip();
121             if(this.activePanel){
122                 this.activePanel.getEl().unclip();
123                 if(this.activePanel.afterSlide){
124                     this.activePanel.afterSlide();
125                 }
126             }
127         }
128     },
129
130     initAutoHide : function(){
131         if(this.autoHide !== false){
132             if(!this.autoHideHd){
133                 var st = new Roo.util.DelayedTask(this.slideIn, this);
134                 this.autoHideHd = {
135                     "mouseout": function(e){
136                         if(!e.within(this.el, true)){
137                             st.delay(500);
138                         }
139                     },
140                     "mouseover" : function(e){
141                         st.cancel();
142                     },
143                     scope : this
144                 };
145             }
146             this.el.on(this.autoHideHd);
147         }
148     },
149
150     clearAutoHide : function(){
151         if(this.autoHide !== false){
152             this.el.un("mouseout", this.autoHideHd.mouseout);
153             this.el.un("mouseover", this.autoHideHd.mouseover);
154         }
155     },
156
157     clearMonitor : function(){
158         Roo.get(document).un("click", this.slideInIf, this);
159     },
160
161     // these names are backwards but not changed for compat
162     slideOut : function(){
163         if(this.isSlid || this.el.hasActiveFx()){
164             return;
165         }
166         this.isSlid = true;
167         if(this.collapseBtn){
168             this.collapseBtn.hide();
169         }
170         this.closeBtnState = this.closeBtn.getStyle('display');
171         this.closeBtn.hide();
172         if(this.stickBtn){
173             this.stickBtn.show();
174         }
175         this.el.show();
176         this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
177         this.beforeSlide();
178         this.el.setStyle("z-index", 10001);
179         this.el.slideIn(this.getSlideAnchor(), {
180             callback: function(){
181                 this.afterSlide();
182                 this.initAutoHide();
183                 Roo.get(document).on("click", this.slideInIf, this);
184                 this.fireEvent("slideshow", this);
185             },
186             scope: this,
187             block: true
188         });
189     },
190
191     afterSlideIn : function(){
192         this.clearAutoHide();
193         this.isSlid = false;
194         this.clearMonitor();
195         this.el.setStyle("z-index", "");
196         if(this.collapseBtn){
197             this.collapseBtn.show();
198         }
199         this.closeBtn.setStyle('display', this.closeBtnState);
200         if(this.stickBtn){
201             this.stickBtn.hide();
202         }
203         this.fireEvent("slidehide", this);
204     },
205
206     slideIn : function(cb){
207         if(!this.isSlid || this.el.hasActiveFx()){
208             Roo.callback(cb);
209             return;
210         }
211         this.isSlid = false;
212         this.beforeSlide();
213         this.el.slideOut(this.getSlideAnchor(), {
214             callback: function(){
215                 this.el.setLeftTop(-10000, -10000);
216                 this.afterSlide();
217                 this.afterSlideIn();
218                 Roo.callback(cb);
219             },
220             scope: this,
221             block: true
222         });
223     },
224     
225     slideInIf : function(e){
226         if(!e.within(this.el)){
227             this.slideIn();
228         }
229     },
230
231     animateCollapse : function(){
232         this.beforeSlide();
233         this.el.setStyle("z-index", 20000);
234         var anchor = this.getSlideAnchor();
235         this.el.slideOut(anchor, {
236             callback : function(){
237                 this.el.setStyle("z-index", "");
238                 this.collapsedEl.slideIn(anchor, {duration:.3});
239                 this.afterSlide();
240                 this.el.setLocation(-10000,-10000);
241                 this.el.hide();
242                 this.fireEvent("collapsed", this);
243             },
244             scope: this,
245             block: true
246         });
247     },
248
249     animateExpand : function(){
250         this.beforeSlide();
251         this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
252         this.el.setStyle("z-index", 20000);
253         this.collapsedEl.hide({
254             duration:.1
255         });
256         this.el.slideIn(this.getSlideAnchor(), {
257             callback : function(){
258                 this.el.setStyle("z-index", "");
259                 this.afterSlide();
260                 if(this.split){
261                     this.split.el.show();
262                 }
263                 this.fireEvent("invalidated", this);
264                 this.fireEvent("expanded", this);
265             },
266             scope: this,
267             block: true
268         });
269     },
270
271     anchors : {
272         "west" : "left",
273         "east" : "right",
274         "north" : "top",
275         "south" : "bottom"
276     },
277
278     sanchors : {
279         "west" : "l",
280         "east" : "r",
281         "north" : "t",
282         "south" : "b"
283     },
284
285     canchors : {
286         "west" : "tl-tr",
287         "east" : "tr-tl",
288         "north" : "tl-bl",
289         "south" : "bl-tl"
290     },
291
292     getAnchor : function(){
293         return this.anchors[this.position];
294     },
295
296     getCollapseAnchor : function(){
297         return this.canchors[this.position];
298     },
299
300     getSlideAnchor : function(){
301         return this.sanchors[this.position];
302     },
303
304     getAlignAdj : function(){
305         var cm = this.cmargins;
306         switch(this.position){
307             case "west":
308                 return [0, 0];
309             break;
310             case "east":
311                 return [0, 0];
312             break;
313             case "north":
314                 return [0, 0];
315             break;
316             case "south":
317                 return [0, 0];
318             break;
319         }
320     },
321
322     getExpandAdj : function(){
323         var c = this.collapsedEl, cm = this.cmargins;
324         switch(this.position){
325             case "west":
326                 return [-(cm.right+c.getWidth()+cm.left), 0];
327             break;
328             case "east":
329                 return [cm.right+c.getWidth()+cm.left, 0];
330             break;
331             case "north":
332                 return [0, -(cm.top+cm.bottom+c.getHeight())];
333             break;
334             case "south":
335                 return [0, cm.top+cm.bottom+c.getHeight()];
336             break;
337         }
338     }
339 });