]>
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.scrollpos
= null;
20 this.lastNickHash
= {};
21 this.lastSelected
= null;
24 updateNickList: function(nicks
) {
26 updateTopic: function(topic
, element
) {
27 qwebirc
.ui
.Colourise("[" + topic
+ "]", element
, this.client
.exec
, this.parentObject
.urlDispatcher
.bind(this.parentObject
), this);
32 if($defined(this.scrolltimer
)) {
33 $clear(this.scrolltimer
);
34 this.scrolltimer
= null;
37 this.parentObject
.__closed(this);
38 this.fireEvent("close", this);
42 this.parentObject
.__setActiveWindow(this);
44 this.setHilighted(qwebirc
.ui
.HILIGHT_NONE
);
46 this.resetScrollPos();
47 this.lastSelected
= new Date();
49 deselect: function() {
51 if($defined(this.scrolltimer
)) {
52 $clear(this.scrolltimer
);
53 this.scrolltimer
= null;
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
);
65 setScrollPos: function() {
66 if(!this.parentObject
.singleWindow
) {
67 this.scrolleddown
= this.scrolledDown();
68 this.scrollpos
= this.lines
.getScroll();
71 addLine: function(type
, line
, colour
, element
) {
72 var hilight
= qwebirc
.ui
.HILIGHT_NONE
;
76 hilight
= qwebirc
.ui
.HILIGHT_ACTIVITY
;
78 if(type
.match(/(NOTICE|ACTION|MSG)$/)) {
79 if(this.type
== qwebirc
.ui
.WINDOW_QUERY
|| this.type
== qwebirc
.ui
.WINDOW_MESSAGES
) {
80 if(type
.match(/^OUR/) || type
.match(/NOTICE$/)) {
81 hilight
= qwebirc
.ui
.HILIGHT_ACTIVITY
;
83 hilight
= qwebirc
.ui
.HILIGHT_US
;
84 this.parentObject
.beep();
87 if(!type
.match(/^OUR/) && this.client
.hilightController
.match(line
["m"])) {
89 hilight
= qwebirc
.ui
.HILIGHT_US
;
90 this.parentObject
.beep();
91 } else if(hilight
!= qwebirc
.ui
.HILIGHT_US
) {
92 hilight
= qwebirc
.ui
.HILIGHT_SPEECH
;
97 if(!this.active
&& (hilight
!= qwebirc
.ui
.HILIGHT_NONE
))
98 this.setHilighted(hilight
);
101 line
= this.parentObject
.theme
.message(type
, line
, lhilight
);
103 qwebirc
.ui
.Colourise(qwebirc
.irc
.IRCTimestamp(new Date()) + " " + line
, element
, this.client
.exec
, this.parentObject
.urlDispatcher
.bind(this.parentObject
), this);
104 this.scrollAdd(element
);
106 errorMessage: function(message
) {
107 this.addLine("", message
, "warncolour");
109 infoMessage: function(message
) {
110 this.addLine("", message
, "infocolour");
112 setHilighted: function(state
) {
113 if(state
== qwebirc
.ui
.HILIGHT_NONE
|| state
>= this.hilighted
)
114 this.hilighted
= state
;
116 scrolledDown: function() {
120 var parent
= this.lines
;
122 var prev
= parent
.getScroll();
123 var prevbottom
= parent
.getScrollSize().y
;
124 var prevsize
= parent
.getSize();
126 /* fixes an IE bug */
127 if(prevbottom
< prevsize
.y
)
128 prevbottom
= prevsize
.y
;
130 return prev
.y
+ prevsize
.y
== prevbottom
;
132 getScrollParent: function() {
133 var scrollparent
= this.lines
;
135 if($defined(this.scroller
))
136 scrollparent
= this.scroller
;
139 scrollToBottom: function() {
140 if(this.type
== qwebirc
.ui
.WINDOW_CUSTOM
|| this.type
== qwebirc
.ui
.WINDOW_CONNECT
)
143 var parent
= this.lines
;
144 var scrollparent
= this.getScrollParent();
146 scrollparent
.scrollTo(parent
.getScroll().x
, parent
.getScrollSize().y
);
148 scrollAdd: function(element
) {
149 var parent
= this.lines
;
151 /* scroll in bursts, else the browser gets really slow */
152 if($defined(element
)) {
153 var sd
= this.scrolledDown();
154 parent
.appendChild(element
);
157 $clear(this.scrolltimer
);
158 this.scrolltimer
= this.scrollAdd
.delay(50, this, [null]);
161 this.scrollToBottom();
162 this.scrolltimer
= null;
165 updateNickList: function(nicks
) {
166 var nickHash
= {}, present
= {};
168 var lnh
= this.lastNickHash
;
170 for(var i
=0;i
<nicks
.length
;i
++)
171 present
[nicks
[i
]] = 1;
175 this.nickListRemove(k
, lnh
[k
]);
177 for(var i
=0;i
<nicks
.length
;i
++) {
181 l
= this.nickListAdd(n
, i
);
188 this.lastNickHash
= nickHash
;
190 nickListAdd: function(position
, nick
) {
192 nickListRemove: function(nick
, stored
) {
194 historyExec: function(line
) {
195 this.commandhistory
.addLine(line
);
196 this.client
.exec(line
);