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