]>
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"); | |
149 | form.appendChild(inputbox); | |
150 | this.inputbox = inputbox; | |
2589dfb0 | 151 | this.inputbox.maxLength = 512; |
c1416a8d CP |
152 | |
153 | var sendInput = function() { | |
e20e5a6b CP |
154 | if(inputbox.value == "") |
155 | return; | |
156 | ||
3184781b | 157 | this.resetTabComplete(); |
e20e5a6b CP |
158 | this.getActiveWindow().historyExec(inputbox.value); |
159 | inputbox.value = ""; | |
c1416a8d CP |
160 | }.bind(this); |
161 | ||
162 | if(!qwebirc.util.deviceHasKeyboard()) { | |
163 | inputbox.addClass("mobile-input"); | |
164 | var inputButton = new Element("input", {type: "button"}); | |
165 | inputButton.addClass("mobile-button"); | |
166 | inputButton.addEvent("click", function() { | |
167 | sendInput(); | |
168 | inputbox.focus(); | |
169 | }); | |
170 | inputButton.value = ">"; | |
171 | this.input.appendChild(inputButton); | |
172 | var reflowButton = function() { | |
173 | var containerSize = this.input.getSize(); | |
174 | var buttonSize = inputButton.getSize(); | |
175 | ||
176 | var buttonLeft = containerSize.x - buttonSize.x - 5; /* lovely 5 */ | |
177 | ||
178 | inputButton.setStyle("left", buttonLeft); | |
179 | inputbox.setStyle("width", buttonLeft - 5); | |
180 | inputButton.setStyle("height", containerSize.y); | |
181 | }.bind(this); | |
182 | this.qjsui.addEvent("reflow", reflowButton); | |
183 | } else { | |
184 | inputbox.addClass("keyboard-input"); | |
185 | } | |
186 | ||
187 | form.addEvent("submit", function(e) { | |
188 | new Event(e).stop(); | |
189 | sendInput(); | |
190 | }); | |
e20e5a6b | 191 | |
3184781b CP |
192 | inputbox.addEvent("focus", this.resetTabComplete.bind(this)); |
193 | inputbox.addEvent("mousedown", this.resetTabComplete.bind(this)); | |
194 | ||
e20e5a6b CP |
195 | inputbox.addEvent("keydown", function(e) { |
196 | var resultfn; | |
197 | var cvalue = inputbox.value; | |
3184781b | 198 | |
e20e5a6b CP |
199 | if(e.key == "up") { |
200 | resultfn = this.commandhistory.upLine; | |
201 | } else if(e.key == "down") { | |
202 | resultfn = this.commandhistory.downLine; | |
3184781b CP |
203 | } else if(e.key == "tab") { |
204 | new Event(e).stop(); | |
205 | this.tabComplete(inputbox); | |
206 | return; | |
e20e5a6b | 207 | } else { |
3184781b CP |
208 | /* ideally alt and other keys wouldn't break this */ |
209 | this.resetTabComplete(); | |
e20e5a6b CP |
210 | return; |
211 | } | |
212 | ||
3184781b | 213 | this.resetTabComplete(); |
e20e5a6b CP |
214 | if((cvalue != "") && (this.lastcvalue != cvalue)) |
215 | this.commandhistory.addLine(cvalue, true); | |
216 | ||
217 | var result = resultfn.bind(this.commandhistory)(); | |
218 | ||
219 | new Event(e).stop(); | |
220 | if(!result) | |
221 | result = ""; | |
222 | this.lastcvalue = result; | |
223 | ||
224 | inputbox.value = result; | |
1d6756bc | 225 | qwebirc.util.setAtEnd(inputbox); |
e20e5a6b CP |
226 | }.bind(this)); |
227 | }, | |
228 | setLines: function(lines) { | |
229 | this.lines.parentNode.replaceChild(lines, this.lines); | |
230 | this.qjsui.middle = this.lines = lines; | |
231 | }, | |
232 | setChannelItems: function(nicklist, topic) { | |
233 | if(!$defined(nicklist)) { | |
234 | nicklist = this.orignicklist; | |
235 | topic = this.origtopic; | |
236 | } | |
237 | this.nicklist.parentNode.replaceChild(nicklist, this.nicklist); | |
238 | this.qjsui.right = this.nicklist = nicklist; | |
239 | ||
240 | this.topic.parentNode.replaceChild(topic, this.topic); | |
241 | this.qjsui.topic = this.topic = topic; | |
242 | } | |
243 | }); | |
244 | ||
245 | qwebirc.ui.QUI.JSUI = new Class({ | |
bfbe72f9 | 246 | Implements: [Events], |
b1ee83f3 CP |
247 | initialize: function(class_, parent, sizer) { |
248 | this.parent = parent; | |
249 | this.sizer = $defined(sizer)?sizer:parent; | |
250 | ||
24ede2cb CP |
251 | this.class_ = class_; |
252 | this.create(); | |
253 | ||
6c19eb8f CP |
254 | this.reflowevent = null; |
255 | ||
b1ee83f3 | 256 | window.addEvent("resize", function() { |
6c19eb8f | 257 | this.reflow(100); |
b1ee83f3 CP |
258 | }.bind(this)); |
259 | }, | |
24ede2cb | 260 | applyClasses: function(pos, l) { |
6c19eb8f | 261 | l.addClass("dynamicpanel"); |
24ede2cb | 262 | l.addClass(this.class_); |
6c19eb8f | 263 | |
24ede2cb CP |
264 | if(pos == "middle") { |
265 | l.addClass("leftboundpanel"); | |
266 | } else if(pos == "top") { | |
267 | l.addClass("topboundpanel"); | |
268 | l.addClass("widepanel"); | |
269 | } else if(pos == "topic") { | |
270 | l.addClass("widepanel"); | |
271 | } else if(pos == "right") { | |
272 | l.addClass("rightboundpanel"); | |
273 | } else if(pos == "bottom") { | |
274 | l.addClass("bottomboundpanel"); | |
275 | l.addClass("widepanel"); | |
276 | } | |
277 | }, | |
278 | create: function() { | |
279 | var XE = function(pos) { | |
280 | var element = new Element("div"); | |
281 | this.applyClasses(pos, element); | |
b1ee83f3 | 282 | |
24ede2cb CP |
283 | this.parent.appendChild(element); |
284 | return element; | |
b1ee83f3 CP |
285 | }.bind(this); |
286 | ||
24ede2cb CP |
287 | this.top = XE("top"); |
288 | this.topic = XE("topic"); | |
289 | this.middle = XE("middle"); | |
290 | this.right = XE("right"); | |
291 | this.bottom = XE("bottom"); | |
b1ee83f3 | 292 | }, |
6c19eb8f CP |
293 | reflow: function(delay) { |
294 | if(!delay) | |
295 | delay = 1; | |
296 | ||
297 | if(this.reflowevent) | |
298 | $clear(this.reflowevent); | |
299 | this.__reflow(); | |
300 | this.reflowevent = this.__reflow.delay(delay, this); | |
301 | }, | |
302 | __reflow: function() { | |
b1ee83f3 CP |
303 | var bottom = this.bottom; |
304 | var middle = this.middle; | |
305 | var right = this.right; | |
306 | var topic = this.topic; | |
307 | var top = this.top; | |
308 | ||
309 | var topicsize = topic.getSize(); | |
310 | var topsize = top.getSize(); | |
311 | var rightsize = right.getSize(); | |
312 | var bottomsize = bottom.getSize(); | |
313 | var docsize = this.sizer.getSize(); | |
314 | ||
315 | var mheight = (docsize.y - topsize.y - bottomsize.y - topicsize.y); | |
316 | var mwidth = (docsize.x - rightsize.x); | |
317 | ||
4b9f894d | 318 | topic.setStyle("top", topsize.y); |
b1ee83f3 | 319 | |
4b9f894d | 320 | middle.setStyle("top", (topsize.y + topicsize.y)); |
b1ee83f3 | 321 | if(mheight > 0) { |
4b9f894d CP |
322 | middle.setStyle("height", mheight); |
323 | right.setStyle("height", mheight); | |
b1ee83f3 CP |
324 | } |
325 | ||
6c19eb8f | 326 | if(mwidth > 0) |
4b9f894d CP |
327 | middle.setStyle("width", mwidth); |
328 | right.setStyle("top", (topsize.y + topicsize.y)); | |
329 | right.setStyle("left", mwidth); | |
b1ee83f3 | 330 | |
4b9f894d | 331 | bottom.setStyle("top", (docsize.y - bottomsize.y)); |
bfbe72f9 | 332 | this.fireEvent("reflow"); |
b1ee83f3 | 333 | }, |
5f464ed5 | 334 | showChannel: function(state, nicklistVisible) { |
b1ee83f3 CP |
335 | var display = "none"; |
336 | if(state) | |
337 | display = "block"; | |
338 | ||
5f464ed5 | 339 | this.right.setStyle("display", nicklistVisible ? display : "none"); |
b1ee83f3 | 340 | this.topic.setStyle("display", display); |
6c19eb8f CP |
341 | }, |
342 | showInput: function(state) { | |
941e1642 | 343 | this.bottom.isVisible = state; |
6c19eb8f | 344 | this.bottom.setStyle("display", state?"block":"none"); |
b1ee83f3 CP |
345 | } |
346 | }); | |
35155ba7 | 347 | |
e20e5a6b CP |
348 | qwebirc.ui.QUI.Window = new Class({ |
349 | Extends: qwebirc.ui.Window, | |
f4ae92cc | 350 | |
f74802c5 CP |
351 | initialize: function(parentObject, client, type, name, identifier) { |
352 | this.parent(parentObject, client, type, name, identifier); | |
be0bd774 | 353 | |
66de775f | 354 | this.tab = new Element("a", {"href": "#"}); |
f4ae92cc | 355 | this.tab.addClass("tab"); |
fd60516d | 356 | this.tab.addEvent("focus", function() { this.blur() }.bind(this.tab));; |
ff1c78b3 CP |
357 | |
358 | this.spaceNode = document.createTextNode(" "); | |
35155ba7 | 359 | parentObject.tabs.appendChild(this.tab); |
ff1c78b3 | 360 | parentObject.tabs.appendChild(this.spaceNode); |
f4ae92cc CP |
361 | |
362 | this.tab.appendText(name); | |
66de775f CP |
363 | this.tab.addEvent("click", function(e) { |
364 | new Event(e).stop(); | |
f84bf379 CP |
365 | |
366 | if(this.closed) | |
367 | return; | |
368 | ||
f4ae92cc CP |
369 | parentObject.selectWindow(this); |
370 | }.bind(this)); | |
f4ae92cc | 371 | |
e20e5a6b CP |
372 | if(type != qwebirc.ui.WINDOW_STATUS && type != qwebirc.ui.WINDOW_CONNECT) { |
373 | var tabclose = new Element("span"); | |
374 | tabclose.set("text", "X"); | |
f4ae92cc | 375 | tabclose.addClass("tabclose"); |
f84bf379 | 376 | var close = function(e) { |
f4ae92cc CP |
377 | new Event(e).stop(); |
378 | ||
f84bf379 CP |
379 | if(this.closed) |
380 | return; | |
381 | ||
e20e5a6b | 382 | if(type == qwebirc.ui.WINDOW_CHANNEL) |
f4ae92cc CP |
383 | this.client.exec("/PART " + name); |
384 | ||
385 | this.close(); | |
3184781b | 386 | |
941e1642 | 387 | //parentObject.inputbox.focus(); |
f84bf379 CP |
388 | }.bind(this); |
389 | ||
390 | tabclose.addEvent("click", close); | |
391 | this.tab.addEvent("mouseup", function(e) { | |
b46f79e6 CP |
392 | var button = 1; |
393 | ||
394 | if(Browser.Engine.trident) | |
395 | button = 4; | |
396 | ||
397 | if(e.event.button == button) | |
f84bf379 | 398 | close(e); |
f4ae92cc | 399 | }.bind(this)); |
52090a1f | 400 | |
f4ae92cc CP |
401 | this.tab.appendChild(tabclose); |
402 | } | |
be0bd774 | 403 | |
be0bd774 | 404 | this.lines = new Element("div"); |
6c19eb8f | 405 | this.parentObject.qjsui.applyClasses("middle", this.lines); |
be0bd774 | 406 | this.lines.addClass("lines"); |
e82478eb CP |
407 | if(type != qwebirc.ui.WINDOW_CUSTOM && type != qwebirc.ui.WINDOW_CONNECT) |
408 | this.lines.addClass("ircwindow"); | |
6c19eb8f | 409 | |
b1ee83f3 CP |
410 | this.lines.addEvent("scroll", function() { |
411 | this.scrolleddown = this.scrolledDown(); | |
ff6a32cc | 412 | this.scrollpos = this.getScrollParent().getScroll(); |
be0bd774 | 413 | }.bind(this)); |
be0bd774 | 414 | |
e20e5a6b | 415 | if(type == qwebirc.ui.WINDOW_CHANNEL) { |
be0bd774 CP |
416 | this.topic = new Element("div"); |
417 | this.topic.addClass("topic"); | |
b1ee83f3 | 418 | this.topic.addClass("tab-invisible"); |
be0bd774 | 419 | this.topic.set("html", " "); |
8eb4377c | 420 | this.topic.addEvent("dblclick", this.editTopic.bind(this)); |
6c19eb8f | 421 | this.parentObject.qjsui.applyClasses("topic", this.topic); |
be0bd774 | 422 | |
52090a1f | 423 | this.prevNick = null; |
66de775f CP |
424 | this.nicklist = new Element("div"); |
425 | this.nicklist.addClass("nicklist"); | |
b1ee83f3 | 426 | this.nicklist.addClass("tab-invisible"); |
cffd43cf | 427 | this.nicklist.addEvent("click", this.removePrevMenu.bind(this)); |
6c19eb8f | 428 | this.parentObject.qjsui.applyClasses("nicklist", this.nicklist); |
be0bd774 | 429 | } |
b1ee83f3 | 430 | |
ff1c78b3 | 431 | if(type == qwebirc.ui.WINDOW_CHANNEL) |
359b7edd | 432 | this.updateTopic(""); |
ff1c78b3 | 433 | |
f121b688 | 434 | this.nicksColoured = this.parentObject.uiOptions.NICK_COLOURS; |
ff1c78b3 | 435 | this.reflow(); |
b1ee83f3 | 436 | }, |
eaf3ed38 CP |
437 | editTopic: function() { |
438 | if(!this.client.nickOnChanHasPrefix(this.client.nickname, this.name, "@")) { | |
439 | /* var cmodes = this.client.getChannelModes(channel); | |
440 | if(cmodes.indexOf("t")) {*/ | |
95d00e97 | 441 | alert("Sorry, you need to be a channel operator to change the topic!"); |
eaf3ed38 CP |
442 | return; |
443 | /*}*/ | |
444 | } | |
445 | var newTopic = prompt("Change topic of " + this.name + " to:", this.topic.topicText); | |
446 | if(newTopic === null) | |
447 | return; | |
448 | ||
449 | this.client.exec("/TOPIC " + newTopic); | |
450 | }, | |
b1ee83f3 CP |
451 | reflow: function() { |
452 | this.parentObject.reflow(); | |
35155ba7 CP |
453 | }, |
454 | onResize: function() { | |
ff6a32cc CP |
455 | if(this.scrolleddown) { |
456 | if(Browser.Engine.trident) { | |
457 | this.scrollToBottom.delay(5, this); | |
458 | } else { | |
459 | this.scrollToBottom(); | |
460 | } | |
461 | } else if($defined(this.scrollpos)) { | |
462 | if(Browser.Engine.trident) { | |
463 | this.getScrollParent().scrollTo(this.scrollpos.x, this.scrollpos.y); | |
464 | } else { | |
465 | this.getScrollParent().scrollTo.delay(5, this, [this.scrollpos.x, this.scrollpos.y]); | |
466 | } | |
467 | } | |
359b7edd | 468 | }, |
cffd43cf | 469 | createMenu: function(nick, parent) { |
d2512acf | 470 | var e = new Element("div"); |
cffd43cf CP |
471 | parent.appendChild(e); |
472 | e.addClass("menu"); | |
473 | ||
27add99a | 474 | var nickArray = [nick]; |
cffd43cf | 475 | qwebirc.ui.MENU_ITEMS.forEach(function(x) { |
27add99a CP |
476 | if(!x.predicate || x.predicate !== true && !x.predicate.apply(this, nickArray)) |
477 | return; | |
478 | ||
479 | var e2 = new Element("a"); | |
480 | e.appendChild(e2); | |
7555d601 | 481 | |
27add99a CP |
482 | e2.href = "#"; |
483 | e2.set("text", "- " + x.text); | |
7555d601 | 484 | |
27add99a CP |
485 | e2.addEvent("focus", function() { this.blur() }.bind(e2)); |
486 | e2.addEvent("click", function(ev) { new Event(ev.stop()); this.menuClick(x.fn); }.bind(this)); | |
cffd43cf CP |
487 | }.bind(this)); |
488 | return e; | |
489 | }, | |
490 | menuClick: function(fn) { | |
491 | /* | |
492 | this.prevNick.removeChild(this.prevNick.menu); | |
493 | this.prevNick.menu = null; | |
494 | */ | |
495 | fn.bind(this)(this.prevNick.realNick); | |
496 | this.removePrevMenu(); | |
497 | }, | |
d8272bcb CP |
498 | moveMenuClass: function() { |
499 | if(!this.prevNick) | |
500 | return; | |
501 | if(this.nicklist.firstChild == this.prevNick) { | |
502 | this.prevNick.removeClass("selected-middle"); | |
503 | } else { | |
504 | this.prevNick.addClass("selected-middle"); | |
505 | } | |
506 | }, | |
cffd43cf CP |
507 | removePrevMenu: function() { |
508 | if(!this.prevNick) | |
509 | return; | |
510 | ||
511 | this.prevNick.removeClass("selected"); | |
d8272bcb | 512 | this.prevNick.removeClass("selected-middle"); |
cffd43cf CP |
513 | if(this.prevNick.menu) |
514 | this.prevNick.removeChild(this.prevNick.menu); | |
515 | this.prevNick = null; | |
516 | }, | |
52090a1f | 517 | nickListAdd: function(nick, position) { |
f121b688 CP |
518 | var realNick = this.client.stripPrefix(nick); |
519 | ||
52090a1f CP |
520 | var e = new Element("a"); |
521 | qwebirc.ui.insertAt(position, this.nicklist, e); | |
f4ae92cc | 522 | |
52090a1f | 523 | e.href = "#"; |
f121b688 CP |
524 | var span = new Element("span"); |
525 | if(this.parentObject.uiOptions.NICK_COLOURS) { | |
526 | var colour = realNick.toHSBColour(this.client); | |
527 | if($defined(colour)) | |
528 | span.setStyle("color", colour.rgbToHex()); | |
529 | } | |
530 | span.set("text", nick); | |
531 | e.appendChild(span); | |
52090a1f | 532 | |
f121b688 | 533 | e.realNick = realNick; |
52090a1f CP |
534 | |
535 | e.addEvent("click", function(x) { | |
aab6d06a CP |
536 | if(this.prevNick == e) { |
537 | this.removePrevMenu(); | |
538 | return; | |
539 | } | |
540 | ||
cffd43cf | 541 | this.removePrevMenu(); |
52090a1f CP |
542 | this.prevNick = e; |
543 | e.addClass("selected"); | |
d8272bcb | 544 | this.moveMenuClass(); |
27add99a | 545 | e.menu = this.createMenu(e.realNick, e); |
52090a1f CP |
546 | new Event(x).stop(); |
547 | }.bind(this)); | |
52090a1f | 548 | |
fd60516d | 549 | e.addEvent("focus", function() { this.blur() }.bind(e)); |
d8272bcb | 550 | this.moveMenuClass(); |
52090a1f CP |
551 | return e; |
552 | }, | |
553 | nickListRemove: function(nick, stored) { | |
554 | this.nicklist.removeChild(stored); | |
d8272bcb | 555 | this.moveMenuClass(); |
f4ae92cc CP |
556 | }, |
557 | updateTopic: function(topic) { | |
f4ae92cc CP |
558 | var t = this.topic; |
559 | ||
560 | while(t.firstChild) | |
561 | t.removeChild(t.firstChild); | |
562 | ||
66de775f | 563 | if(topic) { |
eaf3ed38 | 564 | t.topicText = topic; |
1f06a70a | 565 | this.parent(topic, t); |
66de775f | 566 | } else { |
eaf3ed38 | 567 | t.topicText = topic; |
359b7edd CP |
568 | var e = new Element("div"); |
569 | e.set("text", "(no topic set)"); | |
66de775f | 570 | e.addClass("emptytopic"); |
359b7edd | 571 | t.appendChild(e); |
66de775f | 572 | } |
359b7edd | 573 | this.reflow(); |
f4ae92cc CP |
574 | }, |
575 | select: function() { | |
e20e5a6b | 576 | var inputVisible = this.type != qwebirc.ui.WINDOW_CONNECT && this.type != qwebirc.ui.WINDOW_CUSTOM; |
6c19eb8f | 577 | |
f4ae92cc | 578 | this.tab.removeClass("tab-unselected"); |
f4ae92cc | 579 | this.tab.addClass("tab-selected"); |
359b7edd | 580 | |
6c19eb8f CP |
581 | this.parentObject.setLines(this.lines); |
582 | this.parentObject.setChannelItems(this.nicklist, this.topic); | |
583 | this.parentObject.qjsui.showInput(inputVisible); | |
5f464ed5 | 584 | this.parentObject.qjsui.showChannel($defined(this.nicklist), this.parentObject.uiOptions.SHOW_NICKLIST); |
6c19eb8f CP |
585 | |
586 | this.reflow(); | |
24ede2cb | 587 | |
7c633700 | 588 | this.parent(); |
25be5960 | 589 | |
6c19eb8f CP |
590 | if(inputVisible) |
591 | this.parentObject.inputbox.focus(); | |
f121b688 CP |
592 | |
593 | if(this.type == qwebirc.ui.WINDOW_CHANNEL && this.nicksColoured != this.parentObject.uiOptions.NICK_COLOURS) { | |
594 | this.nicksColoured = this.parentObject.uiOptions.NICK_COLOURS; | |
595 | ||
596 | var nodes = this.nicklist.childNodes; | |
597 | if(this.parentObject.uiOptions.NICK_COLOURS) { | |
598 | for(var i=0;i<nodes.length;i++) { | |
599 | var e = nodes[i], span = e.firstChild; | |
600 | var colour = e.realNick.toHSBColour(this.client); | |
601 | if($defined(colour)) | |
602 | span.setStyle("color", colour.rgbToHex()); | |
603 | }; | |
604 | } else { | |
605 | for(var i=0;i<nodes.length;i++) { | |
606 | var span = nodes[i].firstChild; | |
607 | span.setStyle("color", null); | |
608 | }; | |
609 | } | |
610 | } | |
f4ae92cc CP |
611 | }, |
612 | deselect: function() { | |
613 | this.parent(); | |
614 | ||
f4ae92cc CP |
615 | this.tab.removeClass("tab-selected"); |
616 | this.tab.addClass("tab-unselected"); | |
617 | }, | |
618 | close: function() { | |
619 | this.parent(); | |
620 | ||
f4ae92cc | 621 | this.parentObject.tabs.removeChild(this.tab); |
ff1c78b3 CP |
622 | this.parentObject.tabs.removeChild(this.spaceNode); |
623 | this.reflow(); | |
f4ae92cc | 624 | }, |
b35116e2 | 625 | addLine: function(type, line, colourClass) { |
f4ae92cc CP |
626 | var e = new Element("div"); |
627 | ||
b35116e2 CP |
628 | if(colourClass) { |
629 | e.addClass(colourClass); | |
f4ae92cc CP |
630 | } else if(this.lastcolour) { |
631 | e.addClass("linestyle1"); | |
632 | } else { | |
633 | e.addClass("linestyle2"); | |
634 | } | |
f4ae92cc | 635 | this.lastcolour = !this.lastcolour; |
35155ba7 | 636 | |
b35116e2 | 637 | this.parent(type, line, colourClass, e); |
be0bd774 CP |
638 | }, |
639 | setHilighted: function(state) { | |
2a802692 | 640 | var laststate = this.hilighted; |
96f28062 | 641 | |
be0bd774 | 642 | this.parent(state); |
96f28062 CP |
643 | |
644 | if(state == laststate) | |
645 | return; | |
646 | ||
647 | this.tab.removeClass("tab-hilight-activity"); | |
648 | this.tab.removeClass("tab-hilight-us"); | |
649 | this.tab.removeClass("tab-hilight-speech"); | |
f4ae92cc | 650 | |
96f28062 CP |
651 | switch(this.hilighted) { |
652 | case qwebirc.ui.HILIGHT_US: | |
653 | this.tab.addClass("tab-hilight-us"); | |
654 | break; | |
655 | case qwebirc.ui.HILIGHT_SPEECH: | |
656 | this.tab.addClass("tab-hilight-speech"); | |
657 | break; | |
658 | case qwebirc.ui.HILIGHT_ACTIVITY: | |
659 | this.tab.addClass("tab-hilight-activity"); | |
660 | break; | |
be0bd774 | 661 | } |
f4ae92cc CP |
662 | } |
663 | }); |