]>
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;
22 this.subWindow
= null;
25 updateTopic: function(topic
, element
) {
26 qwebirc
.ui
.Colourise("[" + topic
+ "]", element
, this.client
.exec
, this.parentObject
.urlDispatcher
.bind(this.parentObject
), this);
31 if($defined(this.scrolltimer
)) {
32 $clear(this.scrolltimer
);
33 this.scrolltimer
= null;
36 this.parentObject
.__closed(this);
37 this.fireEvent("close", this);
39 subEvent: function(event
) {
40 if($defined(this.subWindow
))
41 this.subWindow
.fireEvent(event
);
43 setSubWindow: function(window
) {
44 this.subWindow
= window
;
48 this.parentObject
.__setActiveWindow(this);
50 this.setHilighted(qwebirc
.ui
.HILIGHT_NONE
);
52 this.subEvent("select");
53 this.resetScrollPos();
54 this.lastSelected
= new Date();
56 deselect: function() {
57 this.subEvent("deselect");
60 if($defined(this.scrolltimer
)) {
61 $clear(this.scrolltimer
);
62 this.scrolltimer
= null;
67 resetScrollPos: function() {
68 if(this.scrolleddown
) {
69 this.scrollToBottom();
70 } else if($defined(this.scrollpos
)) {
71 this.getScrollParent().scrollTo(this.scrollpos
.x
, this.scrollpos
.y
);
74 setScrollPos: function() {
75 if(!this.parentObject
.singleWindow
) {
76 this.scrolleddown
= this.scrolledDown();
77 this.scrollpos
= this.lines
.getScroll();
80 addLine: function(type
, line
, colour
, element
) {
81 var hilight
= qwebirc
.ui
.HILIGHT_NONE
;
85 hilight
= qwebirc
.ui
.HILIGHT_ACTIVITY
;
87 if(type
.match(/(NOTICE|ACTION|MSG)$/)) {
88 if(this.type
== qwebirc
.ui
.WINDOW_QUERY
|| this.type
== qwebirc
.ui
.WINDOW_MESSAGES
) {
89 if(type
.match(/^OUR/) || type
.match(/NOTICE$/)) {
90 hilight
= qwebirc
.ui
.HILIGHT_ACTIVITY
;
92 hilight
= qwebirc
.ui
.HILIGHT_US
;
93 this.parentObject
.beep();
94 this.parentObject
.flash();
97 if(!type
.match(/^OUR/) && this.client
.hilightController
.match(line
["m"])) {
99 hilight
= qwebirc
.ui
.HILIGHT_US
;
100 this.parentObject
.beep();
101 this.parentObject
.flash();
102 } else if(hilight
!= qwebirc
.ui
.HILIGHT_US
) {
103 hilight
= qwebirc
.ui
.HILIGHT_SPEECH
;
108 if(!this.active
&& (hilight
!= qwebirc
.ui
.HILIGHT_NONE
))
109 this.setHilighted(hilight
);
112 line
= this.parentObject
.theme
.message(type
, line
, lhilight
);
114 qwebirc
.ui
.Colourise(qwebirc
.irc
.IRCTimestamp(new Date()) + " " + line
, element
, this.client
.exec
, this.parentObject
.urlDispatcher
.bind(this.parentObject
), this);
115 this.scrollAdd(element
);
117 errorMessage: function(message
) {
118 this.addLine("", message
, "warncolour");
120 infoMessage: function(message
) {
121 this.addLine("", message
, "infocolour");
123 setHilighted: function(state
) {
124 if(state
== qwebirc
.ui
.HILIGHT_NONE
|| state
>= this.hilighted
)
125 this.hilighted
= state
;
127 scrolledDown: function() {
131 var parent
= this.lines
;
133 var prev
= parent
.getScroll();
134 var prevbottom
= parent
.getScrollSize().y
;
135 var prevsize
= parent
.getSize();
137 /* fixes an IE bug */
138 if(prevbottom
< prevsize
.y
)
139 prevbottom
= prevsize
.y
;
141 return prev
.y
+ prevsize
.y
== prevbottom
;
143 getScrollParent: function() {
144 var scrollparent
= this.lines
;
146 if($defined(this.scroller
))
147 scrollparent
= this.scroller
;
150 scrollToBottom: function() {
151 if(this.type
== qwebirc
.ui
.WINDOW_CUSTOM
|| this.type
== qwebirc
.ui
.WINDOW_CONNECT
)
154 var parent
= this.lines
;
155 var scrollparent
= this.getScrollParent();
157 scrollparent
.scrollTo(parent
.getScroll().x
, parent
.getScrollSize().y
);
159 scrollAdd: function(element
) {
160 var parent
= this.lines
;
162 /* scroll in bursts, else the browser gets really slow */
163 if($defined(element
)) {
164 var sd
= this.scrolledDown();
165 parent
.appendChild(element
);
168 $clear(this.scrolltimer
);
169 this.scrolltimer
= this.scrollAdd
.delay(50, this, [null]);
172 this.scrollToBottom();
173 this.scrolltimer
= null;
176 updateNickList: function(nicks
) {
177 var nickHash
= {}, present
= {};
179 var lnh
= this.lastNickHash
;
181 for(var i
=0;i
<nicks
.length
;i
++)
182 present
[nicks
[i
]] = 1;
186 this.nickListRemove(k
, lnh
[k
]);
188 for(var i
=0;i
<nicks
.length
;i
++) {
192 l
= this.nickListAdd(n
, i
);
199 this.lastNickHash
= nickHash
;
201 nickListAdd: function(position
, nick
) {
203 nickListRemove: function(nick
, stored
) {
205 historyExec: function(line
) {
206 this.commandhistory
.addLine(line
);
207 this.client
.exec(line
);