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