]>
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;
23 updateNickList: function(nicks
) {
25 updateTopic: function(topic
, element
) {
26 qwebirc
.ui
.Colourise("[" + topic
+ "]", element
, this.client
.exec
, this.parentObject
.urlDispatcher
.bind(this.parentObject
), this);
29 if($defined(this.scrolltimer
)) {
30 $clear(this.scrolltimer
);
31 this.scrolltimer
= null;
34 this.parentObject
.__closed(this);
35 this.fireEvent("close", this);
39 this.parentObject
.__setActiveWindow(this);
41 this.setHilighted(qwebirc
.ui
.HILIGHT_NONE
);
43 this.resetScrollPos();
44 this.lastSelected
= new Date();
46 deselect: function() {
48 if($defined(this.scrolltimer
)) {
49 $clear(this.scrolltimer
);
50 this.scrolltimer
= null;
55 resetScrollPos: function() {
56 if(this.scrolleddown
) {
57 this.scrollToBottom();
58 } else if($defined(this.scrollpos
)) {
59 this.getScrollParent().scrollTo(this.scrollpos
.x
, this.scrollpos
.y
);
62 setScrollPos: function() {
63 if(!this.parentObject
.singleWindow
) {
64 this.scrolleddown
= this.scrolledDown();
65 this.scrollpos
= this.lines
.getScroll();
68 addLine: function(type
, line
, colour
, element
) {
69 var hilight
= qwebirc
.ui
.HILIGHT_NONE
;
73 hilight
= qwebirc
.ui
.HILIGHT_ACTIVITY
;
75 if(type
.match(/(NOTICE|ACTION|MSG)$/)) {
76 if(this.type
== qwebirc
.ui
.WINDOW_QUERY
) {
77 hilight
= qwebirc
.ui
.HILIGHT_US
;
79 if(!type
.match(/^OUR/) && this.client
.hilightController
.match(line
["m"])) {
81 hilight
= qwebirc
.ui
.HILIGHT_US
;
82 } else if(hilight
!= qwebirc
.ui
.HILIGHT_US
) {
83 hilight
= qwebirc
.ui
.HILIGHT_SPEECH
;
88 if(!this.active
&& (hilight
!= qwebirc
.ui
.HILIGHT_NONE
))
89 this.setHilighted(hilight
);
92 line
= this.parentObject
.theme
.message(type
, line
, lhilight
);
94 qwebirc
.ui
.Colourise(qwebirc
.irc
.IRCTimestamp(new Date()) + " " + line
, element
, this.client
.exec
, this.parentObject
.urlDispatcher
.bind(this.parentObject
), this);
95 this.scrollAdd(element
);
97 errorMessage: function(message
) {
98 this.addLine("", message
, "red");
100 setHilighted: function(state
) {
101 if(state
== qwebirc
.ui
.HILIGHT_NONE
|| state
>= this.hilighted
)
102 this.hilighted
= state
;
104 scrolledDown: function() {
108 var parent
= this.lines
;
110 var prev
= parent
.getScroll();
111 var prevbottom
= parent
.getScrollSize().y
;
112 var prevsize
= parent
.getSize();
114 /* fixes an IE bug */
115 if(prevbottom
< prevsize
.y
)
116 prevbottom
= prevsize
.y
;
118 return prev
.y
+ prevsize
.y
== prevbottom
;
120 getScrollParent: function() {
121 var scrollparent
= this.lines
;
123 if($defined(this.scroller
))
124 scrollparent
= this.scroller
;
127 scrollToBottom: function() {
128 var parent
= this.lines
;
129 var scrollparent
= this.getScrollParent();
131 scrollparent
.scrollTo(parent
.getScroll().x
, parent
.getScrollSize().y
);
133 scrollAdd: function(element
) {
134 var parent
= this.lines
;
136 /* scroll in bursts, else the browser gets really slow */
137 if($defined(element
)) {
138 var sd
= this.scrolledDown();
139 parent
.appendChild(element
);
142 $clear(this.scrolltimer
);
143 this.scrolltimer
= this.scrollAdd
.delay(50, this, [null]);
146 this.scrollToBottom();
147 this.scrolltimer
= null;
150 updateNickList: function(nicks
) {
151 var nickHash
= {}, present
= {};
153 var lnh
= this.lastNickHash
;
155 for(var i
=0;i
<nicks
.length
;i
++)
156 present
[nicks
[i
]] = 1;
160 this.nickListRemove(k
, lnh
[k
]);
162 for(var i
=0;i
<nicks
.length
;i
++) {
166 l
= this.nickListAdd(n
, i
);
173 this.lastNickHash
= nickHash
;
175 nickListAdd: function(position
, nick
) {
177 nickListRemove: function(nick
, stored
) {
179 historyExec: function(line
) {
180 this.commandhistory
.addLine(line
);
181 this.client
.exec(line
);