Subversion Repositories Applications.papyrus

Rev

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