]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/swmlayout.js
Try not to corrupt the namespaces.
[irc/quakenet/qwebirc.git] / js / ui / swmlayout.js
1 qwebirc.ui.SWMUI.SWM_ANCHOR_NONE = 0x00;
2 qwebirc.ui.SWMUI.SWM_ANCHOR_TOP = 0x01;
3 qwebirc.ui.SWMUI.SWM_ANCHOR_BOTTOM = 0x02;
4 qwebirc.ui.SWMUI.SWM_ANCHOR_LEFT = 0x04;
5 qwebirc.ui.SWMUI.SWM_ANCHOR_RIGHT = 0x08;
6
7 qwebirc.ui.SWMUI.Container = new Class({
8 initialize: function(parentElement) {
9 this.parentElement = parentElement;
10 },
11 getInnerSize: function() {
12 // return {x: this.element.clientWidth, y: this.element.clientHeight};
13 return this.element.getSize();
14 },
15 getOuterSize: function() {
16 return this.element.getSize();
17 },
18 appendChild: function(element) {
19 this.element.appendChild(element);
20 },
21 removeChild: function(element) {
22 this.element.removeChild(element);
23 },
24 setStyle: function(style, value) {
25 this.element.setStyle(setstyle, value);
26 },
27 removeAllChildren: function(element) {
28 while(this.element.firstChild)
29 this.removeChild(this.element.firstChild);
30 },
31 setSize: function(top, left, bottom, right) {
32 var data = {};
33
34 var outer = this.getOuterSize();
35 var inner = this.getInnerSize();
36 var p = this.parentElement.getInnerSize();
37
38 if(top != undefined && bottom != undefined) {
39 data.top = top;
40 data.height = p.y - top - bottom;
41 } else if(top == undefined) {
42 data.bottom = bottom;
43 } else { /* bottom == undefined */
44 data.top = top;
45 }
46
47 if(left != undefined && right != undefined) {
48 data.left = left;
49 data.width = p.x - left - right;
50 } else if(left == undefined) {
51 data.right = right;
52 } else { /* right == undefined */
53 data.left = left;
54 }
55
56 if(data.height)
57 data.height = data.height - (outer.y - inner.y);
58 if(data.width)
59 data.width = data.width - (outer.x - inner.x);
60
61 var data2 = {};
62 for(var k in data)
63 data2[k] = data[k] + "px";
64
65 this.element.setStyles(data2);
66 this.rework();
67 },
68 rework: function() {
69 var x = this.element.getChildren().map(function(x) {
70 return x.wmpanel;
71 });
72
73 var anchorFilter = function(x, y) {
74 return x.filter(function(z) {
75 if(z && (z.anchor == y) && !z.hidden) {
76 return true;
77 }
78 });
79 }
80
81 var top = anchorFilter(x, qwebirc.ui.SWMUI.SWM_ANCHOR_TOP);
82 var bottom = anchorFilter(x, qwebirc.ui.SWMUI.SWM_ANCHOR_BOTTOM);
83 var left = anchorFilter(x, qwebirc.ui.SWMUI.SWM_ANCHOR_LEFT);
84 var right = anchorFilter(x, qwebirc.ui.SWMUI.SWM_ANCHOR_RIGHT);
85 var none = anchorFilter(x, qwebirc.ui.SWMUI.SWM_ANCHOR_NONE);
86
87 var x = this.getInnerSize();
88 var y = this.getOuterSize();
89
90 var tpos = 0;
91 top.each(function(obj) {
92 obj.setSize(tpos, 0, undefined, 0);
93 tpos = tpos + obj.getOuterSize().y;
94 });
95
96 var bpos = 0;
97 bottom.each(function(obj) {
98 obj.setSize(undefined, 0, bpos, 0);
99 bpos = bpos + obj.getOuterSize().y;
100 });
101
102 var lpos = 0;
103 left.each(function(obj) {
104 obj.setSize(tpos, lpos, bpos, undefined);
105 lpos = lpos + obj.getOuterSize().x;
106 });
107
108 var rpos = 0;
109 right.each(function(obj) {
110 obj.setSize(tpos, undefined, bpos, rpos);
111 rpos = rpos + obj.getOuterSize().x;
112 });
113
114 var bpos = 0;
115 bottom.each(function(obj) {
116 obj.setSize(undefined, 0, bpos, 0);
117 bpos = bpos + obj.getOuterSize().y;
118 });
119
120 none.each(function(obj) {
121 obj.setSize(tpos, lpos, bpos, rpos);
122 });
123 }
124 });
125
126 qwebirc.ui.SWMUI.Frame = new Class({
127 Extends: qwebirc.ui.SWMUI.Container,
128 initialize: function(parentElement) {
129 this.parent(this);
130
131 this.element = new Element("div", {"styles": {
132 "position": "relative",
133 "top": "0px",
134 "left": "0px",
135 "height": "100%",
136 "width": "100%"
137 }});
138 this.element.wmpanel = this;
139
140 parentElement.appendChild(this.element);
141 this.element.addClass("swmelement");
142 }
143 });
144
145 qwebirc.ui.SWMUI.Panel = new Class({
146 Extends: qwebirc.ui.SWMUI.Container,
147 initialize: function(parentPanel, hidden) {
148 this.parent(parentPanel);
149 this.element = new Element("div", {"styles": {
150 "position": "absolute"
151 }});
152 this.element.wmpanel = this;
153
154 if(hidden) {
155 this.setHidden(true);
156 } else {
157 this.hidden = false;
158 }
159
160 parentPanel.element.appendChild(this.element);
161 this.anchor = qwebirc.ui.SWMUI.SWM_ANCHOR_NONE;
162 },
163 setHeight: function(height) {
164 this.height = height;
165 },
166 setWidth: function(width) {
167 this.width = width;
168 },
169 setHidden: function(value) {
170 this.hidden = value;
171 if(value) {
172 this.element.setStyle("display", "none");
173 } else {
174 this.element.setStyle("display", "block");
175 }
176 },
177 addClass: function(class_) {
178 this.element.addClass(class_);
179 },
180 getScrollSize: function() {
181 return this.element.getScrollSize();
182 }
183 });
184
185 window.addEvent("domready", function() {
186 window.addEvent("resize", function() {
187 $$("div.swmelement").each(function(x) {
188 x.wmpanel.rework();
189 });
190 });
191 });