]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/qui.js
1 qwebirc
.ui
.QUI
= new Class({
2 Extends: qwebirc
.ui
.NewLoginUI
,
3 initialize: function(parentElement
, theme
, options
) {
4 this.parent(parentElement
, qwebirc
.ui
.QUI
.Window
, "qui", options
);
6 this.parentElement
= parentElement
;
8 postInitialize: function() {
9 this.qjsui
= new qwebirc
.ui
.QUI
.JSUI("qwebirc-qui", this.parentElement
);
10 this.qjsui
.addEvent("reflow", function() {
11 var w
= this.getActiveWindow();
15 this.qjsui
.top
.addClass("tabbar");
17 this.qjsui
.bottom
.addClass("input");
18 this.qjsui
.right
.addClass("nicklist");
19 this.qjsui
.topic
.addClass("topic");
20 this.qjsui
.middle
.addClass("lines");
22 this.tabs
= this.qjsui
.top
;
23 this.origtopic
= this.topic
= this.qjsui
.topic
;
24 this.origlines
= this.lines
= this.qjsui
.middle
;
25 this.orignicklist
= this.nicklist
= this.qjsui
.right
;
27 this.input
= this.qjsui
.bottom
;
28 this.reflow
= this.qjsui
.reflow
.bind(this.qjsui
);
30 this.tabs
.addEvent("mousewheel", function(x
) {
31 var event
= new Event(x
);
36 } else if(event
.wheel
< 0) {
46 createInput: function() {
47 var form
= new Element("form");
48 this.input
.appendChild(form
);
49 form
.addClass("input");
51 var inputbox
= new Element("input");
52 form
.appendChild(inputbox
);
53 this.inputbox
= inputbox
;
55 form
.addEvent("submit", function(e
) {
58 if(inputbox
.value
== "")
61 this.resetTabComplete();
62 this.getActiveWindow().historyExec(inputbox
.value
);
66 inputbox
.addEvent("focus", this.resetTabComplete
.bind(this));
67 inputbox
.addEvent("mousedown", this.resetTabComplete
.bind(this));
69 inputbox
.addEvent("keydown", function(e
) {
71 var cvalue
= inputbox
.value
;
74 resultfn
= this.commandhistory
.upLine
;
75 } else if(e
.key
== "down") {
76 resultfn
= this.commandhistory
.downLine
;
77 } else if(e
.key
== "tab") {
79 this.tabComplete(inputbox
);
82 /* ideally alt and other keys wouldn't break this */
83 this.resetTabComplete();
87 this.resetTabComplete();
88 if((cvalue
!= "") && (this.lastcvalue
!= cvalue
))
89 this.commandhistory
.addLine(cvalue
, true);
91 var result
= resultfn
.bind(this.commandhistory
)();
96 this.lastcvalue
= result
;
98 inputbox
.value
= result
;
99 qwebirc
.util
.setAtEnd(inputbox
);
102 setLines: function(lines
) {
103 this.lines
.parentNode
.replaceChild(lines
, this.lines
);
104 this.qjsui
.middle
= this.lines
= lines
;
106 setChannelItems: function(nicklist
, topic
) {
107 if(!$defined(nicklist
)) {
108 nicklist
= this.orignicklist
;
109 topic
= this.origtopic
;
111 this.nicklist
.parentNode
.replaceChild(nicklist
, this.nicklist
);
112 this.qjsui
.right
= this.nicklist
= nicklist
;
114 this.topic
.parentNode
.replaceChild(topic
, this.topic
);
115 this.qjsui
.topic
= this.topic
= topic
;
119 qwebirc
.ui
.QUI
.JSUI
= new Class({
120 Implements: [Events
],
121 initialize: function(class_
, parent
, sizer
) {
122 this.parent
= parent
;
123 this.sizer
= $defined(sizer
)?sizer:parent
;
125 this.class_
= class_
;
128 this.reflowevent
= null;
130 window
.addEvent("resize", function() {
134 applyClasses: function(pos
, l
) {
135 l
.addClass("dynamicpanel");
136 l
.addClass(this.class_
);
138 if(pos
== "middle") {
139 l
.addClass("leftboundpanel");
140 } else if(pos
== "top") {
141 l
.addClass("topboundpanel");
142 l
.addClass("widepanel");
143 } else if(pos
== "topic") {
144 l
.addClass("widepanel");
145 } else if(pos
== "right") {
146 l
.addClass("rightboundpanel");
147 } else if(pos
== "bottom") {
148 l
.addClass("bottomboundpanel");
149 l
.addClass("widepanel");
153 var XE = function(pos
) {
154 var element
= new Element("div");
155 this.applyClasses(pos
, element
);
157 this.parent
.appendChild(element
);
161 this.top
= XE("top");
162 this.topic
= XE("topic");
163 this.middle
= XE("middle");
164 this.right
= XE("right");
165 this.bottom
= XE("bottom");
167 reflow: function(delay
) {
172 $clear(this.reflowevent
);
174 this.reflowevent
= this.__reflow
.delay(delay
, this);
176 __reflow: function() {
177 var bottom
= this.bottom
;
178 var middle
= this.middle
;
179 var right
= this.right
;
180 var topic
= this.topic
;
183 var topicsize
= topic
.getSize();
184 var topsize
= top
.getSize();
185 var rightsize
= right
.getSize();
186 var bottomsize
= bottom
.getSize();
187 var docsize
= this.sizer
.getSize();
189 var mheight
= (docsize
.y
- topsize
.y
- bottomsize
.y
- topicsize
.y
);
190 var mwidth
= (docsize
.x
- rightsize
.x
);
192 topic
.setStyle("top", topsize
.y
+ "px");
194 middle
.setStyle("top", (topsize
.y
+ topicsize
.y
) + "px");
196 middle
.setStyle("height", mheight
+ "px");
197 right
.setStyle("height", mheight
+ "px");
201 middle
.setStyle("width", mwidth
+ "px");
202 right
.setStyle("top", (topsize
.y
+ topicsize
.y
) + "px");
203 right
.setStyle("left", mwidth
+ "px");
205 bottom
.setStyle("top", (docsize
.y
- bottomsize
.y
) + "px");
206 this.fireEvent("reflow");
208 showChannel: function(state
) {
209 var display
= "none";
213 this.right
.setStyle("display", display
);
214 this.topic
.setStyle("display", display
);
216 showInput: function(state
) {
217 this.bottom
.setStyle("display", state
?"block":"none");
221 qwebirc
.ui
.QUI
.Window
= new Class({
222 Extends: qwebirc
.ui
.Window
,
224 initialize: function(parentObject
, client
, type
, name
, identifier
) {
225 this.parent(parentObject
, client
, type
, name
, identifier
);
227 this.tab
= new Element("a", {"href": "#"});
228 this.tab
.addClass("tab");
229 this.tab
.addEvent("focus", function() { this.blur() }.bind(this.tab
));;
231 parentObject
.tabs
.appendChild(this.tab
);
233 this.tab
.appendText(name
);
234 this.tab
.addEvent("click", function(e
) {
240 parentObject
.selectWindow(this);
243 if(type
!= qwebirc
.ui
.WINDOW_STATUS
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
) {
244 var tabclose
= new Element("span");
245 tabclose
.set("text", "X");
246 tabclose
.addClass("tabclose");
247 var close = function(e
) {
253 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
254 this.client
.exec("/PART " + name
);
258 parentObject
.inputbox
.focus();
261 tabclose
.addEvent("click", close
);
262 this.tab
.addEvent("mouseup", function(e
) {
265 if(Browser
.Engine
.trident
)
268 if(e
.event
.button
== button
)
272 this.tab
.appendChild(tabclose
);
275 this.lines
= new Element("div");
276 this.parentObject
.qjsui
.applyClasses("middle", this.lines
);
277 this.lines
.addClass("lines");
278 if(type
!= qwebirc
.ui
.WINDOW_CUSTOM
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
)
279 this.lines
.addClass("ircwindow");
281 this.lines
.addEvent("scroll", function() {
282 this.scrolleddown
= this.scrolledDown();
283 this.scrollpos
= this.getScrollParent().getScroll();
286 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
287 this.topic
= new Element("div");
288 this.topic
.addClass("topic");
289 this.topic
.addClass("tab-invisible");
290 this.topic
.set("html", " ");
291 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
293 this.prevNick
= null;
294 this.nicklist
= new Element("div");
295 this.nicklist
.addClass("nicklist");
296 this.nicklist
.addClass("tab-invisible");
297 this.nicklist
.addEvent("click", this.removePrevMenu
.bind(this));
298 this.parentObject
.qjsui
.applyClasses("nicklist", this.nicklist
);
301 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
302 this.updateTopic("");
308 this.parentObject
.reflow();
310 onResize: function() {
311 if(this.scrolleddown
) {
312 if(Browser
.Engine
.trident
) {
313 this.scrollToBottom
.delay(5, this);
315 this.scrollToBottom();
317 } else if($defined(this.scrollpos
)) {
318 if(Browser
.Engine
.trident
) {
319 this.getScrollParent().scrollTo(this.scrollpos
.x
, this.scrollpos
.y
);
321 this.getScrollParent().scrollTo
.delay(5, this, [this.scrollpos
.x
, this.scrollpos
.y
]);
325 createMenu: function(nick
, parent
) {
326 var e
= new Element("div");
327 parent
.appendChild(e
);
330 qwebirc
.ui
.MENU_ITEMS
.forEach(function(x
) {
331 var e2
= new Element("a");
335 e2
.set("text", "- " + x
[0]);
337 e2
.addEvent("focus", function() { this.blur() }.bind(e2
));
338 e2
.addEvent("click", function(ev
) { new Event(ev
.stop()); this.menuClick(x
[1]); }.bind(this));
342 menuClick: function(fn
) {
344 this.prevNick.removeChild(this.prevNick.menu);
345 this.prevNick.menu = null;
347 fn
.bind(this)(this.prevNick
.realNick
);
348 this.removePrevMenu();
350 moveMenuClass: function() {
353 if(this.nicklist
.firstChild
== this.prevNick
) {
354 this.prevNick
.removeClass("selected-middle");
356 this.prevNick
.addClass("selected-middle");
359 removePrevMenu: function() {
363 this.prevNick
.removeClass("selected");
364 this.prevNick
.removeClass("selected-middle");
365 if(this.prevNick
.menu
)
366 this.prevNick
.removeChild(this.prevNick
.menu
);
367 this.prevNick
= null;
369 nickListAdd: function(nick
, position
) {
370 var e
= new Element("a");
371 qwebirc
.ui
.insertAt(position
, this.nicklist
, e
);
374 e
.appendChild(document
.createTextNode(nick
));
376 e
.realNick
= this.client
.stripPrefix(nick
);
378 e
.addEvent("click", function(x
) {
379 if(this.prevNick
== e
) {
380 this.removePrevMenu();
384 this.removePrevMenu();
386 e
.addClass("selected");
387 this.moveMenuClass();
388 e
.menu
= this.createMenu(x
.realNick
, e
);
391 e
.addEvent("dblclick", function(x
) {
393 this.client
.exec("/QUERY " + e
.realNick
);
396 e
.addEvent("focus", function() { this.blur() }.bind(e
));
397 this.moveMenuClass();
400 nickListRemove: function(nick
, stored
) {
401 this.nicklist
.removeChild(stored
);
402 this.moveMenuClass();
404 updateTopic: function(topic
) {
408 t
.removeChild(t
.firstChild
);
411 this.parent(topic
, t
);
413 var e
= new Element("div");
414 e
.set("text", "(no topic set)");
415 e
.addClass("emptytopic");
421 var inputVisible
= this.type
!= qwebirc
.ui
.WINDOW_CONNECT
&& this.type
!= qwebirc
.ui
.WINDOW_CUSTOM
;
423 this.tab
.removeClass("tab-unselected");
424 this.tab
.addClass("tab-selected");
426 this.parentObject
.setLines(this.lines
);
427 this.parentObject
.setChannelItems(this.nicklist
, this.topic
);
428 this.parentObject
.qjsui
.showInput(inputVisible
);
429 this.parentObject
.qjsui
.showChannel($defined(this.nicklist
));
436 this.parentObject
.inputbox
.focus();
438 deselect: function() {
441 this.tab
.removeClass("tab-selected");
442 this.tab
.addClass("tab-unselected");
447 this.parentObject
.tabs
.removeChild(this.tab
);
449 addLine: function(type
, line
, colour
) {
450 var e
= new Element("div");
453 e
.setStyles({"background": colour
});
454 } else if(this.lastcolour
) {
455 e
.addClass("linestyle1");
457 e
.addClass("linestyle2");
459 this.lastcolour
= !this.lastcolour
;
461 this.parent(type
, line
, colour
, e
);
463 setHilighted: function(state
) {
464 laststate
= this.hilighted
;
468 if(state
== laststate
)
471 this.tab
.removeClass("tab-hilight-activity");
472 this.tab
.removeClass("tab-hilight-us");
473 this.tab
.removeClass("tab-hilight-speech");
475 switch(this.hilighted
) {
476 case qwebirc
.ui
.HILIGHT_US:
477 this.tab
.addClass("tab-hilight-us");
479 case qwebirc
.ui
.HILIGHT_SPEECH:
480 this.tab
.addClass("tab-hilight-speech");
482 case qwebirc
.ui
.HILIGHT_ACTIVITY:
483 this.tab
.addClass("tab-hilight-activity");