1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
1422 |
alexandre_ |
11 |
|
|
|
12 |
|
1318 |
alexandre_ |
13 |
dojo.provide("dojo.widget.SplitContainer");
|
|
|
14 |
dojo.require("dojo.widget.*");
|
|
|
15 |
dojo.require("dojo.widget.ContentPane");
|
|
|
16 |
dojo.require("dojo.widget.HtmlWidget");
|
|
|
17 |
dojo.require("dojo.html.style");
|
|
|
18 |
dojo.require("dojo.html.layout");
|
|
|
19 |
dojo.require("dojo.html.selection");
|
|
|
20 |
dojo.require("dojo.io.cookie");
|
|
|
21 |
dojo.widget.defineWidget("dojo.widget.SplitContainer", dojo.widget.HtmlWidget, function () {
|
|
|
22 |
this.sizers = [];
|
|
|
23 |
}, {isContainer:true, templateCssString:".dojoSplitContainer{\n\tposition: relative;\n\toverflow: hidden;\n\tdisplay: block;\n}\n\n.dojoSplitPane{\n\tposition: absolute;\n}\n\n.dojoSplitContainerSizerH,\n.dojoSplitContainerSizerV {\n\tfont-size: 1px;\n\tcursor: move;\n\tcursor: w-resize;\n\tbackground-color: ThreeDFace;\n\tborder: 1px solid;\n\tborder-color: ThreeDHighlight ThreeDShadow ThreeDShadow ThreeDHighlight;\n\tmargin: 0;\n}\n\n.dojoSplitContainerSizerV {\n\tcursor: n-resize;\n}\n\n.dojoSplitContainerVirtualSizerH,\n.dojoSplitContainerVirtualSizerV {\n\tfont-size: 1px;\n\tcursor: move;\n\tcursor: w-resize;\n\tbackground-color: ThreeDShadow;\n\t-moz-opacity: 0.5;\n\topacity: 0.5;\n\tfilter: Alpha(Opacity=50);\n\tmargin: 0;\n}\n\n.dojoSplitContainerVirtualSizerV {\n\tcursor: n-resize;\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/SplitContainer.css"), activeSizing:false, sizerWidth:15, orientation:"horizontal", persist:true, postMixInProperties:function () {
|
|
|
24 |
dojo.widget.SplitContainer.superclass.postMixInProperties.apply(this, arguments);
|
|
|
25 |
this.isHorizontal = (this.orientation == "horizontal");
|
|
|
26 |
}, fillInTemplate:function () {
|
|
|
27 |
dojo.widget.SplitContainer.superclass.fillInTemplate.apply(this, arguments);
|
|
|
28 |
dojo.html.addClass(this.domNode, "dojoSplitContainer");
|
|
|
29 |
if (dojo.render.html.moz) {
|
|
|
30 |
this.domNode.style.overflow = "-moz-scrollbars-none";
|
|
|
31 |
}
|
|
|
32 |
var content = dojo.html.getContentBox(this.domNode);
|
|
|
33 |
this.paneWidth = content.width;
|
|
|
34 |
this.paneHeight = content.height;
|
|
|
35 |
}, onResized:function (e) {
|
|
|
36 |
var content = dojo.html.getContentBox(this.domNode);
|
|
|
37 |
this.paneWidth = content.width;
|
|
|
38 |
this.paneHeight = content.height;
|
|
|
39 |
this._layoutPanels();
|
|
|
40 |
}, postCreate:function (args, fragment, parentComp) {
|
|
|
41 |
dojo.widget.SplitContainer.superclass.postCreate.apply(this, arguments);
|
|
|
42 |
for (var i = 0; i < this.children.length; i++) {
|
|
|
43 |
with (this.children[i].domNode.style) {
|
|
|
44 |
position = "absolute";
|
|
|
45 |
}
|
|
|
46 |
dojo.html.addClass(this.children[i].domNode, "dojoSplitPane");
|
|
|
47 |
if (i == this.children.length - 1) {
|
|
|
48 |
break;
|
|
|
49 |
}
|
|
|
50 |
this._addSizer();
|
|
|
51 |
}
|
|
|
52 |
if (typeof this.sizerWidth == "object") {
|
|
|
53 |
try {
|
|
|
54 |
this.sizerWidth = parseInt(this.sizerWidth.toString());
|
|
|
55 |
}
|
|
|
56 |
catch (e) {
|
|
|
57 |
this.sizerWidth = 15;
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
this.virtualSizer = document.createElement("div");
|
|
|
61 |
this.virtualSizer.style.position = "absolute";
|
|
|
62 |
this.virtualSizer.style.display = "none";
|
|
|
63 |
this.virtualSizer.style.zIndex = 10;
|
|
|
64 |
this.virtualSizer.className = this.isHorizontal ? "dojoSplitContainerVirtualSizerH" : "dojoSplitContainerVirtualSizerV";
|
|
|
65 |
this.domNode.appendChild(this.virtualSizer);
|
|
|
66 |
dojo.html.disableSelection(this.virtualSizer);
|
|
|
67 |
if (this.persist) {
|
|
|
68 |
this._restoreState();
|
|
|
69 |
}
|
|
|
70 |
this.resizeSoon();
|
|
|
71 |
}, _injectChild:function (child) {
|
|
|
72 |
with (child.domNode.style) {
|
|
|
73 |
position = "absolute";
|
|
|
74 |
}
|
|
|
75 |
dojo.html.addClass(child.domNode, "dojoSplitPane");
|
|
|
76 |
}, _addSizer:function () {
|
|
|
77 |
var i = this.sizers.length;
|
|
|
78 |
this.sizers[i] = document.createElement("div");
|
|
|
79 |
this.sizers[i].style.position = "absolute";
|
|
|
80 |
this.sizers[i].className = this.isHorizontal ? "dojoSplitContainerSizerH" : "dojoSplitContainerSizerV";
|
|
|
81 |
var self = this;
|
|
|
82 |
var handler = (function () {
|
|
|
83 |
var sizer_i = i;
|
|
|
84 |
return function (e) {
|
|
|
85 |
self.beginSizing(e, sizer_i);
|
|
|
86 |
};
|
|
|
87 |
})();
|
|
|
88 |
dojo.event.connect(this.sizers[i], "onmousedown", handler);
|
|
|
89 |
this.domNode.appendChild(this.sizers[i]);
|
|
|
90 |
dojo.html.disableSelection(this.sizers[i]);
|
|
|
91 |
}, removeChild:function (widget) {
|
|
|
92 |
if (this.sizers.length > 0) {
|
|
|
93 |
for (var x = 0; x < this.children.length; x++) {
|
|
|
94 |
if (this.children[x] === widget) {
|
|
|
95 |
var i = this.sizers.length - 1;
|
|
|
96 |
this.domNode.removeChild(this.sizers[i]);
|
|
|
97 |
this.sizers.length = i;
|
|
|
98 |
break;
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
dojo.widget.SplitContainer.superclass.removeChild.call(this, widget, arguments);
|
|
|
103 |
this.onResized();
|
|
|
104 |
}, addChild:function (widget) {
|
|
|
105 |
dojo.widget.SplitContainer.superclass.addChild.apply(this, arguments);
|
|
|
106 |
this._injectChild(widget);
|
|
|
107 |
if (this.children.length > 1) {
|
|
|
108 |
this._addSizer();
|
|
|
109 |
}
|
|
|
110 |
this._layoutPanels();
|
|
|
111 |
}, _layoutPanels:function () {
|
|
|
112 |
if (this.children.length == 0) {
|
|
|
113 |
return;
|
|
|
114 |
}
|
|
|
115 |
var space = this.isHorizontal ? this.paneWidth : this.paneHeight;
|
|
|
116 |
if (this.children.length > 1) {
|
|
|
117 |
space -= this.sizerWidth * (this.children.length - 1);
|
|
|
118 |
}
|
|
|
119 |
var out_of = 0;
|
|
|
120 |
for (var i = 0; i < this.children.length; i++) {
|
|
|
121 |
out_of += this.children[i].sizeShare;
|
|
|
122 |
}
|
|
|
123 |
var pix_per_unit = space / out_of;
|
|
|
124 |
var total_size = 0;
|
|
|
125 |
for (var i = 0; i < this.children.length - 1; i++) {
|
|
|
126 |
var size = Math.round(pix_per_unit * this.children[i].sizeShare);
|
|
|
127 |
this.children[i].sizeActual = size;
|
|
|
128 |
total_size += size;
|
|
|
129 |
}
|
|
|
130 |
this.children[this.children.length - 1].sizeActual = space - total_size;
|
|
|
131 |
this._checkSizes();
|
|
|
132 |
var pos = 0;
|
|
|
133 |
var size = this.children[0].sizeActual;
|
|
|
134 |
this._movePanel(this.children[0], pos, size);
|
|
|
135 |
this.children[0].position = pos;
|
|
|
136 |
pos += size;
|
|
|
137 |
for (var i = 1; i < this.children.length; i++) {
|
|
|
138 |
this._moveSlider(this.sizers[i - 1], pos, this.sizerWidth);
|
|
|
139 |
this.sizers[i - 1].position = pos;
|
|
|
140 |
pos += this.sizerWidth;
|
|
|
141 |
size = this.children[i].sizeActual;
|
|
|
142 |
this._movePanel(this.children[i], pos, size);
|
|
|
143 |
this.children[i].position = pos;
|
|
|
144 |
pos += size;
|
|
|
145 |
}
|
|
|
146 |
}, _movePanel:function (panel, pos, size) {
|
|
|
147 |
if (this.isHorizontal) {
|
|
|
148 |
panel.domNode.style.left = pos + "px";
|
|
|
149 |
panel.domNode.style.top = 0;
|
|
|
150 |
panel.resizeTo(size, this.paneHeight);
|
|
|
151 |
} else {
|
|
|
152 |
panel.domNode.style.left = 0;
|
|
|
153 |
panel.domNode.style.top = pos + "px";
|
|
|
154 |
panel.resizeTo(this.paneWidth, size);
|
|
|
155 |
}
|
|
|
156 |
}, _moveSlider:function (slider, pos, size) {
|
|
|
157 |
if (this.isHorizontal) {
|
|
|
158 |
slider.style.left = pos + "px";
|
|
|
159 |
slider.style.top = 0;
|
|
|
160 |
dojo.html.setMarginBox(slider, {width:size, height:this.paneHeight});
|
|
|
161 |
} else {
|
|
|
162 |
slider.style.left = 0;
|
|
|
163 |
slider.style.top = pos + "px";
|
|
|
164 |
dojo.html.setMarginBox(slider, {width:this.paneWidth, height:size});
|
|
|
165 |
}
|
|
|
166 |
}, _growPane:function (growth, pane) {
|
|
|
167 |
if (growth > 0) {
|
|
|
168 |
if (pane.sizeActual > pane.sizeMin) {
|
|
|
169 |
if ((pane.sizeActual - pane.sizeMin) > growth) {
|
|
|
170 |
pane.sizeActual = pane.sizeActual - growth;
|
|
|
171 |
growth = 0;
|
|
|
172 |
} else {
|
|
|
173 |
growth -= pane.sizeActual - pane.sizeMin;
|
|
|
174 |
pane.sizeActual = pane.sizeMin;
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
}
|
|
|
178 |
return growth;
|
|
|
179 |
}, _checkSizes:function () {
|
|
|
180 |
var total_min_size = 0;
|
|
|
181 |
var total_size = 0;
|
|
|
182 |
for (var i = 0; i < this.children.length; i++) {
|
|
|
183 |
total_size += this.children[i].sizeActual;
|
|
|
184 |
total_min_size += this.children[i].sizeMin;
|
|
|
185 |
}
|
|
|
186 |
if (total_min_size <= total_size) {
|
|
|
187 |
var growth = 0;
|
|
|
188 |
for (var i = 0; i < this.children.length; i++) {
|
|
|
189 |
if (this.children[i].sizeActual < this.children[i].sizeMin) {
|
|
|
190 |
growth += this.children[i].sizeMin - this.children[i].sizeActual;
|
|
|
191 |
this.children[i].sizeActual = this.children[i].sizeMin;
|
|
|
192 |
}
|
|
|
193 |
}
|
|
|
194 |
if (growth > 0) {
|
|
|
195 |
if (this.isDraggingLeft) {
|
|
|
196 |
for (var i = this.children.length - 1; i >= 0; i--) {
|
|
|
197 |
growth = this._growPane(growth, this.children[i]);
|
|
|
198 |
}
|
|
|
199 |
} else {
|
|
|
200 |
for (var i = 0; i < this.children.length; i++) {
|
|
|
201 |
growth = this._growPane(growth, this.children[i]);
|
|
|
202 |
}
|
|
|
203 |
}
|
|
|
204 |
}
|
|
|
205 |
} else {
|
|
|
206 |
for (var i = 0; i < this.children.length; i++) {
|
|
|
207 |
this.children[i].sizeActual = Math.round(total_size * (this.children[i].sizeMin / total_min_size));
|
|
|
208 |
}
|
|
|
209 |
}
|
|
|
210 |
}, beginSizing:function (e, i) {
|
|
|
211 |
this.paneBefore = this.children[i];
|
|
|
212 |
this.paneAfter = this.children[i + 1];
|
|
|
213 |
this.isSizing = true;
|
|
|
214 |
this.sizingSplitter = this.sizers[i];
|
|
|
215 |
this.originPos = dojo.html.getAbsolutePosition(this.children[0].domNode, true, dojo.html.boxSizing.MARGIN_BOX);
|
|
|
216 |
if (this.isHorizontal) {
|
|
|
217 |
var client = (e.layerX ? e.layerX : e.offsetX);
|
|
|
218 |
var screen = e.pageX;
|
|
|
219 |
this.originPos = this.originPos.x;
|
|
|
220 |
} else {
|
|
|
221 |
var client = (e.layerY ? e.layerY : e.offsetY);
|
|
|
222 |
var screen = e.pageY;
|
|
|
223 |
this.originPos = this.originPos.y;
|
|
|
224 |
}
|
|
|
225 |
this.startPoint = this.lastPoint = screen;
|
|
|
226 |
this.screenToClientOffset = screen - client;
|
|
|
227 |
this.dragOffset = this.lastPoint - this.paneBefore.sizeActual - this.originPos - this.paneBefore.position;
|
|
|
228 |
if (!this.activeSizing) {
|
|
|
229 |
this._showSizingLine();
|
|
|
230 |
}
|
|
|
231 |
dojo.event.connect(document.documentElement, "onmousemove", this, "changeSizing");
|
|
|
232 |
dojo.event.connect(document.documentElement, "onmouseup", this, "endSizing");
|
|
|
233 |
dojo.event.browser.stopEvent(e);
|
|
|
234 |
}, changeSizing:function (e) {
|
|
|
235 |
this.lastPoint = this.isHorizontal ? e.pageX : e.pageY;
|
|
|
236 |
if (this.activeSizing) {
|
|
|
237 |
this.movePoint();
|
|
|
238 |
this._updateSize();
|
|
|
239 |
} else {
|
|
|
240 |
this.movePoint();
|
|
|
241 |
this._moveSizingLine();
|
|
|
242 |
}
|
|
|
243 |
dojo.event.browser.stopEvent(e);
|
|
|
244 |
}, endSizing:function (e) {
|
|
|
245 |
if (!this.activeSizing) {
|
|
|
246 |
this._hideSizingLine();
|
|
|
247 |
}
|
|
|
248 |
this._updateSize();
|
|
|
249 |
this.isSizing = false;
|
|
|
250 |
dojo.event.disconnect(document.documentElement, "onmousemove", this, "changeSizing");
|
|
|
251 |
dojo.event.disconnect(document.documentElement, "onmouseup", this, "endSizing");
|
|
|
252 |
if (this.persist) {
|
|
|
253 |
this._saveState(this);
|
|
|
254 |
}
|
|
|
255 |
}, movePoint:function () {
|
|
|
256 |
var p = this.lastPoint - this.screenToClientOffset;
|
|
|
257 |
var a = p - this.dragOffset;
|
|
|
258 |
a = this.legaliseSplitPoint(a);
|
|
|
259 |
p = a + this.dragOffset;
|
|
|
260 |
this.lastPoint = p + this.screenToClientOffset;
|
|
|
261 |
}, legaliseSplitPoint:function (a) {
|
|
|
262 |
a += this.sizingSplitter.position;
|
|
|
263 |
this.isDraggingLeft = (a > 0) ? true : false;
|
|
|
264 |
if (!this.activeSizing) {
|
|
|
265 |
if (a < this.paneBefore.position + this.paneBefore.sizeMin) {
|
|
|
266 |
a = this.paneBefore.position + this.paneBefore.sizeMin;
|
|
|
267 |
}
|
|
|
268 |
if (a > this.paneAfter.position + (this.paneAfter.sizeActual - (this.sizerWidth + this.paneAfter.sizeMin))) {
|
|
|
269 |
a = this.paneAfter.position + (this.paneAfter.sizeActual - (this.sizerWidth + this.paneAfter.sizeMin));
|
|
|
270 |
}
|
|
|
271 |
}
|
|
|
272 |
a -= this.sizingSplitter.position;
|
|
|
273 |
this._checkSizes();
|
|
|
274 |
return a;
|
|
|
275 |
}, _updateSize:function () {
|
|
|
276 |
var pos = this.lastPoint - this.dragOffset - this.originPos;
|
|
|
277 |
var start_region = this.paneBefore.position;
|
|
|
278 |
var end_region = this.paneAfter.position + this.paneAfter.sizeActual;
|
|
|
279 |
this.paneBefore.sizeActual = pos - start_region;
|
|
|
280 |
this.paneAfter.position = pos + this.sizerWidth;
|
|
|
281 |
this.paneAfter.sizeActual = end_region - this.paneAfter.position;
|
|
|
282 |
for (var i = 0; i < this.children.length; i++) {
|
|
|
283 |
this.children[i].sizeShare = this.children[i].sizeActual;
|
|
|
284 |
}
|
|
|
285 |
this._layoutPanels();
|
|
|
286 |
}, _showSizingLine:function () {
|
|
|
287 |
this._moveSizingLine();
|
|
|
288 |
if (this.isHorizontal) {
|
|
|
289 |
dojo.html.setMarginBox(this.virtualSizer, {width:this.sizerWidth, height:this.paneHeight});
|
|
|
290 |
} else {
|
|
|
291 |
dojo.html.setMarginBox(this.virtualSizer, {width:this.paneWidth, height:this.sizerWidth});
|
|
|
292 |
}
|
|
|
293 |
this.virtualSizer.style.display = "block";
|
|
|
294 |
}, _hideSizingLine:function () {
|
|
|
295 |
this.virtualSizer.style.display = "none";
|
|
|
296 |
}, _moveSizingLine:function () {
|
|
|
297 |
var pos = this.lastPoint - this.startPoint + this.sizingSplitter.position;
|
|
|
298 |
if (this.isHorizontal) {
|
|
|
299 |
this.virtualSizer.style.left = pos + "px";
|
|
|
300 |
} else {
|
|
|
301 |
var pos = (this.lastPoint - this.startPoint) + this.sizingSplitter.position;
|
|
|
302 |
this.virtualSizer.style.top = pos + "px";
|
|
|
303 |
}
|
|
|
304 |
}, _getCookieName:function (i) {
|
|
|
305 |
return this.widgetId + "_" + i;
|
|
|
306 |
}, _restoreState:function () {
|
|
|
307 |
for (var i = 0; i < this.children.length; i++) {
|
|
|
308 |
var cookieName = this._getCookieName(i);
|
|
|
309 |
var cookieValue = dojo.io.cookie.getCookie(cookieName);
|
|
|
310 |
if (cookieValue != null) {
|
|
|
311 |
var pos = parseInt(cookieValue);
|
|
|
312 |
if (typeof pos == "number") {
|
|
|
313 |
this.children[i].sizeShare = pos;
|
|
|
314 |
}
|
|
|
315 |
}
|
|
|
316 |
}
|
|
|
317 |
}, _saveState:function () {
|
|
|
318 |
for (var i = 0; i < this.children.length; i++) {
|
|
|
319 |
var cookieName = this._getCookieName(i);
|
|
|
320 |
dojo.io.cookie.setCookie(cookieName, this.children[i].sizeShare, null, null, null, null);
|
|
|
321 |
}
|
|
|
322 |
}});
|
|
|
323 |
dojo.lang.extend(dojo.widget.Widget, {sizeMin:10, sizeShare:10});
|
|
|
324 |
dojo.widget.defineWidget("dojo.widget.SplitContainerPanel", dojo.widget.ContentPane, {});
|
|
|
325 |
|