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