]>
Commit | Line | Data |
---|---|---|
96f28062 CP |
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 | ||
27b2a55f CP |
6 | qwebirc.ui.MAXIMUM_LINES_PER_WINDOW = 1000; |
7 | ||
5c0b5a6e CP |
8 | qwebirc.ui.WINDOW_LASTLINE = qwebirc.ui.WINDOW_QUERY | qwebirc.ui.WINDOW_MESSAGES | qwebirc.ui.WINDOW_CHANNEL | qwebirc.ui.WINDOW_STATUS; |
9 | ||
e20e5a6b | 10 | qwebirc.ui.Window = new Class({ |
94b18192 CP |
11 | Implements: [Events], |
12 | initialize: function(parentObject, client, type, name, identifier) { | |
13 | this.parentObject = parentObject; | |
14 | this.type = type; | |
15 | this.name = name; | |
16 | this.active = false; | |
17 | this.client = client; | |
18 | this.identifier = identifier; | |
96f28062 | 19 | this.hilighted = qwebirc.ui.HILIGHT_NONE; |
381fddfd | 20 | this.scrolltimer = null; |
9b63b053 | 21 | this.commandhistory = this.parentObject.commandhistory; |
25be5960 | 22 | this.scrolleddown = true; |
9d538d73 | 23 | this.scrollpos = null; |
52090a1f | 24 | this.lastNickHash = {}; |
3236ca77 | 25 | this.lastSelected = null; |
17f40fd9 | 26 | this.subWindow = null; |
f84bf379 | 27 | this.closed = false; |
5c0b5a6e CP |
28 | |
29 | if(this.type & qwebirc.ui.WINDOW_LASTLINE) { | |
30 | this.lastPositionLine = new Element("hr"); | |
31 | this.lastPositionLine.addClass("lastpos"); | |
32 | this.lastPositionLineInserted = false; | |
33 | } | |
94b18192 | 34 | }, |
1f06a70a | 35 | updateTopic: function(topic, element) { |
2cd9e32d | 36 | qwebirc.ui.Colourise("[" + topic + "]", element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this); |
94b18192 CP |
37 | }, |
38 | close: function() { | |
f84bf379 CP |
39 | this.closed = true; |
40 | ||
381fddfd CP |
41 | if($defined(this.scrolltimer)) { |
42 | $clear(this.scrolltimer); | |
43 | this.scrolltimer = null; | |
44 | } | |
45 | ||
94b18192 CP |
46 | this.parentObject.__closed(this); |
47 | this.fireEvent("close", this); | |
48 | }, | |
17f40fd9 CP |
49 | subEvent: function(event) { |
50 | if($defined(this.subWindow)) | |
51 | this.subWindow.fireEvent(event); | |
52 | }, | |
53 | setSubWindow: function(window) { | |
54 | this.subWindow = window; | |
55 | }, | |
94b18192 | 56 | select: function() { |
5c0b5a6e CP |
57 | if(this.lastPositionLineInserted && !this.parentObject.uiOptions.LASTPOS_LINE) { |
58 | this.lines.removeChild(this.lastPositionLine); | |
59 | this.lastPositionLineInserted = false; | |
60 | } | |
61 | ||
94b18192 CP |
62 | this.active = true; |
63 | this.parentObject.__setActiveWindow(this); | |
381fddfd | 64 | if(this.hilighted) |
96f28062 | 65 | this.setHilighted(qwebirc.ui.HILIGHT_NONE); |
17f40fd9 CP |
66 | |
67 | this.subEvent("select"); | |
9d538d73 | 68 | this.resetScrollPos(); |
3236ca77 | 69 | this.lastSelected = new Date(); |
94b18192 CP |
70 | }, |
71 | deselect: function() { | |
17f40fd9 CP |
72 | this.subEvent("deselect"); |
73 | ||
9d538d73 | 74 | this.setScrollPos(); |
7c633700 CP |
75 | if($defined(this.scrolltimer)) { |
76 | $clear(this.scrolltimer); | |
77 | this.scrolltimer = null; | |
78 | } | |
79 | ||
2dd49204 CP |
80 | if(this.type & qwebirc.ui.WINDOW_LASTLINE) |
81 | this.replaceLastPositionLine(); | |
5c0b5a6e | 82 | |
94b18192 CP |
83 | this.active = false; |
84 | }, | |
9d538d73 CP |
85 | resetScrollPos: function() { |
86 | if(this.scrolleddown) { | |
87 | this.scrollToBottom(); | |
88 | } else if($defined(this.scrollpos)) { | |
89 | this.getScrollParent().scrollTo(this.scrollpos.x, this.scrollpos.y); | |
90 | } | |
91 | }, | |
92 | setScrollPos: function() { | |
93 | if(!this.parentObject.singleWindow) { | |
94 | this.scrolleddown = this.scrolledDown(); | |
95 | this.scrollpos = this.lines.getScroll(); | |
96 | } | |
97 | }, | |
30bd2620 | 98 | addLine: function(type, line, colour, element) { |
96f28062 | 99 | var hilight = qwebirc.ui.HILIGHT_NONE; |
b2e77cf9 CP |
100 | var lhilight = false; |
101 | ||
96f28062 CP |
102 | if(type) { |
103 | hilight = qwebirc.ui.HILIGHT_ACTIVITY; | |
104 | ||
105 | if(type.match(/(NOTICE|ACTION|MSG)$/)) { | |
f74802c5 | 106 | if(this.type == qwebirc.ui.WINDOW_QUERY || this.type == qwebirc.ui.WINDOW_MESSAGES) { |
7af2d0c1 | 107 | if(type.match(/^OUR/) || type.match(/NOTICE$/)) { |
f74802c5 CP |
108 | hilight = qwebirc.ui.HILIGHT_ACTIVITY; |
109 | } else { | |
110 | hilight = qwebirc.ui.HILIGHT_US; | |
aeb8c784 | 111 | this.parentObject.beep(); |
326478c2 | 112 | this.parentObject.flash(); |
f74802c5 | 113 | } |
b2e77cf9 CP |
114 | } |
115 | if(!type.match(/^OUR/) && this.client.hilightController.match(line["m"])) { | |
116 | lhilight = true; | |
117 | hilight = qwebirc.ui.HILIGHT_US; | |
aeb8c784 | 118 | this.parentObject.beep(); |
326478c2 | 119 | this.parentObject.flash(); |
b2e77cf9 | 120 | } else if(hilight != qwebirc.ui.HILIGHT_US) { |
96f28062 CP |
121 | hilight = qwebirc.ui.HILIGHT_SPEECH; |
122 | } | |
123 | } | |
124 | } | |
125 | ||
126 | if(!this.active && (hilight != qwebirc.ui.HILIGHT_NONE)) | |
127 | this.setHilighted(hilight); | |
128 | ||
381fddfd | 129 | if(type) |
b2e77cf9 | 130 | line = this.parentObject.theme.message(type, line, lhilight); |
381fddfd | 131 | |
a7249843 CP |
132 | var tsE = document.createElement("span"); |
133 | tsE.className = "timestamp"; | |
134 | tsE.appendChild(document.createTextNode(qwebirc.irc.IRCTimestamp(new Date()) + " ")); | |
135 | element.appendChild(tsE); | |
136 | ||
137 | qwebirc.ui.Colourise(line, element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this); | |
381fddfd | 138 | this.scrollAdd(element); |
94b18192 CP |
139 | }, |
140 | errorMessage: function(message) { | |
5fc104ff | 141 | this.addLine("", message, "warncolour"); |
381fddfd | 142 | }, |
fc38a626 CP |
143 | infoMessage: function(type, message) { |
144 | if(message === undefined) { | |
145 | this.addLine("", type, "infocolour"); | |
146 | } else { | |
147 | this.addLine(type, message, "infocolour"); | |
148 | } | |
0acc3c54 | 149 | }, |
381fddfd | 150 | setHilighted: function(state) { |
96f28062 CP |
151 | if(state == qwebirc.ui.HILIGHT_NONE || state >= this.hilighted) |
152 | this.hilighted = state; | |
381fddfd | 153 | }, |
25be5960 | 154 | scrolledDown: function() { |
7c633700 CP |
155 | if(this.scrolltimer) |
156 | return true; | |
157 | ||
381fddfd | 158 | var parent = this.lines; |
381fddfd | 159 | |
381fddfd CP |
160 | var prev = parent.getScroll(); |
161 | var prevbottom = parent.getScrollSize().y; | |
45459a86 CP |
162 | var prevheight = parent.clientHeight; |
163 | ||
164 | /* | |
165 | * fixes an IE bug: the scrollheight is less than the actual height | |
166 | * when the div isn't full | |
167 | */ | |
168 | if(prevbottom < prevheight) | |
169 | prevbottom = prevheight; | |
fccb1dac | 170 | |
45459a86 | 171 | return prev.y + prevheight == prevbottom; |
7c633700 | 172 | }, |
9d538d73 CP |
173 | getScrollParent: function() { |
174 | var scrollparent = this.lines; | |
7c633700 CP |
175 | |
176 | if($defined(this.scroller)) | |
177 | scrollparent = this.scroller; | |
9d538d73 CP |
178 | return scrollparent; |
179 | }, | |
180 | scrollToBottom: function() { | |
73a06774 CP |
181 | if(this.type == qwebirc.ui.WINDOW_CUSTOM || this.type == qwebirc.ui.WINDOW_CONNECT) |
182 | return; | |
183 | ||
9d538d73 CP |
184 | var parent = this.lines; |
185 | var scrollparent = this.getScrollParent(); | |
7c633700 CP |
186 | |
187 | scrollparent.scrollTo(parent.getScroll().x, parent.getScrollSize().y); | |
188 | }, | |
189 | scrollAdd: function(element) { | |
190 | var parent = this.lines; | |
381fddfd CP |
191 | |
192 | /* scroll in bursts, else the browser gets really slow */ | |
193 | if($defined(element)) { | |
25be5960 | 194 | var sd = this.scrolledDown(); |
381fddfd | 195 | parent.appendChild(element); |
27b2a55f CP |
196 | if(parent.childNodes.length > qwebirc.ui.MAXIMUM_LINES_PER_WINDOW) |
197 | parent.removeChild(parent.firstChild); | |
7c633700 | 198 | if(sd) { |
381fddfd CP |
199 | if(this.scrolltimer) |
200 | $clear(this.scrolltimer); | |
7c633700 | 201 | this.scrolltimer = this.scrollAdd.delay(50, this, [null]); |
2db47312 CC |
202 | } else { |
203 | this.scrollToBottom(); | |
204 | this.scrolltimer = null; | |
381fddfd CP |
205 | } |
206 | } else { | |
25be5960 | 207 | this.scrollToBottom(); |
381fddfd CP |
208 | this.scrolltimer = null; |
209 | } | |
9b63b053 | 210 | }, |
52090a1f | 211 | updateNickList: function(nicks) { |
833f14ce | 212 | var nickHash = {}, present = {}; |
52090a1f CP |
213 | var added = []; |
214 | var lnh = this.lastNickHash; | |
215 | ||
833f14ce CP |
216 | for(var i=0;i<nicks.length;i++) |
217 | present[nicks[i]] = 1; | |
218 | ||
219 | for(var k in lnh) | |
220 | if(!present[k]) | |
221 | this.nickListRemove(k, lnh[k]); | |
222 | ||
52090a1f CP |
223 | for(var i=0;i<nicks.length;i++) { |
224 | var n = nicks[i]; | |
225 | var l = lnh[n]; | |
226 | if(!l) { | |
227 | l = this.nickListAdd(n, i); | |
228 | if(!l) | |
229 | l = 1; | |
230 | } | |
231 | nickHash[n] = l; | |
232 | } | |
233 | ||
52090a1f CP |
234 | this.lastNickHash = nickHash; |
235 | }, | |
236 | nickListAdd: function(position, nick) { | |
237 | }, | |
238 | nickListRemove: function(nick, stored) { | |
239 | }, | |
9b63b053 CP |
240 | historyExec: function(line) { |
241 | this.commandhistory.addLine(line); | |
242 | this.client.exec(line); | |
eb271d86 CP |
243 | }, |
244 | focusChange: function(newValue) { | |
eb271d86 CP |
245 | if(newValue == true || !(this.type & qwebirc.ui.WINDOW_LASTLINE)) |
246 | return; | |
2dd49204 CP |
247 | |
248 | this.replaceLastPositionLine(); | |
249 | }, | |
250 | replaceLastPositionLine: function() { | |
251 | if(this.parentObject.uiOptions.LASTPOS_LINE) { | |
252 | if(!this.lastPositionLineInserted) { | |
253 | this.scrollAdd(this.lastPositionLine); | |
254 | } else if(this.lines.lastChild != this.lastPositionLine) { | |
d081c4b3 CP |
255 | try { |
256 | this.lines.removeChild(this.lastPositionLine); | |
257 | } catch(e) { | |
258 | /* IGNORE, /clear removes lastPositionLine from the dom without resetting it. */ | |
259 | } | |
2dd49204 CP |
260 | this.scrollAdd(this.lastPositionLine); |
261 | } | |
262 | } else { | |
263 | if(this.lastPositionLineInserted) | |
264 | this.lines.removeChild(this.lastPositionLine); | |
265 | } | |
266 | ||
267 | this.lastPositionLineInserted = this.parentObject.uiOptions.LASTPOS_LINE; | |
5aa173fb CP |
268 | }, |
269 | rename: function(name) { | |
eb271d86 | 270 | } |
94b18192 | 271 | }); |