]>
Commit | Line | Data |
---|---|---|
1 | var SWMUIWindow = new Class({ | |
2 | Extends: UIWindow, | |
3 | ||
4 | initialize: function(parentObject, client, type, name) { | |
5 | this.parent(parentObject, client, type, name); | |
6 | this.contentPanel = new SWMPanel(parentObject.mainPanel, true); | |
7 | this.contentPanel.addClass("content"); | |
8 | ||
9 | if(type == WINDOW_CHANNEL) { | |
10 | this.nickList = new SWMPanel(this.contentPanel); | |
11 | this.nickList.anchor = SWM_ANCHOR_RIGHT; | |
12 | this.nickList.addClass("nicklist"); | |
13 | ||
14 | this.topic = new SWMPanel(this.contentPanel); | |
15 | this.topic.anchor = SWM_ANCHOR_TOP; | |
16 | this.topic.addClass("topic"); | |
17 | } | |
18 | ||
19 | this.xlines = new SWMPanel(this.contentPanel); | |
20 | this.lines = this.xlines.element; | |
21 | ||
22 | this.tab = new Element("span"); | |
23 | this.tab.addClass("tab"); | |
24 | ||
25 | this.tab.appendText(name); | |
26 | this.tab.addEvent("click", function() { | |
27 | parentObject.selectWindow(this); | |
28 | }.bind(this)); | |
29 | ||
30 | parentObject.tabPanel.appendChild(this.tab); | |
31 | parentObject.resize(); | |
32 | ||
33 | if(type != WINDOW_STATUS) { | |
34 | tabclose = new Element("span"); | |
35 | tabclose.addClass("tabclose"); | |
36 | tabclose.addEvent("click", function(e) { | |
37 | new Event(e).stop(); | |
38 | ||
39 | if(type == WINDOW_CHANNEL) | |
40 | this.client.exec("/PART " + name); | |
41 | ||
42 | this.close(); | |
43 | }.bind(this)); | |
44 | tabclose.set("text", "X"); | |
45 | this.tab.appendChild(tabclose); | |
46 | } | |
47 | }, | |
48 | updateNickList: function(nicks) { | |
49 | this.parent(nicks); | |
50 | ||
51 | this.nickList.removeAllChildren(); | |
52 | nicks.each(function(nick) { | |
53 | var e = new Element("div"); | |
54 | this.nickList.appendChild(e); | |
55 | e.appendChild(document.createTextNode(nick)); | |
56 | }.bind(this)); | |
57 | ||
58 | this.parentObject.resize(); | |
59 | }, | |
60 | updateTopic: function(topic) { | |
61 | this.parent(topic); | |
62 | ||
63 | this.topic.removeAllChildren(); | |
64 | Colourise(topic, this.topic.element); | |
65 | ||
66 | this.parentObject.resize(); | |
67 | }, | |
68 | select: function() { | |
69 | this.parent(); | |
70 | ||
71 | this.contentPanel.setHidden(false); | |
72 | this.parentObject.resize(); | |
73 | this.tab.removeClass("tab-unselected"); | |
74 | this.tab.addClass("tab-selected"); | |
75 | }, | |
76 | deselect: function() { | |
77 | this.parent(); | |
78 | ||
79 | this.contentPanel.setHidden(true); | |
80 | this.parentObject.resize(); | |
81 | this.tab.removeClass("tab-selected"); | |
82 | this.tab.addClass("tab-unselected"); | |
83 | }, | |
84 | close: function() { | |
85 | this.parent(); | |
86 | ||
87 | this.parentObject.mainPanel.removeChild(this.contentPanel.element); | |
88 | this.parentObject.tabPanel.removeChild(this.tab); | |
89 | }, | |
90 | addLine: function(type, line, colour) { | |
91 | var e = new Element("div"); | |
92 | ||
93 | if(colour) { | |
94 | e.setStyles({"background": colour}); | |
95 | } else if(this.lastcolour) { | |
96 | e.addClass("linestyle1"); | |
97 | } else { | |
98 | e.addClass("linestyle2"); | |
99 | } | |
100 | ||
101 | this.lastcolour = !this.lastcolour; | |
102 | ||
103 | this.parent(type, line, colour, e); | |
104 | }, | |
105 | setHilighted: function(state) { | |
106 | this.parent(state); | |
107 | ||
108 | if(state) { | |
109 | this.tab.addClass("tab-highlighted"); | |
110 | } else { | |
111 | this.tab.removeClass("tab-highlighted"); | |
112 | } | |
113 | } | |
114 | }); | |
115 | ||
116 | var SWMUI = new Class({ | |
117 | Extends: UI, | |
118 | initialize: function(parentElement, theme) { | |
119 | this.parent(parentElement, SWMUIWindow, "swmui"); | |
120 | ||
121 | this.parentElement = parentElement; | |
122 | this.theme = theme; | |
123 | }, | |
124 | postInitialize: function() { | |
125 | this.rootFrame = new SWMFrame(this.parentElement); | |
126 | ||
127 | this.tabPanel = new SWMPanel(this.rootFrame); | |
128 | this.tabPanel.anchor = SWM_ANCHOR_TOP; | |
129 | this.tabPanel.addClass("tabs"); | |
130 | ||
131 | this.mainPanel = new SWMPanel(this.rootFrame); | |
132 | this.mainPanel.addClass("main"); | |
133 | ||
134 | this.entryPanel = new SWMPanel(this.rootFrame); | |
135 | this.entryPanel.anchor = SWM_ANCHOR_BOTTOM; | |
136 | this.entryPanel.addClass("entry"); | |
137 | ||
138 | var form = new Element("form"); | |
139 | ||
140 | var inputbox = new Element("input"); | |
141 | inputbox.setStyle("border", "0px"); | |
142 | ||
143 | window.addEvent("resize", function() { | |
144 | var s = this.entryPanel.getInnerSize().x; | |
145 | inputbox.setStyle("width", s + "px"); | |
146 | }.bind(this)); | |
147 | ||
148 | form.addEvent("submit", function(e) { | |
149 | new Event(e).stop(); | |
150 | ||
151 | this.getActiveWindow().client.exec(inputbox.value); | |
152 | inputbox.value = ""; | |
153 | }.bind(this)); | |
154 | ||
155 | this.entryPanel.appendChild(form); | |
156 | form.appendChild(inputbox); | |
157 | inputbox.focus(); | |
158 | ||
159 | this.resize(); | |
160 | }, | |
161 | resize: function() { | |
162 | window.fireEvent("resize"); | |
163 | }, | |
164 | loginBox: function(callback, initialNickname, initialChannels) { | |
165 | var box = new Element("div"); | |
166 | this.parentElement.appendChild(box); | |
167 | ||
168 | var header = new Element("h1"); | |
169 | header.set("text", "qwebirc"); | |
170 | box.appendChild(header); | |
171 | ||
172 | var form = new Element("form"); | |
173 | box.appendChild(form); | |
174 | ||
175 | var boxtable = new Element("table"); | |
176 | form.appendChild(boxtable); | |
177 | ||
178 | var tbody = new Element("tbody"); | |
179 | boxtable.appendChild(tbody); /* stupid IE */ | |
180 | ||
181 | function createRow(label, e2) { | |
182 | var r = new Element("tr"); | |
183 | tbody.appendChild(r); | |
184 | ||
185 | var d1 = new Element("td"); | |
186 | if(label) | |
187 | d1.set("text", label); | |
188 | r.appendChild(d1); | |
189 | ||
190 | var d2 = new Element("td"); | |
191 | r.appendChild(d2); | |
192 | d2.appendChild(e2); | |
193 | return d1; | |
194 | } | |
195 | ||
196 | var nick = new Element("input"); | |
197 | createRow("Nickname:", nick); | |
198 | var chan = new Element("input"); | |
199 | createRow("Channels (comma seperated):", chan); | |
200 | ||
201 | var connbutton = new Element("input", {"type": "submit"}); | |
202 | connbutton.set("value", "Connect"); | |
203 | createRow(undefined, connbutton) | |
204 | ||
205 | form.addEvent("submit", function(e) { | |
206 | new Event(e).stop(); | |
207 | var nickname = nick.value; | |
208 | var chans = chan.value; | |
209 | if(chans == "#") /* sorry channel "#" :P */ | |
210 | chans = ""; | |
211 | ||
212 | if(!nickname) { | |
213 | alert("You must supply a nickname."); | |
214 | nick.focus(); | |
215 | return; | |
216 | } | |
217 | ||
218 | this.parentElement.removeChild(box); | |
219 | this.postInitialize(); | |
220 | callback({"nickname": nickname, "autojoin": chans}); | |
221 | }.bind(this)); | |
222 | ||
223 | nick.set("value", initialNickname); | |
224 | chan.set("value", initialChannels); | |
225 | ||
226 | nick.focus(); | |
227 | } | |
228 | }); |