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