Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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.html.layout");
14
dojo.require("dojo.lang.common");
15
dojo.require("dojo.string.extras");
16
dojo.require("dojo.html.style");
17
dojo.require("dojo.html.layout");
18
dojo.widget.html.layout = function (container, children, layoutPriority) {
19
	dojo.html.addClass(container, "dojoLayoutContainer");
20
	children = dojo.lang.filter(children, function (child, idx) {
21
		child.idx = idx;
22
		return dojo.lang.inArray(["top", "bottom", "left", "right", "client", "flood"], child.layoutAlign);
23
	});
24
	if (layoutPriority && layoutPriority != "none") {
25
		var rank = function (child) {
26
			switch (child.layoutAlign) {
27
			  case "flood":
28
				return 1;
29
			  case "left":
30
			  case "right":
31
				return (layoutPriority == "left-right") ? 2 : 3;
32
			  case "top":
33
			  case "bottom":
34
				return (layoutPriority == "left-right") ? 3 : 2;
35
			  default:
36
				return 4;
37
			}
38
		};
39
		children.sort(function (a, b) {
40
			return (rank(a) - rank(b)) || (a.idx - b.idx);
41
		});
42
	}
43
	var f = {top:dojo.html.getPixelValue(container, "padding-top", true), left:dojo.html.getPixelValue(container, "padding-left", true)};
44
	dojo.lang.mixin(f, dojo.html.getContentBox(container));
45
	dojo.lang.forEach(children, function (child) {
46
		var elm = child.domNode;
47
		var pos = child.layoutAlign;
48
		with (elm.style) {
49
			left = f.left + "px";
50
			top = f.top + "px";
51
			bottom = "auto";
52
			right = "auto";
53
		}
54
		dojo.html.addClass(elm, "dojoAlign" + dojo.string.capitalize(pos));
55
		if ((pos == "top") || (pos == "bottom")) {
56
			dojo.html.setMarginBox(elm, {width:f.width});
57
			var h = dojo.html.getMarginBox(elm).height;
58
			f.height -= h;
59
			if (pos == "top") {
60
				f.top += h;
61
			} else {
62
				elm.style.top = f.top + f.height + "px";
63
			}
64
			if (child.onResized) {
65
				child.onResized();
66
			}
67
		} else {
68
			if (pos == "left" || pos == "right") {
69
				var w = dojo.html.getMarginBox(elm).width;
70
				if (child.resizeTo) {
71
					child.resizeTo(w, f.height);
72
				} else {
73
					dojo.html.setMarginBox(elm, {width:w, height:f.height});
74
				}
75
				f.width -= w;
76
				if (pos == "left") {
77
					f.left += w;
78
				} else {
79
					elm.style.left = f.left + f.width + "px";
80
				}
81
			} else {
82
				if (pos == "flood" || pos == "client") {
83
					if (child.resizeTo) {
84
						child.resizeTo(f.width, f.height);
85
					} else {
86
						dojo.html.setMarginBox(elm, {width:f.width, height:f.height});
87
					}
88
				}
89
			}
90
		}
91
	});
92
};
93
dojo.html.insertCssText(".dojoLayoutContainer{ position: relative; display: block; overflow: hidden; }\n" + "body .dojoAlignTop, body .dojoAlignBottom, body .dojoAlignLeft, body .dojoAlignRight { position: absolute; overflow: hidden; }\n" + "body .dojoAlignClient { position: absolute }\n" + ".dojoAlignClient { overflow: auto; }\n");
94