]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/baseuiwindow.js
1 qwebirc
.ui
.HILIGHT_NONE
= 0;
2 qwebirc
.ui
.HILIGHT_ACTIVITY
= 1;
3 qwebirc
.ui
.HILIGHT_SPEECH
= 2;
4 qwebirc
.ui
.HILIGHT_US
= 3;
6 qwebirc
.ui
.MAXIMUM_LINES_PER_WINDOW
= 1000;
8 qwebirc
.ui
.WINDOW_LASTLINE
= qwebirc
.ui
.WINDOW_QUERY
| qwebirc
.ui
.WINDOW_MESSAGES
| qwebirc
.ui
.WINDOW_CHANNEL
| qwebirc
.ui
.WINDOW_STATUS
;
10 qwebirc
.ui
.Window
= new Class({
12 initialize: function(parentObject
, client
, type
, name
, identifier
) {
13 this.parentObject
= parentObject
;
18 this.identifier
= identifier
;
19 this.hilighted
= qwebirc
.ui
.HILIGHT_NONE
;
20 this.scrolltimer
= null;
21 this.commandhistory
= this.parentObject
.commandhistory
;
22 this.scrolleddown
= true;
23 this.scrollpos
= null;
24 this.lastNickHash
= new QHash();
25 this.lastSelected
= null;
26 this.subWindow
= null;
29 if(this.type
& qwebirc
.ui
.WINDOW_LASTLINE
) {
30 this.lastPositionLine
= new Element("hr");
31 this.lastPositionLine
.addClass("lastpos");
32 this.lastPositionLineInserted
= false;
35 updateTopic: function(topic
, element
) {
36 qwebirc
.ui
.Colourise("[" + topic
+ "]", element
, this.client
.exec
, this.parentObject
.urlDispatcher
.bind(this.parentObject
), this);
41 if($defined(this.scrolltimer
)) {
42 $clear(this.scrolltimer
);
43 this.scrolltimer
= null;
46 this.parentObject
.__closed(this);
47 this.fireEvent("close", this);
49 subEvent: function(event
) {
50 if($defined(this.subWindow
))
51 this.subWindow
.fireEvent(event
);
53 setSubWindow: function(window
) {
54 this.subWindow
= window
;
57 if(this.lastPositionLineInserted
&& !this.parentObject
.uiOptions
.LASTPOS_LINE
) {
58 this.lines
.removeChild(this.lastPositionLine
);
59 this.lastPositionLineInserted
= false;
63 this.parentObject
.__setActiveWindow(this);
65 this.setHilighted(qwebirc
.ui
.HILIGHT_NONE
);
67 this.subEvent("select");
68 this.resetScrollPos();
69 this.lastSelected
= new Date();
71 deselect: function() {
72 this.subEvent("deselect");
75 if($defined(this.scrolltimer
)) {
76 $clear(this.scrolltimer
);
77 this.scrolltimer
= null;
80 if(this.type
& qwebirc
.ui
.WINDOW_LASTLINE
)
81 this.replaceLastPositionLine();
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
);
92 setScrollPos: function() {
93 if(!this.parentObject
.singleWindow
) {
94 this.scrolleddown
= this.scrolledDown();
95 this.scrollpos
= this.lines
.getScroll();
98 addLine: function(type
, line
, colour
, element
) {
99 var hilight
= qwebirc
.ui
.HILIGHT_NONE
;
100 var lhilight
= false;
103 var selectMe = function() { this.parentObject
.selectWindow(this); }.bind(this);
104 var message
= $defined(line
) ? line
["m"] : null;
105 hilight
= qwebirc
.ui
.HILIGHT_ACTIVITY
;
107 if(type
.match(/(NOTICE|ACTION|MSG)$/)) {
108 if(this.type
== qwebirc
.ui
.WINDOW_QUERY
|| this.type
== qwebirc
.ui
.WINDOW_MESSAGES
) {
109 if(type
.match(/^OUR/) || type
.match(/NOTICE$/)) {
110 hilight
= qwebirc
.ui
.HILIGHT_ACTIVITY
;
112 hilight
= qwebirc
.ui
.HILIGHT_US
;
113 this.parentObject
.notify("Private message from " + this.name
, message
, selectMe
);
116 if(!type
.match(/^OUR/) && this.client
.hilightController
.match(message
)) {
118 hilight
= qwebirc
.ui
.HILIGHT_US
;
119 this.parentObject
.notify("Hilighted in " + this.name
, message
, selectMe
);
120 } else if(hilight
!= qwebirc
.ui
.HILIGHT_US
) {
121 hilight
= qwebirc
.ui
.HILIGHT_SPEECH
;
126 if(!this.active
&& (hilight
!= qwebirc
.ui
.HILIGHT_NONE
))
127 this.setHilighted(hilight
);
130 line
= this.parentObject
.theme
.message(type
, line
, lhilight
);
132 var tsE
= document
.createElement("span");
133 tsE
.className
= "timestamp";
134 tsE
.appendChild(document
.createTextNode(qwebirc
.irc
.IRCTimestamp(new Date()) + " "));
135 element
.appendChild(tsE
);
137 qwebirc
.ui
.Colourise(line
, element
, this.client
.exec
, this.parentObject
.urlDispatcher
.bind(this.parentObject
), this);
138 this.scrollAdd(element
);
140 errorMessage: function(message
) {
141 this.addLine("", message
, "warncolour");
143 infoMessage: function(type
, message
) {
144 if(message
=== undefined) {
145 this.addLine("", type
, "infocolour");
147 this.addLine(type
, message
, "infocolour");
150 setHilighted: function(state
) {
151 if(state
== qwebirc
.ui
.HILIGHT_NONE
|| state
>= this.hilighted
)
152 this.hilighted
= state
;
154 scrolledDown: function() {
158 var parent
= this.lines
;
160 var scrollPos
= parent
.getScroll().y
;
161 var linesHeight
= parent
.getScrollSize().y
;
162 var windowHeight
= parent
.clientHeight
;
165 * fixes an IE bug: the scrollheight is less than the actual height
166 * when the div isn't full
168 if(linesHeight
< windowHeight
)
169 linesHeight
= windowHeight
;
171 return scrollPos
+ windowHeight
>= linesHeight
- 3; /* window of error */
173 getScrollParent: function() {
174 var scrollparent
= this.lines
;
176 if($defined(this.scroller
))
177 scrollparent
= this.scroller
;
180 scrollToBottom: function() {
181 if(this.type
== qwebirc
.ui
.WINDOW_CUSTOM
|| this.type
== qwebirc
.ui
.WINDOW_CONNECT
)
184 var parent
= this.lines
;
185 var scrollparent
= this.getScrollParent();
187 scrollparent
.scrollTo(parent
.getScroll().x
, parent
.getScrollSize().y
);
189 scrollAdd: function(element
) {
190 var parent
= this.lines
;
192 /* scroll in bursts, else the browser gets really slow */
193 if($defined(element
)) {
194 var sd
= this.scrolledDown();
195 parent
.appendChild(element
);
196 if(parent
.childNodes
.length
> qwebirc
.ui
.MAXIMUM_LINES_PER_WINDOW
)
197 parent
.removeChild(parent
.firstChild
);
199 if(sd
&& !this.scrollTimer
)
200 this.scrolltimer
= this.scrollAdd
.delay(50, this, [null]);
202 this.scrollToBottom();
203 this.scrolltimer
= null;
206 updateNickList: function(nicks
) {
207 var nickHash
= new QHash(), present
= new QSet();
209 var lnh
= this.lastNickHash
;
211 for(var i
=0;i
<nicks
.length
;i
++)
212 present
.add(nicks
[i
]);
214 lnh
.each(function(k
, v
) {
215 if(!present
.contains(k
))
216 this.nickListRemove(k
, v
);
219 for(var i
=0;i
<nicks
.length
;i
++) {
223 l
= this.nickListAdd(n
, i
);
230 this.lastNickHash
= nickHash
;
232 nickListAdd: function(position
, nick
) {
234 nickListRemove: function(nick
, stored
) {
236 historyExec: function(line
) {
237 this.commandhistory
.addLine(line
);
238 this.client
.exec(line
);
240 focusChange: function(newValue
) {
241 if(newValue
== true || !(this.type
& qwebirc
.ui
.WINDOW_LASTLINE
))
244 this.replaceLastPositionLine();
246 replaceLastPositionLine: function() {
247 if(this.parentObject
.uiOptions
.LASTPOS_LINE
) {
248 if(!this.scrolledDown())
251 if(!this.lastPositionLineInserted
) {
252 this.scrollAdd(this.lastPositionLine
);
253 } else if(this.lines
.lastChild
!= this.lastPositionLine
) {
255 this.lines
.removeChild(this.lastPositionLine
);
257 /* IGNORE, /clear removes lastPositionLine from the dom without resetting it. */
259 this.scrollAdd(this.lastPositionLine
);
262 if(this.lastPositionLineInserted
)
263 this.lines
.removeChild(this.lastPositionLine
);
266 this.lastPositionLineInserted
= this.parentObject
.uiOptions
.LASTPOS_LINE
;
268 rename: function(name
) {