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