]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/layout/SplitContainer.js
2 Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo
._hasResource
["dijit.layout.SplitContainer"]){
9 dojo
._hasResource
["dijit.layout.SplitContainer"]=true;
10 dojo
.provide("dijit.layout.SplitContainer");
11 dojo
.require("dojo.cookie");
12 dojo
.require("dijit.layout._LayoutWidget");
13 dojo
.declare("dijit.layout.SplitContainer",dijit
.layout
._LayoutWidget
,{constructor:function(){
14 dojo
.deprecated("dijit.layout.SplitContainer is deprecated","use BorderContainer with splitter instead",2);
15 },activeSizing
:false,sizerWidth
:7,orientation
:"horizontal",persist
:true,baseClass
:"dijitSplitContainer",postMixInProperties:function(){
16 this.inherited("postMixInProperties",arguments
);
17 this.isHorizontal
=(this.orientation
=="horizontal");
18 },postCreate:function(){
19 this.inherited(arguments
);
22 this.domNode
.style
.overflow
="-moz-scrollbars-none";
24 if(typeof this.sizerWidth
=="object"){
26 this.sizerWidth
=parseInt(this.sizerWidth
.toString());
32 var _1
=dojo
.doc
.createElement("div");
34 _1
.style
.position
="relative";
36 _1
.className
=this.isHorizontal
?"dijitSplitContainerVirtualSizerH":"dijitSplitContainerVirtualSizerV";
37 this.domNode
.appendChild(_1
);
38 dojo
.setSelectable(_1
,false);
40 delete this.virtualSizer
;
41 dojo
.forEach(this._ownconnects
,dojo
.disconnect
);
42 this.inherited(arguments
);
47 dojo
.forEach(this.getChildren(),function(_2
,i
,_3
){
56 this.inherited(arguments
);
57 },_setupChild:function(_4
){
58 this.inherited(arguments
);
59 _4
.domNode
.style
.position
="absolute";
60 dojo
.addClass(_4
.domNode
,"dijitSplitPane");
61 },_onSizerMouseDown:function(e
){
63 for(var i
=0;i
<this.sizers
.length
;i
++){
64 if(this.sizers
[i
].id
==e
.target
.id
){
68 if(i
<this.sizers
.length
){
69 this.beginSizing(e
,i
);
72 },_addSizer:function(_5
){
73 _5
=_5
===undefined?this.sizers
.length
:_5
;
74 var _6
=dojo
.doc
.createElement("div");
75 _6
.id
=dijit
.getUniqueId("dijit_layout_SplitterContainer_Splitter");
76 this.sizers
.splice(_5
,0,_6
);
77 this.domNode
.appendChild(_6
);
78 _6
.className
=this.isHorizontal
?"dijitSplitContainerSizerH":"dijitSplitContainerSizerV";
79 var _7
=dojo
.doc
.createElement("div");
82 this.connect(_6
,"onmousedown","_onSizerMouseDown");
83 dojo
.setSelectable(_6
,false);
84 },removeChild:function(_8
){
85 if(this.sizers
.length
){
86 var i
=dojo
.indexOf(this.getChildren(),_8
);
88 if(i
==this.sizers
.length
){
91 dojo
.destroy(this.sizers
[i
]);
92 this.sizers
.splice(i
,1);
95 this.inherited(arguments
);
99 },addChild:function(_9
,_a
){
100 this.inherited(arguments
);
102 var _b
=this.getChildren();
109 this.paneWidth
=this._contentBox
.w
;
110 this.paneHeight
=this._contentBox
.h
;
111 var _c
=this.getChildren();
115 var _d
=this.isHorizontal
?this.paneWidth
:this.paneHeight
;
117 _d
-=this.sizerWidth
*(_c
.length
-1);
120 dojo
.forEach(_c
,function(_f
){
125 dojo
.forEach(_c
.slice(0,_c
.length
-1),function(_12
){
126 var _13
=Math
.round(_10
*_12
.sizeShare
);
130 _c
[_c
.length
-1].sizeActual
=_d
-_11
;
133 var _14
=_c
[0].sizeActual
;
134 this._movePanel(_c
[0],pos
,_14
);
140 dojo
.some(_c
.slice(1),function(_15
,i
){
144 this._moveSlider(this.sizers
[i
],pos
,this.sizerWidth
);
145 this.sizers
[i
].position
=pos
;
146 pos
+=this.sizerWidth
;
148 this._movePanel(_15
,pos
,_14
);
152 },_movePanel:function(_16
,pos
,_17
){
153 if(this.isHorizontal
){
154 _16
.domNode
.style
.left
=pos
+"px";
155 _16
.domNode
.style
.top
=0;
156 var box
={w
:_17
,h
:this.paneHeight
};
160 dojo
.marginBox(_16
.domNode
,box
);
163 _16
.domNode
.style
.left
=0;
164 _16
.domNode
.style
.top
=pos
+"px";
165 var box
={w
:this.paneWidth
,h
:_17
};
169 dojo
.marginBox(_16
.domNode
,box
);
172 },_moveSlider:function(_18
,pos
,_19
){
173 if(this.isHorizontal
){
174 _18
.style
.left
=pos
+"px";
176 dojo
.marginBox(_18
,{w
:_19
,h
:this.paneHeight
});
179 _18
.style
.top
=pos
+"px";
180 dojo
.marginBox(_18
,{w
:this.paneWidth
,h
:_19
});
182 },_growPane:function(_1a
,_1b
){
184 if(_1b
.sizeActual
>_1b
.sizeMin
){
185 if((_1b
.sizeActual
-_1b
.sizeMin
)>_1a
){
186 _1b
.sizeActual
=_1b
.sizeActual
-_1a
;
189 _1a
-=_1b
.sizeActual
-_1b
.sizeMin
;
190 _1b
.sizeActual
=_1b
.sizeMin
;
195 },_checkSizes:function(){
198 var _1e
=this.getChildren();
199 dojo
.forEach(_1e
,function(_1f
){
205 dojo
.forEach(_1e
,function(_21
){
206 if(_21
.sizeActual
<_21
.sizeMin
){
207 _20
+=_21
.sizeMin
-_21
.sizeActual
;
208 _21
.sizeActual
=_21
.sizeMin
;
212 var _22
=this.isDraggingLeft
?_1e
.reverse():_1e
;
213 dojo
.forEach(_22
,function(_23
){
214 _20
=this._growPane(_20
,_23
);
218 dojo
.forEach(_1e
,function(_24
){
219 _24
.sizeActual
=Math
.round(_1d
*(_24
.sizeMin
/_1c
));
222 },beginSizing:function(e
,i
){
223 var _25
=this.getChildren();
224 this.paneBefore
=_25
[i
];
225 this.paneAfter
=_25
[i
+1];
227 this.sizingSplitter
=this.sizers
[i
];
229 this.cover
=dojo
.create("div",{style
:{position
:"absolute",zIndex
:5,top
:0,left
:0,width
:"100%",height
:"100%"}},this.domNode
);
231 this.cover
.style
.zIndex
=5;
233 this.sizingSplitter
.style
.zIndex
=6;
234 this.originPos
=dojo
.position(_25
[0].domNode
,true);
235 if(this.isHorizontal
){
236 var _26
=e
.layerX
||e
.offsetX
||0;
238 this.originPos
=this.originPos
.x
;
240 var _26
=e
.layerY
||e
.offsetY
||0;
242 this.originPos
=this.originPos
.y
;
244 this.startPoint
=this.lastPoint
=_27
;
245 this.screenToClientOffset
=_27
-_26
;
246 this.dragOffset
=this.lastPoint
-this.paneBefore
.sizeActual
-this.originPos
-this.paneBefore
.position
;
247 if(!this.activeSizing
){
248 this._showSizingLine();
250 this._ownconnects
=[];
251 this._ownconnects
.push(dojo
.connect(dojo
.doc
.documentElement
,"onmousemove",this,"changeSizing"));
252 this._ownconnects
.push(dojo
.connect(dojo
.doc
.documentElement
,"onmouseup",this,"endSizing"));
254 },changeSizing:function(e
){
258 this.lastPoint
=this.isHorizontal
?e
.pageX
:e
.pageY
;
260 if(this.activeSizing
){
263 this._moveSizingLine();
266 },endSizing:function(e
){
271 this.cover
.style
.zIndex
=-1;
273 if(!this.activeSizing
){
274 this._hideSizingLine();
279 this._saveState(this);
281 dojo
.forEach(this._ownconnects
,dojo
.disconnect
);
282 },movePoint:function(){
283 var p
=this.lastPoint
-this.screenToClientOffset
;
284 var a
=p
-this.dragOffset
;
285 a
=this.legaliseSplitPoint(a
);
287 this.lastPoint
=p
+this.screenToClientOffset
;
288 },legaliseSplitPoint:function(a
){
289 a
+=this.sizingSplitter
.position
;
290 this.isDraggingLeft
=!!(a
>0);
291 if(!this.activeSizing
){
292 var min
=this.paneBefore
.position
+this.paneBefore
.sizeMin
;
296 var max
=this.paneAfter
.position
+(this.paneAfter
.sizeActual
-(this.sizerWidth
+this.paneAfter
.sizeMin
));
301 a
-=this.sizingSplitter
.position
;
304 },_updateSize:function(){
305 var pos
=this.lastPoint
-this.dragOffset
-this.originPos
;
306 var _28
=this.paneBefore
.position
;
307 var _29
=this.paneAfter
.position
+this.paneAfter
.sizeActual
;
308 this.paneBefore
.sizeActual
=pos
-_28
;
309 this.paneAfter
.position
=pos
+this.sizerWidth
;
310 this.paneAfter
.sizeActual
=_29
-this.paneAfter
.position
;
311 dojo
.forEach(this.getChildren(),function(_2a
){
312 _2a
.sizeShare
=_2a
.sizeActual
;
317 },_showSizingLine:function(){
318 this._moveSizingLine();
319 dojo
.marginBox(this.virtualSizer
,this.isHorizontal
?{w
:this.sizerWidth
,h
:this.paneHeight
}:{w
:this.paneWidth
,h
:this.sizerWidth
});
320 this.virtualSizer
.style
.display
="block";
321 },_hideSizingLine:function(){
322 this.virtualSizer
.style
.display
="none";
323 },_moveSizingLine:function(){
324 var pos
=(this.lastPoint
-this.startPoint
)+this.sizingSplitter
.position
;
325 dojo
.style(this.virtualSizer
,(this.isHorizontal
?"left":"top"),pos
+"px");
326 },_getCookieName:function(i
){
327 return this.id
+"_"+i
;
328 },_restoreState:function(){
329 dojo
.forEach(this.getChildren(),function(_2b
,i
){
330 var _2c
=this._getCookieName(i
);
331 var _2d
=dojo
.cookie(_2c
);
333 var pos
=parseInt(_2d
);
334 if(typeof pos
=="number"){
339 },_saveState:function(){
343 dojo
.forEach(this.getChildren(),function(_2e
,i
){
344 dojo
.cookie(this._getCookieName(i
),_2e
.sizeShare
,{expires
:365});
347 dojo
.extend(dijit
._Widget
,{sizeMin
:10,sizeShare
:10});