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