]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/qui.js
Fix topic issues and resizing.
[irc/quakenet/qwebirc.git] / js / ui / qui.js
1 var QUIWindow = new Class({
2 Extends: UIWindow,
3
4 initialize: function(parentObject, client, type, name) {
5 this.parent(parentObject, client, type, name);
6
7 this.tab = new Element("a", {"href": "#"});
8 this.tab.addClass("tab");
9
10 this.tab.appendText(name);
11 this.tab.addEvent("click", function(e) {
12 new Event(e).stop();
13 parentObject.selectWindow(this);
14 }.bind(this));
15
16 parentObject.tabs.appendChild(this.tab);
17
18 if(type != WINDOW_STATUS) {
19 tabclose = new Element("span");
20 tabclose.addClass("tabclose");
21 tabclose.addEvent("click", function(e) {
22 new Event(e).stop();
23
24 if(type == WINDOW_CHANNEL)
25 this.client.exec("/PART " + name);
26
27 this.close();
28 }.bind(this));
29 tabclose.set("text", "X");
30 this.tab.appendChild(tabclose);
31 }
32
33 this.parentObject.reflow();
34
35 this.window = new Element("div");
36 this.window.addClass("window");
37 parentObject.container.appendChild(this.window);
38
39 this.lines = new Element("div");
40 this.lines.addClass("lines");
41 this.window.appendChild(this.lines);
42
43 var formdiv = new Element("div");
44 this.window.appendChild(formdiv);
45 this.formdiv = formdiv;
46
47 var form = new Element("form");
48 var inputbox = new Element("input");
49
50 formdiv.addClass("input");
51
52 form.addEvent("submit", function(e) {
53 new Event(e).stop();
54
55 this.historyExec(inputbox.value);
56 inputbox.value = "";
57 }.bind(this));
58 formdiv.appendChild(form);
59 form.appendChild(inputbox);
60
61 inputbox.addEvent("keypress", function(e) {
62 var result;
63 if(e.key == "up") {
64 result = this.commandhistory.nextLine();
65 } else if(e.key == "down") {
66 result = this.commandhistory.prevLine();
67 } else {
68 return;
69 }
70
71 new Event(e).stop();
72 if(!result)
73 result = ""
74 inputbox.value = result;
75 setAtEnd(inputbox);
76 }.bind(this));
77 this.inputbox = inputbox;
78
79 var toppos = 0;
80 var rightpos = 0;
81 var bottompos = formdiv.getSize().y;
82
83 if(type == WINDOW_CHANNEL) {
84 this.topic = new Element("div");
85 this.topic.addClass("topic");
86 this.topic.set("html", " ");
87
88 this.window.appendChild(this.topic);
89
90 this.nicklist = new Element("div");
91 this.nicklist.addClass("nicklist");
92
93 this.window.appendChild(this.nicklist);
94 rightpos = this.nicklist.getSize().x;
95 }
96
97 this.lines.addClass("lines");
98 if(type == WINDOW_CHANNEL) {
99 /* calls reflow */
100 this.updateTopic("");
101 } else {
102 this.reflow();
103 }
104
105 this.lines.addEvent("scroll", function() {
106 this.scrolleddown = this.scrolledDown();
107 }.bind(this));
108
109 window.addEvent("resize", function() {
110 if(this.scrolleddown)
111 this.scrollToBottom();
112 this.reflow();
113 }.bind(this));
114 },
115 reflow: function() {
116 var toppos = 0;
117 var rightpos = 0;
118 var bottompos = this.formdiv.getSize().y;
119
120 if(this.type == WINDOW_CHANNEL) {
121 toppos = this.topic.getSize().y;
122
123 this.nicklist.setStyle("top", toppos + "px");
124 this.nicklist.setStyle("bottom", (bottompos - 1) + "px");
125 }
126
127 this.lines.setStyle("top", toppos + "px");
128 this.lines.setStyle("bottom", bottompos + "px");
129 this.lines.setStyle("right", rightpos + "px");
130 },
131 updateNickList: function(nicks) {
132 this.parent(nicks);
133
134 var n = this.nicklist;
135 while(n.firstChild)
136 n.removeChild(n.firstChild);
137
138 nicks.each(function(nick) {
139 var e = new Element("div");
140 n.appendChild(e);
141 e.appendChild(document.createTextNode(nick));
142 });
143 },
144 updateTopic: function(topic) {
145 this.parent(topic);
146
147 var t = this.topic;
148
149 while(t.firstChild)
150 t.removeChild(t.firstChild);
151
152 if(topic) {
153 Colourise("[" + topic + "]", t);
154 } else {
155 var e = new Element("div");
156 e.set("text", "(no topic set)");
157 e.addClass("emptytopic");
158 t.appendChild(e);
159 }
160 this.reflow();
161 },
162 select: function() {
163 this.window.removeClass("tab-invisible");
164 this.tab.removeClass("tab-unselected");
165 this.tab.addClass("tab-selected");
166 this.reflow();
167
168 this.parent();
169
170 this.inputbox.focus();
171 },
172 deselect: function() {
173 this.parent();
174
175 this.window.addClass("tab-invisible");
176 this.tab.removeClass("tab-selected");
177 this.tab.addClass("tab-unselected");
178 },
179 close: function() {
180 this.parent();
181
182 this.parentObject.container.removeChild(this.window);
183 this.parentObject.tabs.removeChild(this.tab);
184 },
185 addLine: function(type, line, colour) {
186 var e = new Element("div");
187
188 if(colour) {
189 e.setStyles({"background": colour});
190 } else if(this.lastcolour) {
191 e.addClass("linestyle1");
192 } else {
193 e.addClass("linestyle2");
194 }
195 this.lastcolour = !this.lastcolour;
196
197 this.parent(type, line, colour, e);
198 },
199 setHilighted: function(state) {
200 this.parent(state);
201
202 if(state) {
203 this.tab.addClass("tab-hilighted");
204 } else {
205 this.tab.removeClass("tab-hilighted");
206 }
207 }
208 });
209
210 var QUI = new Class({
211 Extends: UI,
212 initialize: function(parentElement, theme) {
213 this.parent(parentElement, QUIWindow, "qui");
214 this.theme = theme;
215 this.parentElement = parentElement;
216 },
217 reflow: function() {
218 var tabheight = this.tabs.getSize().y;
219 this.container.setStyle("top", tabheight + "px");
220 },
221 postInitialize: function() {
222 this.outerContainer = new Element("div");
223 this.outerContainer.addClass("outercontainer");
224 this.parentElement.appendChild(this.outerContainer);
225
226 this.tabs = new Element("div");
227 this.tabs.addClass("tabbar");
228 this.outerContainer.appendChild(this.tabs);
229
230 var tester = new Element("span");
231 this.tabs.appendChild(tester);
232
233 this.tabheight = this.tabs.getSize().y;
234 this.tabs.removeChild(tester);
235
236 this.container = new Element("div");
237 this.container.addClass("container");
238 this.outerContainer.appendChild(this.container);
239 },
240 loginBox: function(callbackfn, intialNickname, initialChannels, autoConnect, autoNick) {
241 this.parent(function(options) {
242 this.postInitialize();
243 callbackfn(options);
244 }.bind(this), intialNickname, initialChannels, autoConnect, autoNick);
245 }
246 });