]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/baseuiwindow.js
Fix hilight query bug.
[irc/quakenet/qwebirc.git] / js / ui / baseuiwindow.js
1 qwebirc.ui.HILIGHT_NONE = 0;
2 qwebirc.ui.HILIGHT_ACTIVITY = 1;
3 qwebirc.ui.HILIGHT_SPEECH = 2;
4 qwebirc.ui.HILIGHT_US = 3;
5
6 qwebirc.ui.Window = new Class({
7 Implements: [Events],
8 initialize: function(parentObject, client, type, name, identifier) {
9 this.parentObject = parentObject;
10 this.type = type;
11 this.name = name;
12 this.active = false;
13 this.client = client;
14 this.identifier = identifier;
15 this.hilighted = qwebirc.ui.HILIGHT_NONE;
16 this.scrolltimer = null;
17 this.commandhistory = this.parentObject.commandhistory;
18 this.scrolleddown = true;
19 this.lastNickHash = {};
20 //new CommandHistory();
21 },
22 updateNickList: function(nicks) {
23 },
24 updateTopic: function(topic, element) {
25 qwebirc.ui.Colourise("[" + topic + "]", element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this);
26 },
27 close: function() {
28 if($defined(this.scrolltimer)) {
29 $clear(this.scrolltimer);
30 this.scrolltimer = null;
31 }
32
33 this.parentObject.__closed(this);
34 this.fireEvent("close", this);
35 },
36 select: function() {
37 this.active = true;
38 this.parentObject.__setActiveWindow(this);
39 if(this.hilighted)
40 this.setHilighted(qwebirc.ui.HILIGHT_NONE);
41 if(this.scrolleddown)
42 this.scrollToBottom();
43 },
44 deselect: function() {
45 if(!this.parentObject.singleWindow)
46 this.scrolleddown = this.scrolledDown();
47 if($defined(this.scrolltimer)) {
48 $clear(this.scrolltimer);
49 this.scrolltimer = null;
50 }
51
52 this.active = false;
53 },
54 addLine: function(type, line, colour, element) {
55 var hilight = qwebirc.ui.HILIGHT_NONE;
56 var lhilight = false;
57
58 if(type) {
59 hilight = qwebirc.ui.HILIGHT_ACTIVITY;
60
61 if(type.match(/(NOTICE|ACTION|MSG)$/)) {
62 if(this.type == qwebirc.ui.WINDOW_QUERY) {
63 hilight = qwebirc.ui.HILIGHT_US;
64 }
65 if(!type.match(/^OUR/) && this.client.hilightController.match(line["m"])) {
66 lhilight = true;
67 hilight = qwebirc.ui.HILIGHT_US;
68 } else if(hilight != qwebirc.ui.HILIGHT_US) {
69 hilight = qwebirc.ui.HILIGHT_SPEECH;
70 }
71 }
72 }
73
74 if(!this.active && (hilight != qwebirc.ui.HILIGHT_NONE))
75 this.setHilighted(hilight);
76
77 if(type)
78 line = this.parentObject.theme.message(type, line, lhilight);
79
80 qwebirc.ui.Colourise(qwebirc.irc.IRCTimestamp(new Date()) + " " + line, element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this);
81 this.scrollAdd(element);
82 },
83 errorMessage: function(message) {
84 this.addLine("", message, "red");
85 },
86 setHilighted: function(state) {
87 if(state == qwebirc.ui.HILIGHT_NONE || state >= this.hilighted)
88 this.hilighted = state;
89 },
90 scrolledDown: function() {
91 if(this.scrolltimer)
92 return true;
93
94 var parent = this.lines;
95
96 var prev = parent.getScroll();
97 var prevbottom = parent.getScrollSize().y;
98 var prevsize = parent.getSize();
99
100 /* fixes an IE bug */
101 if(prevbottom < prevsize.y)
102 prevbottom = prevsize.y;
103
104 return prev.y + prevsize.y == prevbottom;
105 },
106 scrollToBottom: function() {
107 var parent = this.lines;
108 var scrollparent = parent;
109
110 if($defined(this.scroller))
111 scrollparent = this.scroller;
112
113 scrollparent.scrollTo(parent.getScroll().x, parent.getScrollSize().y);
114 },
115 scrollAdd: function(element) {
116 var parent = this.lines;
117
118 /* scroll in bursts, else the browser gets really slow */
119 if($defined(element)) {
120 var sd = this.scrolledDown();
121 parent.appendChild(element);
122 if(sd) {
123 if(this.scrolltimer)
124 $clear(this.scrolltimer);
125 this.scrolltimer = this.scrollAdd.delay(50, this, [null]);
126 }
127 } else {
128 this.scrollToBottom();
129 this.scrolltimer = null;
130 }
131 },
132 updateNickList: function(nicks) {
133 var nickHash = {};
134 var added = [];
135 var lnh = this.lastNickHash;
136
137 for(var i=0;i<nicks.length;i++) {
138 var n = nicks[i];
139 var l = lnh[n];
140 if(!l) {
141 l = this.nickListAdd(n, i);
142 if(!l)
143 l = 1;
144 }
145 nickHash[n] = l;
146 }
147
148 for(var k in lnh)
149 if(!nickHash[k])
150 this.nickListRemove(k, lnh[k]);
151
152 this.lastNickHash = nickHash;
153 },
154 nickListAdd: function(position, nick) {
155 },
156 nickListRemove: function(nick, stored) {
157 },
158 historyExec: function(line) {
159 this.commandhistory.addLine(line);
160 this.client.exec(line);
161 }
162 });