]>
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
.WINDOW_LASTLINE
= qwebirc
.ui
.WINDOW_QUERY
| qwebirc
.ui
.WINDOW_MESSAGES
| qwebirc
.ui
.WINDOW_CHANNEL
| qwebirc
.ui
.WINDOW_STATUS
;
8 qwebirc
.ui
.Window
= new Class({
10 initialize: function(parentObject
, client
, type
, name
, identifier
) {
11 this.parentObject
= parentObject
;
16 this.identifier
= identifier
;
17 this.hilighted
= qwebirc
.ui
.HILIGHT_NONE
;
18 this.scrolltimer
= null;
19 this.commandhistory
= this.parentObject
.commandhistory
;
20 this.scrolleddown
= true;
21 this.scrollpos
= null;
22 this.lastNickHash
= {};
23 this.lastSelected
= null;
24 this.subWindow
= null;
27 if(this.type
& qwebirc
.ui
.WINDOW_LASTLINE
) {
28 this.lastPositionLine
= new Element("hr");
29 this.lastPositionLine
.addClass("lastpos");
30 this.lastPositionLineInserted
= false;
33 updateTopic: function(topic
, element
) {
34 qwebirc
.ui
.Colourise("[" + topic
+ "]", element
, this.client
.exec
, this.parentObject
.urlDispatcher
.bind(this.parentObject
), this);
39 if($defined(this.scrolltimer
)) {
40 $clear(this.scrolltimer
);
41 this.scrolltimer
= null;
44 this.parentObject
.__closed(this);
45 this.fireEvent("close", this);
47 subEvent: function(event
) {
48 if($defined(this.subWindow
))
49 this.subWindow
.fireEvent(event
);
51 setSubWindow: function(window
) {
52 this.subWindow
= window
;
55 if(this.lastPositionLineInserted
&& !this.parentObject
.uiOptions
.LASTPOS_LINE
) {
56 this.lines
.removeChild(this.lastPositionLine
);
57 this.lastPositionLineInserted
= false;
61 this.parentObject
.__setActiveWindow(this);
63 this.setHilighted(qwebirc
.ui
.HILIGHT_NONE
);
65 this.subEvent("select");
66 this.resetScrollPos();
67 this.lastSelected
= new Date();
69 deselect: function() {
70 this.subEvent("deselect");
73 if($defined(this.scrolltimer
)) {
74 $clear(this.scrolltimer
);
75 this.scrolltimer
= null;
78 if(this.type
& qwebirc
.ui
.WINDOW_LASTLINE
)
79 this.replaceLastPositionLine();
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
);
90 setScrollPos: function() {
91 if(!this.parentObject
.singleWindow
) {
92 this.scrolleddown
= this.scrolledDown();
93 this.scrollpos
= this.lines
.getScroll();
96 addLine: function(type
, line
, colour
, element
) {
97 var hilight
= qwebirc
.ui
.HILIGHT_NONE
;
101 hilight
= qwebirc
.ui
.HILIGHT_ACTIVITY
;
103 if(type
.match(/(NOTICE|ACTION|MSG)$/)) {
104 if(this.type
== qwebirc
.ui
.WINDOW_QUERY
|| this.type
== qwebirc
.ui
.WINDOW_MESSAGES
) {
105 if(type
.match(/^OUR/) || type
.match(/NOTICE$/)) {
106 hilight
= qwebirc
.ui
.HILIGHT_ACTIVITY
;
108 hilight
= qwebirc
.ui
.HILIGHT_US
;
109 this.parentObject
.beep();
110 this.parentObject
.flash();
113 if(!type
.match(/^OUR/) && this.client
.hilightController
.match(line
["m"])) {
115 hilight
= qwebirc
.ui
.HILIGHT_US
;
116 this.parentObject
.beep();
117 this.parentObject
.flash();
118 } else if(hilight
!= qwebirc
.ui
.HILIGHT_US
) {
119 hilight
= qwebirc
.ui
.HILIGHT_SPEECH
;
124 if(!this.active
&& (hilight
!= qwebirc
.ui
.HILIGHT_NONE
))
125 this.setHilighted(hilight
);
128 line
= this.parentObject
.theme
.message(type
, line
, lhilight
);
130 qwebirc
.ui
.Colourise(qwebirc
.irc
.IRCTimestamp(new Date()) + " " + line
, element
, this.client
.exec
, this.parentObject
.urlDispatcher
.bind(this.parentObject
), this);
131 this.scrollAdd(element
);
133 errorMessage: function(message
) {
134 this.addLine("", message
, "warncolour");
136 infoMessage: function(message
) {
137 this.addLine("", message
, "infocolour");
139 setHilighted: function(state
) {
140 if(state
== qwebirc
.ui
.HILIGHT_NONE
|| state
>= this.hilighted
)
141 this.hilighted
= state
;
143 scrolledDown: function() {
147 var parent
= this.lines
;
149 var prev
= parent
.getScroll();
150 var prevbottom
= parent
.getScrollSize().y
;
151 var prevsize
= parent
.getSize();
153 /* fixes an IE bug */
154 if(prevbottom
< prevsize
.y
)
155 prevbottom
= prevsize
.y
;
157 return prev
.y
+ prevsize
.y
== prevbottom
;
159 getScrollParent: function() {
160 var scrollparent
= this.lines
;
162 if($defined(this.scroller
))
163 scrollparent
= this.scroller
;
166 scrollToBottom: function() {
167 if(this.type
== qwebirc
.ui
.WINDOW_CUSTOM
|| this.type
== qwebirc
.ui
.WINDOW_CONNECT
)
170 var parent
= this.lines
;
171 var scrollparent
= this.getScrollParent();
173 scrollparent
.scrollTo(parent
.getScroll().x
, parent
.getScrollSize().y
);
175 scrollAdd: function(element
) {
176 var parent
= this.lines
;
178 /* scroll in bursts, else the browser gets really slow */
179 if($defined(element
)) {
180 var sd
= this.scrolledDown();
181 parent
.appendChild(element
);
184 $clear(this.scrolltimer
);
185 this.scrolltimer
= this.scrollAdd
.delay(50, this, [null]);
188 this.scrollToBottom();
189 this.scrolltimer
= null;
192 updateNickList: function(nicks
) {
193 var nickHash
= {}, present
= {};
195 var lnh
= this.lastNickHash
;
197 for(var i
=0;i
<nicks
.length
;i
++)
198 present
[nicks
[i
]] = 1;
202 this.nickListRemove(k
, lnh
[k
]);
204 for(var i
=0;i
<nicks
.length
;i
++) {
208 l
= this.nickListAdd(n
, i
);
215 this.lastNickHash
= nickHash
;
217 nickListAdd: function(position
, nick
) {
219 nickListRemove: function(nick
, stored
) {
221 historyExec: function(line
) {
222 this.commandhistory
.addLine(line
);
223 this.client
.exec(line
);
225 focusChange: function(newValue
) {
226 if(newValue
== true || !(this.type
& qwebirc
.ui
.WINDOW_LASTLINE
))
229 this.replaceLastPositionLine();
231 replaceLastPositionLine: function() {
232 if(this.parentObject
.uiOptions
.LASTPOS_LINE
) {
233 if(!this.lastPositionLineInserted
) {
234 this.scrollAdd(this.lastPositionLine
);
235 } else if(this.lines
.lastChild
!= this.lastPositionLine
) {
236 this.lines
.removeChild(this.lastPositionLine
);
237 this.scrollAdd(this.lastPositionLine
);
240 if(this.lastPositionLineInserted
)
241 this.lines
.removeChild(this.lastPositionLine
);
244 this.lastPositionLineInserted
= this.parentObject
.uiOptions
.LASTPOS_LINE
;