]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/baseuiwindow.js
Merge.
[irc/quakenet/qwebirc.git] / js / ui / baseuiwindow.js
1 var UIWindow = new Class({
2 Implements: [Events],
3 initialize: function(parentObject, client, type, name, identifier) {
4 this.parentObject = parentObject;
5 this.type = type;
6 this.name = name;
7 this.active = false;
8 this.client = client;
9 this.identifier = identifier;
10 this.hilighted = false;
11 this.scrolltimer = null;
12 this.commandhistory = this.parentObject.commandhistory;
13 this.scrolleddown = true;
14 //new CommandHistory();
15 },
16 updateNickList: function(nicks) {
17 },
18 updateTopic: function(topic) {
19 },
20 close: function() {
21 if($defined(this.scrolltimer)) {
22 $clear(this.scrolltimer);
23 this.scrolltimer = null;
24 }
25
26 this.parentObject.__closed(this);
27 this.fireEvent("close", this);
28 },
29 select: function() {
30 this.active = true;
31 this.parentObject.__setActiveWindow(this);
32 if(this.hilighted)
33 this.setHilighted(false);
34 if(this.scrolleddown)
35 this.scrollToBottom();
36 },
37 deselect: function() {
38 if(!this.parentObject.singleWindow)
39 this.scrolleddown = this.scrolledDown();
40 if($defined(this.scrolltimer)) {
41 $clear(this.scrolltimer);
42 this.scrolltimer = null;
43 }
44
45 this.active = false;
46 },
47 addLine: function(type, line, colour, element) {
48 if(!this.active && !this.hilighted)
49 this.setHilighted(true);
50 if(type)
51 line = this.parentObject.theme.message(type, line);
52
53 Colourise(IRCTimestamp(new Date()) + " " + line, element, this.client.exec);
54
55 this.scrollAdd(element);
56 },
57 errorMessage: function(message) {
58 this.addLine("", message, "red");
59 },
60 setHilighted: function(state) {
61 this.hilighted = state;
62 },
63 scrolledDown: function() {
64 if(this.scrolltimer)
65 return true;
66
67 var parent = this.lines;
68
69 var prev = parent.getScroll();
70 var prevbottom = parent.getScrollSize().y;
71 var prevsize = parent.getSize();
72
73 return prev.y + prevsize.y == prevbottom;
74 },
75 scrollToBottom: function() {
76 var parent = this.lines;
77 var scrollparent = parent;
78
79 if($defined(this.scroller))
80 scrollparent = this.scroller;
81
82 scrollparent.scrollTo(parent.getScroll().x, parent.getScrollSize().y);
83 },
84 scrollAdd: function(element) {
85 var parent = this.lines;
86
87 /* scroll in bursts, else the browser gets really slow */
88 if($defined(element)) {
89 var sd = this.scrolledDown();
90 parent.appendChild(element);
91 if(sd) {
92 if(this.scrolltimer)
93 $clear(this.scrolltimer);
94 this.scrolltimer = this.scrollAdd.delay(50, this, [null]);
95 }
96 } else {
97 this.scrollToBottom();
98 this.scrolltimer = null;
99 }
100 },
101 historyExec: function(line) {
102 this.commandhistory.addLine(line);
103 this.client.exec(line);
104 }
105 });