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