]>
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
= new Class({
8 initialize: function(parentObject
, client
, type
, name
, identifier
) {
9 this.parentObject
= parentObject
;
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.lastNickHash
= {};
20 this.lastSelected
= null;
22 updateNickList: function(nicks
) {
24 updateTopic: function(topic
, element
) {
25 qwebirc
.ui
.Colourise("[" + topic
+ "]", element
, this.client
.exec
, this.parentObject
.urlDispatcher
.bind(this.parentObject
), this);
28 if($defined(this.scrolltimer
)) {
29 $clear(this.scrolltimer
);
30 this.scrolltimer
= null;
33 this.parentObject
.__closed(this);
34 this.fireEvent("close", this);
38 this.parentObject
.__setActiveWindow(this);
40 this.setHilighted(qwebirc
.ui
.HILIGHT_NONE
);
42 this.scrollToBottom();
43 this.lastSelected
= new Date();
45 deselect: function() {
46 if(!this.parentObject
.singleWindow
)
47 this.scrolleddown
= this.scrolledDown();
48 if($defined(this.scrolltimer
)) {
49 $clear(this.scrolltimer
);
50 this.scrolltimer
= null;
55 addLine: function(type
, line
, colour
, element
) {
56 var hilight
= qwebirc
.ui
.HILIGHT_NONE
;
60 hilight
= qwebirc
.ui
.HILIGHT_ACTIVITY
;
62 if(type
.match(/(NOTICE|ACTION|MSG)$/)) {
63 if(this.type
== qwebirc
.ui
.WINDOW_QUERY
) {
64 hilight
= qwebirc
.ui
.HILIGHT_US
;
66 if(!type
.match(/^OUR/) && this.client
.hilightController
.match(line
["m"])) {
68 hilight
= qwebirc
.ui
.HILIGHT_US
;
69 } else if(hilight
!= qwebirc
.ui
.HILIGHT_US
) {
70 hilight
= qwebirc
.ui
.HILIGHT_SPEECH
;
75 if(!this.active
&& (hilight
!= qwebirc
.ui
.HILIGHT_NONE
))
76 this.setHilighted(hilight
);
79 line
= this.parentObject
.theme
.message(type
, line
, lhilight
);
81 qwebirc
.ui
.Colourise(qwebirc
.irc
.IRCTimestamp(new Date()) + " " + line
, element
, this.client
.exec
, this.parentObject
.urlDispatcher
.bind(this.parentObject
), this);
82 this.scrollAdd(element
);
84 errorMessage: function(message
) {
85 this.addLine("", message
, "red");
87 setHilighted: function(state
) {
88 if(state
== qwebirc
.ui
.HILIGHT_NONE
|| state
>= this.hilighted
)
89 this.hilighted
= state
;
91 scrolledDown: function() {
95 var parent
= this.lines
;
97 var prev
= parent
.getScroll();
98 var prevbottom
= parent
.getScrollSize().y
;
99 var prevsize
= parent
.getSize();
101 /* fixes an IE bug */
102 if(prevbottom
< prevsize
.y
)
103 prevbottom
= prevsize
.y
;
105 return prev
.y
+ prevsize
.y
== prevbottom
;
107 scrollToBottom: function() {
108 var parent
= this.lines
;
109 var scrollparent
= parent
;
111 if($defined(this.scroller
))
112 scrollparent
= this.scroller
;
114 scrollparent
.scrollTo(parent
.getScroll().x
, parent
.getScrollSize().y
);
116 scrollAdd: function(element
) {
117 var parent
= this.lines
;
119 /* scroll in bursts, else the browser gets really slow */
120 if($defined(element
)) {
121 var sd
= this.scrolledDown();
122 parent
.appendChild(element
);
125 $clear(this.scrolltimer
);
126 this.scrolltimer
= this.scrollAdd
.delay(50, this, [null]);
129 this.scrollToBottom();
130 this.scrolltimer
= null;
133 updateNickList: function(nicks
) {
134 var nickHash
= {}, present
= {};
136 var lnh
= this.lastNickHash
;
138 for(var i
=0;i
<nicks
.length
;i
++)
139 present
[nicks
[i
]] = 1;
143 this.nickListRemove(k
, lnh
[k
]);
145 for(var i
=0;i
<nicks
.length
;i
++) {
149 l
= this.nickListAdd(n
, i
);
156 this.lastNickHash
= nickHash
;
158 nickListAdd: function(position
, nick
) {
160 nickListRemove: function(nick
, stored
) {
162 historyExec: function(line
) {
163 this.commandhistory
.addLine(line
);
164 this.client
.exec(line
);