]>
Commit | Line | Data |
---|---|---|
f4ae92cc CP |
1 | var QUIWindow = new Class({ |
2 | Extends: UIWindow, | |
3 | ||
4 | initialize: function(parentObject, client, type, name) { | |
5 | this.parent(parentObject, client, type, name); | |
be0bd774 | 6 | |
66de775f | 7 | this.tab = new Element("a", {"href": "#"}); |
f4ae92cc CP |
8 | this.tab.addClass("tab"); |
9 | ||
10 | this.tab.appendText(name); | |
66de775f CP |
11 | this.tab.addEvent("click", function(e) { |
12 | new Event(e).stop(); | |
f4ae92cc CP |
13 | parentObject.selectWindow(this); |
14 | }.bind(this)); | |
15 | ||
16 | parentObject.tabs.appendChild(this.tab); | |
17 | ||
18 | if(type != WINDOW_STATUS) { | |
19 | tabclose = new Element("span"); | |
20 | tabclose.addClass("tabclose"); | |
21 | tabclose.addEvent("click", function(e) { | |
22 | new Event(e).stop(); | |
23 | ||
24 | if(type == WINDOW_CHANNEL) | |
25 | this.client.exec("/PART " + name); | |
26 | ||
27 | this.close(); | |
28 | }.bind(this)); | |
29 | tabclose.set("text", "X"); | |
30 | this.tab.appendChild(tabclose); | |
31 | } | |
be0bd774 CP |
32 | |
33 | this.parentObject.reflow(); | |
34 | ||
35 | this.window = new Element("div"); | |
36 | this.window.addClass("window"); | |
37 | parentObject.container.appendChild(this.window); | |
38 | ||
39 | this.lines = new Element("div"); | |
40 | this.lines.addClass("lines"); | |
41 | this.window.appendChild(this.lines); | |
42 | ||
43 | var formdiv = new Element("div"); | |
44 | this.window.appendChild(formdiv); | |
359b7edd | 45 | this.formdiv = formdiv; |
be0bd774 CP |
46 | |
47 | var form = new Element("form"); | |
48 | var inputbox = new Element("input"); | |
9b63b053 | 49 | |
be0bd774 CP |
50 | formdiv.addClass("input"); |
51 | ||
52 | form.addEvent("submit", function(e) { | |
53 | new Event(e).stop(); | |
54 | ||
9b63b053 | 55 | this.historyExec(inputbox.value); |
be0bd774 CP |
56 | inputbox.value = ""; |
57 | }.bind(this)); | |
58 | formdiv.appendChild(form); | |
59 | form.appendChild(inputbox); | |
60 | ||
9b63b053 CP |
61 | inputbox.addEvent("keypress", function(e) { |
62 | var result; | |
63 | if(e.key == "up") { | |
64 | result = this.commandhistory.nextLine(); | |
65 | } else if(e.key == "down") { | |
66 | result = this.commandhistory.prevLine(); | |
67 | } else { | |
68 | return; | |
69 | } | |
70 | ||
71 | new Event(e).stop(); | |
72 | if(!result) | |
73 | result = "" | |
74 | inputbox.value = result; | |
75 | setAtEnd(inputbox); | |
76 | }.bind(this)); | |
25be5960 CP |
77 | this.inputbox = inputbox; |
78 | ||
be0bd774 CP |
79 | var toppos = 0; |
80 | var rightpos = 0; | |
81 | var bottompos = formdiv.getSize().y; | |
82 | ||
83 | if(type == WINDOW_CHANNEL) { | |
be0bd774 CP |
84 | this.topic = new Element("div"); |
85 | this.topic.addClass("topic"); | |
86 | this.topic.set("html", " "); | |
359b7edd | 87 | |
be0bd774 CP |
88 | this.window.appendChild(this.topic); |
89 | ||
66de775f CP |
90 | this.nicklist = new Element("div"); |
91 | this.nicklist.addClass("nicklist"); | |
66de775f CP |
92 | |
93 | this.window.appendChild(this.nicklist); | |
be0bd774 CP |
94 | } |
95 | ||
be0bd774 | 96 | this.lines.addClass("lines"); |
359b7edd CP |
97 | if(type == WINDOW_CHANNEL) { |
98 | /* calls reflow */ | |
99 | this.updateTopic(""); | |
100 | } else { | |
101 | this.reflow(); | |
102 | } | |
25be5960 CP |
103 | |
104 | this.lines.addEvent("scroll", function() { | |
105 | this.scrolleddown = this.scrolledDown(); | |
106 | }.bind(this)); | |
107 | ||
108 | window.addEvent("resize", function() { | |
109 | if(this.scrolleddown) | |
110 | this.scrollToBottom(); | |
359b7edd | 111 | this.reflow(); |
25be5960 | 112 | }.bind(this)); |
f4ae92cc | 113 | }, |
359b7edd CP |
114 | reflow: function() { |
115 | var toppos = 0; | |
116 | var rightpos = 0; | |
117 | var bottompos = this.formdiv.getSize().y; | |
118 | ||
119 | if(this.type == WINDOW_CHANNEL) { | |
120 | toppos = this.topic.getSize().y; | |
121 | ||
122 | this.nicklist.setStyle("top", toppos + "px"); | |
123 | this.nicklist.setStyle("bottom", (bottompos - 1) + "px"); | |
2b8e1a88 | 124 | rightpos = this.nicklist.getSize().x; |
359b7edd CP |
125 | } |
126 | ||
127 | this.lines.setStyle("top", toppos + "px"); | |
128 | this.lines.setStyle("bottom", bottompos + "px"); | |
129 | this.lines.setStyle("right", rightpos + "px"); | |
130 | }, | |
f4ae92cc CP |
131 | updateNickList: function(nicks) { |
132 | this.parent(nicks); | |
133 | ||
134 | var n = this.nicklist; | |
135 | while(n.firstChild) | |
136 | n.removeChild(n.firstChild); | |
137 | ||
138 | nicks.each(function(nick) { | |
139 | var e = new Element("div"); | |
140 | n.appendChild(e); | |
141 | e.appendChild(document.createTextNode(nick)); | |
142 | }); | |
143 | }, | |
144 | updateTopic: function(topic) { | |
145 | this.parent(topic); | |
146 | ||
147 | var t = this.topic; | |
148 | ||
149 | while(t.firstChild) | |
150 | t.removeChild(t.firstChild); | |
151 | ||
66de775f | 152 | if(topic) { |
359b7edd | 153 | Colourise("[" + topic + "]", t); |
66de775f | 154 | } else { |
359b7edd CP |
155 | var e = new Element("div"); |
156 | e.set("text", "(no topic set)"); | |
66de775f | 157 | e.addClass("emptytopic"); |
359b7edd | 158 | t.appendChild(e); |
66de775f | 159 | } |
359b7edd | 160 | this.reflow(); |
f4ae92cc CP |
161 | }, |
162 | select: function() { | |
be0bd774 | 163 | this.window.removeClass("tab-invisible"); |
f4ae92cc | 164 | this.tab.removeClass("tab-unselected"); |
f4ae92cc | 165 | this.tab.addClass("tab-selected"); |
359b7edd CP |
166 | this.reflow(); |
167 | ||
7c633700 | 168 | this.parent(); |
25be5960 CP |
169 | |
170 | this.inputbox.focus(); | |
f4ae92cc CP |
171 | }, |
172 | deselect: function() { | |
173 | this.parent(); | |
174 | ||
be0bd774 | 175 | this.window.addClass("tab-invisible"); |
f4ae92cc CP |
176 | this.tab.removeClass("tab-selected"); |
177 | this.tab.addClass("tab-unselected"); | |
178 | }, | |
179 | close: function() { | |
180 | this.parent(); | |
181 | ||
be0bd774 | 182 | this.parentObject.container.removeChild(this.window); |
f4ae92cc CP |
183 | this.parentObject.tabs.removeChild(this.tab); |
184 | }, | |
185 | addLine: function(type, line, colour) { | |
f4ae92cc CP |
186 | var e = new Element("div"); |
187 | ||
188 | if(colour) { | |
189 | e.setStyles({"background": colour}); | |
190 | } else if(this.lastcolour) { | |
191 | e.addClass("linestyle1"); | |
192 | } else { | |
193 | e.addClass("linestyle2"); | |
194 | } | |
f4ae92cc | 195 | this.lastcolour = !this.lastcolour; |
be0bd774 CP |
196 | |
197 | this.parent(type, line, colour, e); | |
198 | }, | |
199 | setHilighted: function(state) { | |
200 | this.parent(state); | |
f4ae92cc | 201 | |
be0bd774 | 202 | if(state) { |
7c633700 | 203 | this.tab.addClass("tab-hilighted"); |
be0bd774 | 204 | } else { |
7c633700 | 205 | this.tab.removeClass("tab-hilighted"); |
be0bd774 | 206 | } |
f4ae92cc CP |
207 | } |
208 | }); | |
209 | ||
210 | var QUI = new Class({ | |
211 | Extends: UI, | |
212 | initialize: function(parentElement, theme) { | |
ba47bd8b | 213 | this.parent(parentElement, QUIWindow, "qui"); |
f4ae92cc CP |
214 | this.theme = theme; |
215 | this.parentElement = parentElement; | |
216 | }, | |
be0bd774 CP |
217 | reflow: function() { |
218 | var tabheight = this.tabs.getSize().y; | |
219 | this.container.setStyle("top", tabheight + "px"); | |
220 | }, | |
221 | postInitialize: function() { | |
222 | this.outerContainer = new Element("div"); | |
223 | this.outerContainer.addClass("outercontainer"); | |
224 | this.parentElement.appendChild(this.outerContainer); | |
225 | ||
f4ae92cc CP |
226 | this.tabs = new Element("div"); |
227 | this.tabs.addClass("tabbar"); | |
be0bd774 | 228 | this.outerContainer.appendChild(this.tabs); |
f4ae92cc | 229 | |
be0bd774 CP |
230 | var tester = new Element("span"); |
231 | this.tabs.appendChild(tester); | |
f4ae92cc | 232 | |
be0bd774 CP |
233 | this.tabheight = this.tabs.getSize().y; |
234 | this.tabs.removeChild(tester); | |
235 | ||
f4ae92cc CP |
236 | this.container = new Element("div"); |
237 | this.container.addClass("container"); | |
be0bd774 | 238 | this.outerContainer.appendChild(this.container); |
f4ae92cc | 239 | }, |
66de775f | 240 | loginBox: function(callbackfn, intialNickname, initialChannels, autoConnect, autoNick) { |
f4ae92cc CP |
241 | this.parent(function(options) { |
242 | this.postInitialize(); | |
243 | callbackfn(options); | |
66de775f | 244 | }.bind(this), intialNickname, initialChannels, autoConnect, autoNick); |
f4ae92cc CP |
245 | } |
246 | }); |