]>
Commit | Line | Data |
---|---|---|
e20e5a6b | 1 | qwebirc.ui.QUI = new Class({ |
144ee52f | 2 | Extends: qwebirc.ui.RootUI, |
2cad083e CP |
3 | initialize: function(parentElement, theme, options) { |
4 | this.parent(parentElement, qwebirc.ui.QUI.Window, "qui", options); | |
e20e5a6b CP |
5 | this.theme = theme; |
6 | this.parentElement = parentElement; | |
4dd199c3 | 7 | this.setModifiableStylesheet("qui"); |
e20e5a6b CP |
8 | }, |
9 | postInitialize: function() { | |
10 | this.qjsui = new qwebirc.ui.QUI.JSUI("qwebirc-qui", this.parentElement); | |
bfbe72f9 CP |
11 | this.qjsui.addEvent("reflow", function() { |
12 | var w = this.getActiveWindow(); | |
13 | if($defined(w)) | |
14 | w.onResize(); | |
15 | }.bind(this)); | |
941e1642 | 16 | this.qjsui.top.addClass("outertabbar"); |
e20e5a6b CP |
17 | |
18 | this.qjsui.bottom.addClass("input"); | |
19 | this.qjsui.right.addClass("nicklist"); | |
20 | this.qjsui.topic.addClass("topic"); | |
21 | this.qjsui.middle.addClass("lines"); | |
22 | ||
941e1642 | 23 | this.outerTabs = this.qjsui.top; |
0989d983 | 24 | |
941e1642 CP |
25 | this.tabs = new Element("div"); |
26 | this.tabs.addClass("tabbar"); | |
9da8639a CP |
27 | |
28 | this.__createDropdownMenu(); | |
29 | ||
941e1642 | 30 | this.outerTabs.appendChild(this.tabs); |
e20e5a6b CP |
31 | this.origtopic = this.topic = this.qjsui.topic; |
32 | this.origlines = this.lines = this.qjsui.middle; | |
33 | this.orignicklist = this.nicklist = this.qjsui.right; | |
34 | ||
35 | this.input = this.qjsui.bottom; | |
36 | this.reflow = this.qjsui.reflow.bind(this.qjsui); | |
37 | ||
ff4befd8 CP |
38 | this.tabs.addEvent("mousewheel", function(x) { |
39 | var event = new Event(x); | |
40 | ||
41 | /* up */ | |
42 | if(event.wheel > 0) { | |
43 | this.nextWindow(); | |
44 | } else if(event.wheel < 0) { | |
45 | /* down */ | |
b35116e2 | 46 | this.prevWindow(); |
ff4befd8 CP |
47 | } |
48 | event.stop(); | |
49 | }.bind(this)); | |
50 | ||
e20e5a6b CP |
51 | this.createInput(); |
52 | this.reflow(); | |
0a55be30 CP |
53 | this.reflow.delay(100); /* Konqueror fix */ |
54 | ||
9da8639a CP |
55 | /* HACK, in Chrome this should work immediately but doesn't */ |
56 | this.__createDropdownHint.delay(100, this); | |
e20e5a6b | 57 | }, |
0989d983 | 58 | __createDropdownMenu: function() { |
e9837dce | 59 | var dropdownMenu = new Element("span"); |
43cb8910 | 60 | dropdownMenu.addClass("dropdownmenu"); |
0989d983 CP |
61 | |
62 | dropdownMenu.hide = function() { | |
43cb8910 CP |
63 | dropdownMenu.setStyle("display", "none"); |
64 | dropdownMenu.visible = false; | |
e9837dce | 65 | document.removeEvent("mousedown", hideEvent); |
43cb8910 | 66 | }.bind(this); |
e9837dce | 67 | var hideEvent = function() { dropdownMenu.hide(); }; |
0989d983 CP |
68 | |
69 | dropdownMenu.hide(); | |
43cb8910 CP |
70 | this.parentElement.appendChild(dropdownMenu); |
71 | ||
72 | this.UICommands.forEach(function(x) { | |
73 | var text = x[0]; | |
74 | var fn = this[x[1] + "Window"].bind(this); | |
75 | var e = new Element("a"); | |
0989d983 | 76 | e.addEvent("mousedown", function(e) { new Event(e).stop(); }); |
43cb8910 CP |
77 | e.addEvent("click", function() { |
78 | dropdownMenu.hide(); | |
79 | fn(); | |
80 | }); | |
81 | e.set("text", text); | |
82 | dropdownMenu.appendChild(e); | |
83 | }.bind(this)); | |
84 | ||
941e1642 | 85 | var dropdown = new Element("div"); |
43cb8910 | 86 | dropdown.addClass("dropdown-tab"); |
fbe5af77 | 87 | dropdown.appendChild(new Element("img", {src: qwebirc.global.staticBaseURL + "images/icon.png", title: "menu", alt: "menu"})); |
391f51ff CP |
88 | dropdown.setStyle("opacity", 1); |
89 | ||
90 | var dropdownEffect = new Fx.Tween(dropdown, {duration: "long", property: "opacity", link: "chain"}); | |
91 | dropdownEffect.start(0.25); | |
92 | dropdownEffect.start(1); | |
93 | dropdownEffect.start(0.33); | |
94 | dropdownEffect.start(1); | |
95 | ||
941e1642 | 96 | this.outerTabs.appendChild(dropdown); |
9da8639a | 97 | dropdownMenu.show = function(x) { |
43cb8910 | 98 | new Event(x).stop(); |
e9837dce | 99 | this.hideHint(); |
43cb8910 CP |
100 | |
101 | if(dropdownMenu.visible) { | |
102 | dropdownMenu.hide(); | |
103 | return; | |
104 | } | |
e9837dce CP |
105 | var top = this.outerTabs.getSize().y; |
106 | ||
941e1642 | 107 | dropdownMenu.setStyle("left", 0); |
385143a6 | 108 | dropdownMenu.setStyle("top", top-1); /* -1 == top border */ |
43cb8910 CP |
109 | dropdownMenu.setStyle("display", "inline-block"); |
110 | dropdownMenu.visible = true; | |
e9837dce CP |
111 | |
112 | document.addEvent("mousedown", hideEvent); | |
43cb8910 | 113 | }.bind(this); |
e9837dce | 114 | dropdown.addEvent("mousedown", function(e) { new Event(e).stop(); }); |
43cb8910 | 115 | dropdown.addEvent("click", dropdownMenu.show); |
0989d983 | 116 | }, |
9da8639a | 117 | __createDropdownHint: function() { |
43cb8910 CP |
118 | var dropdownhint = new Element("div"); |
119 | dropdownhint.addClass("dropdownhint"); | |
391f51ff | 120 | dropdownhint.set("text", "Click the icon for the main menu."); |
e9837dce CP |
121 | dropdownhint.setStyle("top", this.outerTabs.getSize().y + 5); |
122 | ||
123 | this.parentElement.appendChild(dropdownhint); | |
391f51ff CP |
124 | new Fx.Morph(dropdownhint, {duration: "normal", transition: Fx.Transitions.Sine.easeOut}).start({left: [900, 5]}); |
125 | ||
43cb8910 | 126 | var hider = function() { |
391f51ff CP |
127 | new Fx.Morph(dropdownhint, {duration: "long"}).start({left: [5, -900]}); |
128 | }.delay(4000, this); | |
0989d983 | 129 | |
391f51ff CP |
130 | var hider2 = function() { |
131 | if(dropdownhint.hidden) | |
132 | return; | |
e9837dce | 133 | this.parentElement.removeChild(dropdownhint); |
391f51ff CP |
134 | dropdownhint.hidden = 1; |
135 | }.bind(this); | |
136 | hider2.delay(4000); | |
e9837dce | 137 | this.hideHint = hider2; |
391f51ff CP |
138 | |
139 | document.addEvent("mousedown", hider2); | |
140 | document.addEvent("keypress", hider2); | |
43cb8910 | 141 | }, |
e20e5a6b CP |
142 | createInput: function() { |
143 | var form = new Element("form"); | |
144 | this.input.appendChild(form); | |
c1416a8d | 145 | |
e20e5a6b CP |
146 | form.addClass("input"); |
147 | ||
148 | var inputbox = new Element("input"); | |
fc38a626 | 149 | this.addEvent("signedOn", function() { |
1761242b | 150 | inputbox.placeholder = "chat here! you can also use commands, like /JOIN or /HELP"; |
63494576 CP |
151 | var d = function() { inputbox.addClass("input-flash"); }.delay(250); |
152 | var d = function() { inputbox.removeClass("input-flash"); }.delay(500); | |
153 | var d = function() { inputbox.addClass("input-flash"); }.delay(750); | |
154 | var d = function() { inputbox.removeClass("input-flash"); }.delay(1000); | |
155 | var d = function() { inputbox.addClass("input-flash"); }.delay(1250); | |
156 | var d = function() { inputbox.removeClass("input-flash"); }.delay(1750); | |
fc38a626 | 157 | }); |
e20e5a6b CP |
158 | form.appendChild(inputbox); |
159 | this.inputbox = inputbox; | |
7c82e345 | 160 | this.inputbox.maxLength = 470; |
c1416a8d CP |
161 | |
162 | var sendInput = function() { | |
e20e5a6b CP |
163 | if(inputbox.value == "") |
164 | return; | |
165 | ||
3184781b | 166 | this.resetTabComplete(); |
e20e5a6b CP |
167 | this.getActiveWindow().historyExec(inputbox.value); |
168 | inputbox.value = ""; | |
fc38a626 | 169 | inputbox.placeholder = ""; |
c1416a8d CP |
170 | }.bind(this); |
171 | ||
172 | if(!qwebirc.util.deviceHasKeyboard()) { | |
173 | inputbox.addClass("mobile-input"); | |
174 | var inputButton = new Element("input", {type: "button"}); | |
175 | inputButton.addClass("mobile-button"); | |
176 | inputButton.addEvent("click", function() { | |
177 | sendInput(); | |
178 | inputbox.focus(); | |
179 | }); | |
180 | inputButton.value = ">"; | |
181 | this.input.appendChild(inputButton); | |
182 | var reflowButton = function() { | |
183 | var containerSize = this.input.getSize(); | |
184 | var buttonSize = inputButton.getSize(); | |
185 | ||
186 | var buttonLeft = containerSize.x - buttonSize.x - 5; /* lovely 5 */ | |
187 | ||
188 | inputButton.setStyle("left", buttonLeft); | |
189 | inputbox.setStyle("width", buttonLeft - 5); | |
190 | inputButton.setStyle("height", containerSize.y); | |
191 | }.bind(this); | |
192 | this.qjsui.addEvent("reflow", reflowButton); | |
193 | } else { | |
194 | inputbox.addClass("keyboard-input"); | |
195 | } | |
196 | ||
197 | form.addEvent("submit", function(e) { | |
198 | new Event(e).stop(); | |
199 | sendInput(); | |
200 | }); | |
e20e5a6b | 201 | |
3184781b CP |
202 | inputbox.addEvent("focus", this.resetTabComplete.bind(this)); |
203 | inputbox.addEvent("mousedown", this.resetTabComplete.bind(this)); | |
204 | ||
e20e5a6b CP |
205 | inputbox.addEvent("keydown", function(e) { |
206 | var resultfn; | |
207 | var cvalue = inputbox.value; | |
3184781b | 208 | |
e20e5a6b CP |
209 | if(e.key == "up") { |
210 | resultfn = this.commandhistory.upLine; | |
211 | } else if(e.key == "down") { | |
212 | resultfn = this.commandhistory.downLine; | |
325d6a9f | 213 | } else if(e.key == "tab" && !e.altKey && !e.ctrlKey && !e.shiftKey) { |
3184781b CP |
214 | new Event(e).stop(); |
215 | this.tabComplete(inputbox); | |
216 | return; | |
e20e5a6b | 217 | } else { |
3184781b CP |
218 | /* ideally alt and other keys wouldn't break this */ |
219 | this.resetTabComplete(); | |
e20e5a6b CP |
220 | return; |
221 | } | |
222 | ||
3184781b | 223 | this.resetTabComplete(); |
e20e5a6b CP |
224 | if((cvalue != "") && (this.lastcvalue != cvalue)) |
225 | this.commandhistory.addLine(cvalue, true); | |
226 | ||
227 | var result = resultfn.bind(this.commandhistory)(); | |
228 | ||
229 | new Event(e).stop(); | |
230 | if(!result) | |
231 | result = ""; | |
232 | this.lastcvalue = result; | |
233 | ||
234 | inputbox.value = result; | |
1d6756bc | 235 | qwebirc.util.setAtEnd(inputbox); |
e20e5a6b CP |
236 | }.bind(this)); |
237 | }, | |
238 | setLines: function(lines) { | |
239 | this.lines.parentNode.replaceChild(lines, this.lines); | |
240 | this.qjsui.middle = this.lines = lines; | |
241 | }, | |
242 | setChannelItems: function(nicklist, topic) { | |
243 | if(!$defined(nicklist)) { | |
244 | nicklist = this.orignicklist; | |
245 | topic = this.origtopic; | |
246 | } | |
247 | this.nicklist.parentNode.replaceChild(nicklist, this.nicklist); | |
248 | this.qjsui.right = this.nicklist = nicklist; | |
249 | ||
250 | this.topic.parentNode.replaceChild(topic, this.topic); | |
251 | this.qjsui.topic = this.topic = topic; | |
252 | } | |
253 | }); | |
254 | ||
255 | qwebirc.ui.QUI.JSUI = new Class({ | |
bfbe72f9 | 256 | Implements: [Events], |
b1ee83f3 CP |
257 | initialize: function(class_, parent, sizer) { |
258 | this.parent = parent; | |
259 | this.sizer = $defined(sizer)?sizer:parent; | |
260 | ||
24ede2cb CP |
261 | this.class_ = class_; |
262 | this.create(); | |
263 | ||
6c19eb8f CP |
264 | this.reflowevent = null; |
265 | ||
b1ee83f3 | 266 | window.addEvent("resize", function() { |
6c19eb8f | 267 | this.reflow(100); |
b1ee83f3 CP |
268 | }.bind(this)); |
269 | }, | |
24ede2cb | 270 | applyClasses: function(pos, l) { |
6c19eb8f | 271 | l.addClass("dynamicpanel"); |
24ede2cb | 272 | l.addClass(this.class_); |
6c19eb8f | 273 | |
24ede2cb CP |
274 | if(pos == "middle") { |
275 | l.addClass("leftboundpanel"); | |
276 | } else if(pos == "top") { | |
277 | l.addClass("topboundpanel"); | |
278 | l.addClass("widepanel"); | |
279 | } else if(pos == "topic") { | |
280 | l.addClass("widepanel"); | |
281 | } else if(pos == "right") { | |
282 | l.addClass("rightboundpanel"); | |
283 | } else if(pos == "bottom") { | |
284 | l.addClass("bottomboundpanel"); | |
285 | l.addClass("widepanel"); | |
286 | } | |
287 | }, | |
288 | create: function() { | |
289 | var XE = function(pos) { | |
290 | var element = new Element("div"); | |
291 | this.applyClasses(pos, element); | |
b1ee83f3 | 292 | |
24ede2cb CP |
293 | this.parent.appendChild(element); |
294 | return element; | |
b1ee83f3 CP |
295 | }.bind(this); |
296 | ||
24ede2cb CP |
297 | this.top = XE("top"); |
298 | this.topic = XE("topic"); | |
299 | this.middle = XE("middle"); | |
300 | this.right = XE("right"); | |
301 | this.bottom = XE("bottom"); | |
b1ee83f3 | 302 | }, |
6c19eb8f CP |
303 | reflow: function(delay) { |
304 | if(!delay) | |
305 | delay = 1; | |
306 | ||
307 | if(this.reflowevent) | |
308 | $clear(this.reflowevent); | |
309 | this.__reflow(); | |
310 | this.reflowevent = this.__reflow.delay(delay, this); | |
311 | }, | |
312 | __reflow: function() { | |
b1ee83f3 CP |
313 | var bottom = this.bottom; |
314 | var middle = this.middle; | |
315 | var right = this.right; | |
316 | var topic = this.topic; | |
317 | var top = this.top; | |
318 | ||
319 | var topicsize = topic.getSize(); | |
320 | var topsize = top.getSize(); | |
321 | var rightsize = right.getSize(); | |
322 | var bottomsize = bottom.getSize(); | |
323 | var docsize = this.sizer.getSize(); | |
324 | ||
325 | var mheight = (docsize.y - topsize.y - bottomsize.y - topicsize.y); | |
326 | var mwidth = (docsize.x - rightsize.x); | |
327 | ||
4b9f894d | 328 | topic.setStyle("top", topsize.y); |
b1ee83f3 | 329 | |
4b9f894d | 330 | middle.setStyle("top", (topsize.y + topicsize.y)); |
b1ee83f3 | 331 | if(mheight > 0) { |
4b9f894d CP |
332 | middle.setStyle("height", mheight); |
333 | right.setStyle("height", mheight); | |
b1ee83f3 CP |
334 | } |
335 | ||
6c19eb8f | 336 | if(mwidth > 0) |
4b9f894d CP |
337 | middle.setStyle("width", mwidth); |
338 | right.setStyle("top", (topsize.y + topicsize.y)); | |
339 | right.setStyle("left", mwidth); | |
b1ee83f3 | 340 | |
4b9f894d | 341 | bottom.setStyle("top", (docsize.y - bottomsize.y)); |
bfbe72f9 | 342 | this.fireEvent("reflow"); |
b1ee83f3 | 343 | }, |
5f464ed5 | 344 | showChannel: function(state, nicklistVisible) { |
b1ee83f3 CP |
345 | var display = "none"; |
346 | if(state) | |
347 | display = "block"; | |
348 | ||
5f464ed5 | 349 | this.right.setStyle("display", nicklistVisible ? display : "none"); |
b1ee83f3 | 350 | this.topic.setStyle("display", display); |
6c19eb8f CP |
351 | }, |
352 | showInput: function(state) { | |
941e1642 | 353 | this.bottom.isVisible = state; |
6c19eb8f | 354 | this.bottom.setStyle("display", state?"block":"none"); |
b1ee83f3 CP |
355 | } |
356 | }); | |
35155ba7 | 357 | |
e20e5a6b CP |
358 | qwebirc.ui.QUI.Window = new Class({ |
359 | Extends: qwebirc.ui.Window, | |
f4ae92cc | 360 | |
f74802c5 CP |
361 | initialize: function(parentObject, client, type, name, identifier) { |
362 | this.parent(parentObject, client, type, name, identifier); | |
be0bd774 | 363 | |
66de775f | 364 | this.tab = new Element("a", {"href": "#"}); |
f4ae92cc | 365 | this.tab.addClass("tab"); |
fd60516d | 366 | this.tab.addEvent("focus", function() { this.blur() }.bind(this.tab));; |
ff1c78b3 CP |
367 | |
368 | this.spaceNode = document.createTextNode(" "); | |
35155ba7 | 369 | parentObject.tabs.appendChild(this.tab); |
ff1c78b3 | 370 | parentObject.tabs.appendChild(this.spaceNode); |
f4ae92cc CP |
371 | |
372 | this.tab.appendText(name); | |
66de775f CP |
373 | this.tab.addEvent("click", function(e) { |
374 | new Event(e).stop(); | |
f84bf379 CP |
375 | |
376 | if(this.closed) | |
377 | return; | |
378 | ||
f4ae92cc CP |
379 | parentObject.selectWindow(this); |
380 | }.bind(this)); | |
f4ae92cc | 381 | |
e20e5a6b CP |
382 | if(type != qwebirc.ui.WINDOW_STATUS && type != qwebirc.ui.WINDOW_CONNECT) { |
383 | var tabclose = new Element("span"); | |
384 | tabclose.set("text", "X"); | |
f4ae92cc | 385 | tabclose.addClass("tabclose"); |
f84bf379 | 386 | var close = function(e) { |
f4ae92cc CP |
387 | new Event(e).stop(); |
388 | ||
f84bf379 CP |
389 | if(this.closed) |
390 | return; | |
391 | ||
e20e5a6b | 392 | if(type == qwebirc.ui.WINDOW_CHANNEL) |
f4ae92cc CP |
393 | this.client.exec("/PART " + name); |
394 | ||
395 | this.close(); | |
3184781b | 396 | |
941e1642 | 397 | //parentObject.inputbox.focus(); |
f84bf379 CP |
398 | }.bind(this); |
399 | ||
400 | tabclose.addEvent("click", close); | |
401 | this.tab.addEvent("mouseup", function(e) { | |
b46f79e6 CP |
402 | var button = 1; |
403 | ||
404 | if(Browser.Engine.trident) | |
405 | button = 4; | |
406 | ||
407 | if(e.event.button == button) | |
f84bf379 | 408 | close(e); |
f4ae92cc | 409 | }.bind(this)); |
52090a1f | 410 | |
f4ae92cc CP |
411 | this.tab.appendChild(tabclose); |
412 | } | |
be0bd774 | 413 | |
be0bd774 | 414 | this.lines = new Element("div"); |
6c19eb8f | 415 | this.parentObject.qjsui.applyClasses("middle", this.lines); |
be0bd774 | 416 | this.lines.addClass("lines"); |
e82478eb CP |
417 | if(type != qwebirc.ui.WINDOW_CUSTOM && type != qwebirc.ui.WINDOW_CONNECT) |
418 | this.lines.addClass("ircwindow"); | |
6c19eb8f | 419 | |
b1ee83f3 CP |
420 | this.lines.addEvent("scroll", function() { |
421 | this.scrolleddown = this.scrolledDown(); | |
ff6a32cc | 422 | this.scrollpos = this.getScrollParent().getScroll(); |
be0bd774 | 423 | }.bind(this)); |
be0bd774 | 424 | |
e20e5a6b | 425 | if(type == qwebirc.ui.WINDOW_CHANNEL) { |
be0bd774 CP |
426 | this.topic = new Element("div"); |
427 | this.topic.addClass("topic"); | |
b1ee83f3 | 428 | this.topic.addClass("tab-invisible"); |
be0bd774 | 429 | this.topic.set("html", " "); |
8eb4377c | 430 | this.topic.addEvent("dblclick", this.editTopic.bind(this)); |
6c19eb8f | 431 | this.parentObject.qjsui.applyClasses("topic", this.topic); |
be0bd774 | 432 | |
52090a1f | 433 | this.prevNick = null; |
66de775f CP |
434 | this.nicklist = new Element("div"); |
435 | this.nicklist.addClass("nicklist"); | |
b1ee83f3 | 436 | this.nicklist.addClass("tab-invisible"); |
cffd43cf | 437 | this.nicklist.addEvent("click", this.removePrevMenu.bind(this)); |
6c19eb8f | 438 | this.parentObject.qjsui.applyClasses("nicklist", this.nicklist); |
be0bd774 | 439 | } |
b1ee83f3 | 440 | |
ff1c78b3 | 441 | if(type == qwebirc.ui.WINDOW_CHANNEL) |
359b7edd | 442 | this.updateTopic(""); |
ff1c78b3 | 443 | |
f121b688 | 444 | this.nicksColoured = this.parentObject.uiOptions.NICK_COLOURS; |
ff1c78b3 | 445 | this.reflow(); |
b1ee83f3 | 446 | }, |
5aa173fb CP |
447 | rename: function(name) { |
448 | this.tab.replaceChild(document.createTextNode(name), this.tab.firstChild); | |
449 | }, | |
eaf3ed38 CP |
450 | editTopic: function() { |
451 | if(!this.client.nickOnChanHasPrefix(this.client.nickname, this.name, "@")) { | |
452 | /* var cmodes = this.client.getChannelModes(channel); | |
453 | if(cmodes.indexOf("t")) {*/ | |
95d00e97 | 454 | alert("Sorry, you need to be a channel operator to change the topic!"); |
eaf3ed38 CP |
455 | return; |
456 | /*}*/ | |
457 | } | |
458 | var newTopic = prompt("Change topic of " + this.name + " to:", this.topic.topicText); | |
459 | if(newTopic === null) | |
460 | return; | |
461 | ||
462 | this.client.exec("/TOPIC " + newTopic); | |
463 | }, | |
b1ee83f3 CP |
464 | reflow: function() { |
465 | this.parentObject.reflow(); | |
35155ba7 CP |
466 | }, |
467 | onResize: function() { | |
ff6a32cc CP |
468 | if(this.scrolleddown) { |
469 | if(Browser.Engine.trident) { | |
470 | this.scrollToBottom.delay(5, this); | |
471 | } else { | |
472 | this.scrollToBottom(); | |
473 | } | |
474 | } else if($defined(this.scrollpos)) { | |
475 | if(Browser.Engine.trident) { | |
476 | this.getScrollParent().scrollTo(this.scrollpos.x, this.scrollpos.y); | |
477 | } else { | |
478 | this.getScrollParent().scrollTo.delay(5, this, [this.scrollpos.x, this.scrollpos.y]); | |
479 | } | |
480 | } | |
359b7edd | 481 | }, |
cffd43cf | 482 | createMenu: function(nick, parent) { |
d2512acf | 483 | var e = new Element("div"); |
cffd43cf CP |
484 | parent.appendChild(e); |
485 | e.addClass("menu"); | |
486 | ||
27add99a | 487 | var nickArray = [nick]; |
cffd43cf | 488 | qwebirc.ui.MENU_ITEMS.forEach(function(x) { |
27add99a CP |
489 | if(!x.predicate || x.predicate !== true && !x.predicate.apply(this, nickArray)) |
490 | return; | |
491 | ||
492 | var e2 = new Element("a"); | |
493 | e.appendChild(e2); | |
7555d601 | 494 | |
27add99a CP |
495 | e2.href = "#"; |
496 | e2.set("text", "- " + x.text); | |
7555d601 | 497 | |
27add99a CP |
498 | e2.addEvent("focus", function() { this.blur() }.bind(e2)); |
499 | e2.addEvent("click", function(ev) { new Event(ev.stop()); this.menuClick(x.fn); }.bind(this)); | |
cffd43cf CP |
500 | }.bind(this)); |
501 | return e; | |
502 | }, | |
503 | menuClick: function(fn) { | |
504 | /* | |
505 | this.prevNick.removeChild(this.prevNick.menu); | |
506 | this.prevNick.menu = null; | |
507 | */ | |
508 | fn.bind(this)(this.prevNick.realNick); | |
509 | this.removePrevMenu(); | |
510 | }, | |
d8272bcb CP |
511 | moveMenuClass: function() { |
512 | if(!this.prevNick) | |
513 | return; | |
514 | if(this.nicklist.firstChild == this.prevNick) { | |
515 | this.prevNick.removeClass("selected-middle"); | |
516 | } else { | |
517 | this.prevNick.addClass("selected-middle"); | |
518 | } | |
519 | }, | |
cffd43cf CP |
520 | removePrevMenu: function() { |
521 | if(!this.prevNick) | |
522 | return; | |
523 | ||
524 | this.prevNick.removeClass("selected"); | |
d8272bcb | 525 | this.prevNick.removeClass("selected-middle"); |
cffd43cf CP |
526 | if(this.prevNick.menu) |
527 | this.prevNick.removeChild(this.prevNick.menu); | |
528 | this.prevNick = null; | |
529 | }, | |
52090a1f | 530 | nickListAdd: function(nick, position) { |
f121b688 CP |
531 | var realNick = this.client.stripPrefix(nick); |
532 | ||
52090a1f CP |
533 | var e = new Element("a"); |
534 | qwebirc.ui.insertAt(position, this.nicklist, e); | |
f4ae92cc | 535 | |
52090a1f | 536 | e.href = "#"; |
f121b688 CP |
537 | var span = new Element("span"); |
538 | if(this.parentObject.uiOptions.NICK_COLOURS) { | |
539 | var colour = realNick.toHSBColour(this.client); | |
540 | if($defined(colour)) | |
541 | span.setStyle("color", colour.rgbToHex()); | |
542 | } | |
543 | span.set("text", nick); | |
544 | e.appendChild(span); | |
52090a1f | 545 | |
f121b688 | 546 | e.realNick = realNick; |
52090a1f CP |
547 | |
548 | e.addEvent("click", function(x) { | |
aab6d06a CP |
549 | if(this.prevNick == e) { |
550 | this.removePrevMenu(); | |
551 | return; | |
552 | } | |
553 | ||
cffd43cf | 554 | this.removePrevMenu(); |
52090a1f CP |
555 | this.prevNick = e; |
556 | e.addClass("selected"); | |
d8272bcb | 557 | this.moveMenuClass(); |
27add99a | 558 | e.menu = this.createMenu(e.realNick, e); |
52090a1f CP |
559 | new Event(x).stop(); |
560 | }.bind(this)); | |
52090a1f | 561 | |
fd60516d | 562 | e.addEvent("focus", function() { this.blur() }.bind(e)); |
d8272bcb | 563 | this.moveMenuClass(); |
52090a1f CP |
564 | return e; |
565 | }, | |
566 | nickListRemove: function(nick, stored) { | |
567 | this.nicklist.removeChild(stored); | |
d8272bcb | 568 | this.moveMenuClass(); |
f4ae92cc CP |
569 | }, |
570 | updateTopic: function(topic) { | |
f4ae92cc CP |
571 | var t = this.topic; |
572 | ||
573 | while(t.firstChild) | |
574 | t.removeChild(t.firstChild); | |
575 | ||
66de775f | 576 | if(topic) { |
eaf3ed38 | 577 | t.topicText = topic; |
1f06a70a | 578 | this.parent(topic, t); |
66de775f | 579 | } else { |
eaf3ed38 | 580 | t.topicText = topic; |
359b7edd CP |
581 | var e = new Element("div"); |
582 | e.set("text", "(no topic set)"); | |
66de775f | 583 | e.addClass("emptytopic"); |
359b7edd | 584 | t.appendChild(e); |
66de775f | 585 | } |
359b7edd | 586 | this.reflow(); |
f4ae92cc CP |
587 | }, |
588 | select: function() { | |
e20e5a6b | 589 | var inputVisible = this.type != qwebirc.ui.WINDOW_CONNECT && this.type != qwebirc.ui.WINDOW_CUSTOM; |
6c19eb8f | 590 | |
f4ae92cc | 591 | this.tab.removeClass("tab-unselected"); |
f4ae92cc | 592 | this.tab.addClass("tab-selected"); |
359b7edd | 593 | |
6c19eb8f CP |
594 | this.parentObject.setLines(this.lines); |
595 | this.parentObject.setChannelItems(this.nicklist, this.topic); | |
596 | this.parentObject.qjsui.showInput(inputVisible); | |
5f464ed5 | 597 | this.parentObject.qjsui.showChannel($defined(this.nicklist), this.parentObject.uiOptions.SHOW_NICKLIST); |
6c19eb8f CP |
598 | |
599 | this.reflow(); | |
24ede2cb | 600 | |
7c633700 | 601 | this.parent(); |
25be5960 | 602 | |
6c19eb8f CP |
603 | if(inputVisible) |
604 | this.parentObject.inputbox.focus(); | |
f121b688 CP |
605 | |
606 | if(this.type == qwebirc.ui.WINDOW_CHANNEL && this.nicksColoured != this.parentObject.uiOptions.NICK_COLOURS) { | |
607 | this.nicksColoured = this.parentObject.uiOptions.NICK_COLOURS; | |
608 | ||
609 | var nodes = this.nicklist.childNodes; | |
610 | if(this.parentObject.uiOptions.NICK_COLOURS) { | |
611 | for(var i=0;i<nodes.length;i++) { | |
612 | var e = nodes[i], span = e.firstChild; | |
613 | var colour = e.realNick.toHSBColour(this.client); | |
614 | if($defined(colour)) | |
615 | span.setStyle("color", colour.rgbToHex()); | |
616 | }; | |
617 | } else { | |
618 | for(var i=0;i<nodes.length;i++) { | |
619 | var span = nodes[i].firstChild; | |
620 | span.setStyle("color", null); | |
621 | }; | |
622 | } | |
623 | } | |
f4ae92cc CP |
624 | }, |
625 | deselect: function() { | |
626 | this.parent(); | |
627 | ||
f4ae92cc CP |
628 | this.tab.removeClass("tab-selected"); |
629 | this.tab.addClass("tab-unselected"); | |
630 | }, | |
631 | close: function() { | |
632 | this.parent(); | |
633 | ||
f4ae92cc | 634 | this.parentObject.tabs.removeChild(this.tab); |
ff1c78b3 CP |
635 | this.parentObject.tabs.removeChild(this.spaceNode); |
636 | this.reflow(); | |
f4ae92cc | 637 | }, |
b35116e2 | 638 | addLine: function(type, line, colourClass) { |
f4ae92cc CP |
639 | var e = new Element("div"); |
640 | ||
b35116e2 CP |
641 | if(colourClass) { |
642 | e.addClass(colourClass); | |
f4ae92cc CP |
643 | } else if(this.lastcolour) { |
644 | e.addClass("linestyle1"); | |
645 | } else { | |
646 | e.addClass("linestyle2"); | |
647 | } | |
f4ae92cc | 648 | this.lastcolour = !this.lastcolour; |
35155ba7 | 649 | |
b35116e2 | 650 | this.parent(type, line, colourClass, e); |
be0bd774 CP |
651 | }, |
652 | setHilighted: function(state) { | |
2a802692 | 653 | var laststate = this.hilighted; |
96f28062 | 654 | |
be0bd774 | 655 | this.parent(state); |
96f28062 CP |
656 | |
657 | if(state == laststate) | |
658 | return; | |
659 | ||
660 | this.tab.removeClass("tab-hilight-activity"); | |
661 | this.tab.removeClass("tab-hilight-us"); | |
662 | this.tab.removeClass("tab-hilight-speech"); | |
f4ae92cc | 663 | |
96f28062 CP |
664 | switch(this.hilighted) { |
665 | case qwebirc.ui.HILIGHT_US: | |
666 | this.tab.addClass("tab-hilight-us"); | |
667 | break; | |
668 | case qwebirc.ui.HILIGHT_SPEECH: | |
669 | this.tab.addClass("tab-hilight-speech"); | |
670 | break; | |
671 | case qwebirc.ui.HILIGHT_ACTIVITY: | |
672 | this.tab.addClass("tab-hilight-activity"); | |
673 | break; | |
be0bd774 | 674 | } |
f4ae92cc CP |
675 | } |
676 | }); |