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