]>
Commit | Line | Data |
---|---|---|
8f36f657 CP |
1 | var SWM_ANCHOR_NONE = 0x00;\r |
2 | var SWM_ANCHOR_TOP = 0x01;\r | |
3 | var SWM_ANCHOR_BOTTOM = 0x02;\r | |
4 | var SWM_ANCHOR_LEFT = 0x04;\r | |
5 | var SWM_ANCHOR_RIGHT = 0x08;\r | |
6 | \r | |
7 | var SWMPanel = new Class({\r | |
8 | initialize: function(parent, id) {\r | |
9 | this.parent = parent;\r | |
10 | \r | |
11 | var element = new Element("div", {"id": id, "styles": { "position": "absolute" } });\r | |
12 | this.element = element;\r | |
13 | this.element.wmpanel = this;\r | |
14 | \r | |
15 | parent.addClass("wmelement");\r | |
16 | \r | |
17 | parent.appendChild(this.element);\r | |
18 | this.anchor = ANCHOR_NONE;\r | |
19 | },\r | |
20 | \r | |
21 | setHeight: function(height) {\r | |
22 | this.height = height;\r | |
23 | },\r | |
24 | \r | |
25 | setWidth: function(width) {\r | |
26 | this.width = width;\r | |
27 | }\r | |
28 | });\r | |
29 | \r | |
30 | window.addEvent("domready", function() {\r | |
31 | function reworkLayout(container) {\r | |
32 | function anchorFilter(x, anchor) {\r | |
33 | return x.filter(function(y) {\r | |
34 | if(y.anchor == anchor)\r | |
35 | return true;\r | |
36 | });\r | |
37 | }\r | |
38 | var x = container.getChildren().map(function(x) {\r | |
39 | return x.wmpanel\r | |
40 | });\r | |
41 | var top = anchorFilter(x, SWM_ANCHOR_TOP);\r | |
42 | var bottom = anchorFilter(x, SWM_ANCHOR_BOTTOM);\r | |
43 | var none = anchorFilter(x, SWM_ANCHOR_NONE);\r | |
44 | \r | |
45 | var left = anchorFilter(x, SWM_ANCHOR_LEFT);\r | |
46 | var right = anchorFilter(x, SWM_ANCHOR_RIGHT);\r | |
47 | \r | |
48 | var tpos = 0;\r | |
49 | for(var i=0;i<top.length;i++) {\r | |
50 | var obj = top[i].element;\r | |
51 | obj.setStyles({"top": tpos + "px", "left": "0px", "right": "0px"});\r | |
52 | tpos = tpos + obj.getSize()["size"]["y"];\r | |
53 | }\r | |
54 | \r | |
55 | var bpos = 0;\r | |
56 | for(var i=0;i<bottom.length;i++) {\r | |
57 | var obj = bottom[i].element;\r | |
58 | obj.setStyles({"bottom": bpos + "px", "left": "0px", "right": "0px"});\r | |
59 | bpos = bpos + obj.getSize()["size"]["y"];\r | |
60 | }\r | |
61 | \r | |
62 | var lpos = 0;\r | |
63 | for(var i=0;i<left.length;i++) {\r | |
64 | var obj = left[i].element;\r | |
65 | obj.setStyles({"left": lpos + "px", "top": tpos + "px", "bottom": bpos + "px"});\r | |
66 | lpos = lpos + obj.getSize()["size"]["x"];\r | |
67 | }\r | |
68 | \r | |
69 | var rpos = 0;\r | |
70 | for(var i=0;i<right.length;i++) {\r | |
71 | var obj = right[i].element;\r | |
72 | obj.setStyles({"right": rpos + "px", "top": tpos + "px", "bottom": bpos + "px"});\r | |
73 | rpos = rpos + obj.getSize()["size"]["x"];\r | |
74 | }\r | |
75 | \r | |
76 | for(var i=0;i<none.length;i++) {\r | |
77 | var obj = none[i].element;\r | |
78 | obj.setStyles({"left": lpos + "px", "right": rpos + "px", "top": tpos + "px", "bottom": bpos + "px"});\r | |
79 | }\r | |
80 | }\r | |
81 | \r | |
82 | window.addEvent("resize", function() {\r | |
83 | $$("div[class=wmelement]").forEach(reworklayout);\r | |
84 | });\r | |
85 | }); |