]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/baseuiwindow.js
Fix version in ctcp.
[irc/quakenet/qwebirc.git] / js / ui / baseuiwindow.js
CommitLineData
96f28062
CP
1qwebirc.ui.HILIGHT_NONE = 0;
2qwebirc.ui.HILIGHT_ACTIVITY = 1;
3qwebirc.ui.HILIGHT_SPEECH = 2;
4qwebirc.ui.HILIGHT_US = 3;
5
e20e5a6b 6qwebirc.ui.Window = new Class({
94b18192
CP
7 Implements: [Events],
8 initialize: function(parentObject, client, type, name, identifier) {
9 this.parentObject = parentObject;
10 this.type = type;
11 this.name = name;
12 this.active = false;
13 this.client = client;
14 this.identifier = identifier;
96f28062 15 this.hilighted = qwebirc.ui.HILIGHT_NONE;
381fddfd 16 this.scrolltimer = null;
9b63b053 17 this.commandhistory = this.parentObject.commandhistory;
25be5960 18 this.scrolleddown = true;
52090a1f 19 this.lastNickHash = {};
9b63b053 20 //new CommandHistory();
94b18192
CP
21 },
22 updateNickList: function(nicks) {
23 },
1f06a70a 24 updateTopic: function(topic, element) {
2cd9e32d 25 qwebirc.ui.Colourise("[" + topic + "]", element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this);
94b18192
CP
26 },
27 close: function() {
381fddfd
CP
28 if($defined(this.scrolltimer)) {
29 $clear(this.scrolltimer);
30 this.scrolltimer = null;
31 }
32
94b18192
CP
33 this.parentObject.__closed(this);
34 this.fireEvent("close", this);
35 },
36 select: function() {
37 this.active = true;
38 this.parentObject.__setActiveWindow(this);
381fddfd 39 if(this.hilighted)
96f28062 40 this.setHilighted(qwebirc.ui.HILIGHT_NONE);
7c633700 41 if(this.scrolleddown)
25be5960 42 this.scrollToBottom();
94b18192
CP
43 },
44 deselect: function() {
7c633700 45 if(!this.parentObject.singleWindow)
25be5960 46 this.scrolleddown = this.scrolledDown();
7c633700
CP
47 if($defined(this.scrolltimer)) {
48 $clear(this.scrolltimer);
49 this.scrolltimer = null;
50 }
51
94b18192
CP
52 this.active = false;
53 },
30bd2620 54 addLine: function(type, line, colour, element) {
96f28062 55 var hilight = qwebirc.ui.HILIGHT_NONE;
b2e77cf9
CP
56 var lhilight = false;
57
96f28062
CP
58 if(type) {
59 hilight = qwebirc.ui.HILIGHT_ACTIVITY;
60
61 if(type.match(/(NOTICE|ACTION|MSG)$/)) {
62 if(this.type == qwebirc.ui.WINDOW_QUERY) {
96f28062 63 hilight = qwebirc.ui.HILIGHT_US;
b2e77cf9
CP
64 }
65 if(!type.match(/^OUR/) && this.client.hilightController.match(line["m"])) {
66 lhilight = true;
67 hilight = qwebirc.ui.HILIGHT_US;
68 } else if(hilight != qwebirc.ui.HILIGHT_US) {
96f28062
CP
69 hilight = qwebirc.ui.HILIGHT_SPEECH;
70 }
71 }
72 }
73
74 if(!this.active && (hilight != qwebirc.ui.HILIGHT_NONE))
75 this.setHilighted(hilight);
76
381fddfd 77 if(type)
b2e77cf9 78 line = this.parentObject.theme.message(type, line, lhilight);
381fddfd 79
2cd9e32d 80 qwebirc.ui.Colourise(qwebirc.irc.IRCTimestamp(new Date()) + " " + line, element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this);
381fddfd 81 this.scrollAdd(element);
94b18192
CP
82 },
83 errorMessage: function(message) {
84 this.addLine("", message, "red");
381fddfd
CP
85 },
86 setHilighted: function(state) {
96f28062
CP
87 if(state == qwebirc.ui.HILIGHT_NONE || state >= this.hilighted)
88 this.hilighted = state;
381fddfd 89 },
25be5960 90 scrolledDown: function() {
7c633700
CP
91 if(this.scrolltimer)
92 return true;
93
381fddfd 94 var parent = this.lines;
381fddfd 95
381fddfd
CP
96 var prev = parent.getScroll();
97 var prevbottom = parent.getScrollSize().y;
98 var prevsize = parent.getSize();
25be5960 99
fccb1dac
CP
100 /* fixes an IE bug */
101 if(prevbottom < prevsize.y)
102 prevbottom = prevsize.y;
103
7c633700
CP
104 return prev.y + prevsize.y == prevbottom;
105 },
25be5960 106 scrollToBottom: function() {
7c633700
CP
107 var parent = this.lines;
108 var scrollparent = parent;
109
110 if($defined(this.scroller))
111 scrollparent = this.scroller;
112
113 scrollparent.scrollTo(parent.getScroll().x, parent.getScrollSize().y);
114 },
115 scrollAdd: function(element) {
116 var parent = this.lines;
381fddfd
CP
117
118 /* scroll in bursts, else the browser gets really slow */
119 if($defined(element)) {
25be5960 120 var sd = this.scrolledDown();
381fddfd 121 parent.appendChild(element);
7c633700 122 if(sd) {
381fddfd
CP
123 if(this.scrolltimer)
124 $clear(this.scrolltimer);
7c633700 125 this.scrolltimer = this.scrollAdd.delay(50, this, [null]);
381fddfd
CP
126 }
127 } else {
25be5960 128 this.scrollToBottom();
381fddfd
CP
129 this.scrolltimer = null;
130 }
9b63b053 131 },
52090a1f 132 updateNickList: function(nicks) {
833f14ce 133 var nickHash = {}, present = {};
52090a1f
CP
134 var added = [];
135 var lnh = this.lastNickHash;
136
833f14ce
CP
137 for(var i=0;i<nicks.length;i++)
138 present[nicks[i]] = 1;
139
140 for(var k in lnh)
141 if(!present[k])
142 this.nickListRemove(k, lnh[k]);
143
52090a1f
CP
144 for(var i=0;i<nicks.length;i++) {
145 var n = nicks[i];
146 var l = lnh[n];
147 if(!l) {
148 l = this.nickListAdd(n, i);
149 if(!l)
150 l = 1;
151 }
152 nickHash[n] = l;
153 }
154
52090a1f
CP
155 this.lastNickHash = nickHash;
156 },
157 nickListAdd: function(position, nick) {
158 },
159 nickListRemove: function(nick, stored) {
160 },
9b63b053
CP
161 historyExec: function(line) {
162 this.commandhistory.addLine(line);
163 this.client.exec(line);
94b18192
CP
164 }
165});