]>
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 | ||
e20e5a6b | 6 | qwebirc.ui.Window = new Class({ |
94b18192 CP |
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; | |
96f28062 | 15 | this.hilighted = qwebirc.ui.HILIGHT_NONE; |
381fddfd | 16 | this.scrolltimer = null; |
9b63b053 | 17 | this.commandhistory = this.parentObject.commandhistory; |
25be5960 | 18 | this.scrolleddown = true; |
9d538d73 | 19 | this.scrollpos = null; |
52090a1f | 20 | this.lastNickHash = {}; |
3236ca77 | 21 | this.lastSelected = null; |
17f40fd9 | 22 | this.subWindow = null; |
f84bf379 | 23 | this.closed = false; |
94b18192 | 24 | }, |
1f06a70a | 25 | updateTopic: function(topic, element) { |
2cd9e32d | 26 | qwebirc.ui.Colourise("[" + topic + "]", element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this); |
94b18192 CP |
27 | }, |
28 | close: function() { | |
f84bf379 CP |
29 | this.closed = true; |
30 | ||
381fddfd CP |
31 | if($defined(this.scrolltimer)) { |
32 | $clear(this.scrolltimer); | |
33 | this.scrolltimer = null; | |
34 | } | |
35 | ||
94b18192 CP |
36 | this.parentObject.__closed(this); |
37 | this.fireEvent("close", this); | |
38 | }, | |
17f40fd9 CP |
39 | subEvent: function(event) { |
40 | if($defined(this.subWindow)) | |
41 | this.subWindow.fireEvent(event); | |
42 | }, | |
43 | setSubWindow: function(window) { | |
44 | this.subWindow = window; | |
45 | }, | |
94b18192 CP |
46 | select: function() { |
47 | this.active = true; | |
48 | this.parentObject.__setActiveWindow(this); | |
381fddfd | 49 | if(this.hilighted) |
96f28062 | 50 | this.setHilighted(qwebirc.ui.HILIGHT_NONE); |
17f40fd9 CP |
51 | |
52 | this.subEvent("select"); | |
9d538d73 | 53 | this.resetScrollPos(); |
3236ca77 | 54 | this.lastSelected = new Date(); |
94b18192 CP |
55 | }, |
56 | deselect: function() { | |
17f40fd9 CP |
57 | this.subEvent("deselect"); |
58 | ||
9d538d73 | 59 | this.setScrollPos(); |
7c633700 CP |
60 | if($defined(this.scrolltimer)) { |
61 | $clear(this.scrolltimer); | |
62 | this.scrolltimer = null; | |
63 | } | |
64 | ||
94b18192 CP |
65 | this.active = false; |
66 | }, | |
9d538d73 CP |
67 | resetScrollPos: function() { |
68 | if(this.scrolleddown) { | |
69 | this.scrollToBottom(); | |
70 | } else if($defined(this.scrollpos)) { | |
71 | this.getScrollParent().scrollTo(this.scrollpos.x, this.scrollpos.y); | |
72 | } | |
73 | }, | |
74 | setScrollPos: function() { | |
75 | if(!this.parentObject.singleWindow) { | |
76 | this.scrolleddown = this.scrolledDown(); | |
77 | this.scrollpos = this.lines.getScroll(); | |
78 | } | |
79 | }, | |
30bd2620 | 80 | addLine: function(type, line, colour, element) { |
96f28062 | 81 | var hilight = qwebirc.ui.HILIGHT_NONE; |
b2e77cf9 CP |
82 | var lhilight = false; |
83 | ||
96f28062 CP |
84 | if(type) { |
85 | hilight = qwebirc.ui.HILIGHT_ACTIVITY; | |
86 | ||
87 | if(type.match(/(NOTICE|ACTION|MSG)$/)) { | |
f74802c5 | 88 | if(this.type == qwebirc.ui.WINDOW_QUERY || this.type == qwebirc.ui.WINDOW_MESSAGES) { |
7af2d0c1 | 89 | if(type.match(/^OUR/) || type.match(/NOTICE$/)) { |
f74802c5 CP |
90 | hilight = qwebirc.ui.HILIGHT_ACTIVITY; |
91 | } else { | |
92 | hilight = qwebirc.ui.HILIGHT_US; | |
aeb8c784 | 93 | this.parentObject.beep(); |
326478c2 | 94 | this.parentObject.flash(); |
f74802c5 | 95 | } |
b2e77cf9 CP |
96 | } |
97 | if(!type.match(/^OUR/) && this.client.hilightController.match(line["m"])) { | |
98 | lhilight = true; | |
99 | hilight = qwebirc.ui.HILIGHT_US; | |
aeb8c784 | 100 | this.parentObject.beep(); |
326478c2 | 101 | this.parentObject.flash(); |
b2e77cf9 | 102 | } else if(hilight != qwebirc.ui.HILIGHT_US) { |
96f28062 CP |
103 | hilight = qwebirc.ui.HILIGHT_SPEECH; |
104 | } | |
105 | } | |
106 | } | |
107 | ||
108 | if(!this.active && (hilight != qwebirc.ui.HILIGHT_NONE)) | |
109 | this.setHilighted(hilight); | |
110 | ||
381fddfd | 111 | if(type) |
b2e77cf9 | 112 | line = this.parentObject.theme.message(type, line, lhilight); |
381fddfd | 113 | |
2cd9e32d | 114 | qwebirc.ui.Colourise(qwebirc.irc.IRCTimestamp(new Date()) + " " + line, element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this); |
381fddfd | 115 | this.scrollAdd(element); |
94b18192 CP |
116 | }, |
117 | errorMessage: function(message) { | |
5fc104ff | 118 | this.addLine("", message, "warncolour"); |
381fddfd | 119 | }, |
0acc3c54 | 120 | infoMessage: function(message) { |
5fc104ff | 121 | this.addLine("", message, "infocolour"); |
0acc3c54 | 122 | }, |
381fddfd | 123 | setHilighted: function(state) { |
96f28062 CP |
124 | if(state == qwebirc.ui.HILIGHT_NONE || state >= this.hilighted) |
125 | this.hilighted = state; | |
381fddfd | 126 | }, |
25be5960 | 127 | scrolledDown: function() { |
7c633700 CP |
128 | if(this.scrolltimer) |
129 | return true; | |
130 | ||
381fddfd | 131 | var parent = this.lines; |
381fddfd | 132 | |
381fddfd CP |
133 | var prev = parent.getScroll(); |
134 | var prevbottom = parent.getScrollSize().y; | |
135 | var prevsize = parent.getSize(); | |
25be5960 | 136 | |
fccb1dac CP |
137 | /* fixes an IE bug */ |
138 | if(prevbottom < prevsize.y) | |
139 | prevbottom = prevsize.y; | |
140 | ||
7c633700 CP |
141 | return prev.y + prevsize.y == prevbottom; |
142 | }, | |
9d538d73 CP |
143 | getScrollParent: function() { |
144 | var scrollparent = this.lines; | |
7c633700 CP |
145 | |
146 | if($defined(this.scroller)) | |
147 | scrollparent = this.scroller; | |
9d538d73 CP |
148 | return scrollparent; |
149 | }, | |
150 | scrollToBottom: function() { | |
73a06774 CP |
151 | if(this.type == qwebirc.ui.WINDOW_CUSTOM || this.type == qwebirc.ui.WINDOW_CONNECT) |
152 | return; | |
153 | ||
9d538d73 CP |
154 | var parent = this.lines; |
155 | var scrollparent = this.getScrollParent(); | |
7c633700 CP |
156 | |
157 | scrollparent.scrollTo(parent.getScroll().x, parent.getScrollSize().y); | |
158 | }, | |
159 | scrollAdd: function(element) { | |
160 | var parent = this.lines; | |
381fddfd CP |
161 | |
162 | /* scroll in bursts, else the browser gets really slow */ | |
163 | if($defined(element)) { | |
25be5960 | 164 | var sd = this.scrolledDown(); |
381fddfd | 165 | parent.appendChild(element); |
7c633700 | 166 | if(sd) { |
381fddfd CP |
167 | if(this.scrolltimer) |
168 | $clear(this.scrolltimer); | |
7c633700 | 169 | this.scrolltimer = this.scrollAdd.delay(50, this, [null]); |
381fddfd CP |
170 | } |
171 | } else { | |
25be5960 | 172 | this.scrollToBottom(); |
381fddfd CP |
173 | this.scrolltimer = null; |
174 | } | |
9b63b053 | 175 | }, |
52090a1f | 176 | updateNickList: function(nicks) { |
833f14ce | 177 | var nickHash = {}, present = {}; |
52090a1f CP |
178 | var added = []; |
179 | var lnh = this.lastNickHash; | |
180 | ||
833f14ce CP |
181 | for(var i=0;i<nicks.length;i++) |
182 | present[nicks[i]] = 1; | |
183 | ||
184 | for(var k in lnh) | |
185 | if(!present[k]) | |
186 | this.nickListRemove(k, lnh[k]); | |
187 | ||
52090a1f CP |
188 | for(var i=0;i<nicks.length;i++) { |
189 | var n = nicks[i]; | |
190 | var l = lnh[n]; | |
191 | if(!l) { | |
192 | l = this.nickListAdd(n, i); | |
193 | if(!l) | |
194 | l = 1; | |
195 | } | |
196 | nickHash[n] = l; | |
197 | } | |
198 | ||
52090a1f CP |
199 | this.lastNickHash = nickHash; |
200 | }, | |
201 | nickListAdd: function(position, nick) { | |
202 | }, | |
203 | nickListRemove: function(nick, stored) { | |
204 | }, | |
9b63b053 CP |
205 | historyExec: function(line) { |
206 | this.commandhistory.addLine(line); | |
207 | this.client.exec(line); | |
e516cc76 | 208 | } |
94b18192 | 209 | }); |