]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/qui.js
Add URL parsing for channels/nick selection.
[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
46 var form = new Element("form");
47 var inputbox = new Element("input");
48
49 formdiv.addClass("input");
50
51 form.addEvent("submit", function(e) {
52 new Event(e).stop();
53
54 this.historyExec(inputbox.value);
55 inputbox.value = "";
56 }.bind(this));
57 formdiv.appendChild(form);
58 form.appendChild(inputbox);
59
60 inputbox.addEvent("keypress", function(e) {
61 var result;
62 if(e.key == "up") {
63 result = this.commandhistory.nextLine();
64 } else if(e.key == "down") {
65 result = this.commandhistory.prevLine();
66 } else {
67 return;
68 }
69
70 new Event(e).stop();
71 if(!result)
72 result = ""
73 inputbox.value = result;
74 setAtEnd(inputbox);
75 }.bind(this));
76 this.inputbox = inputbox;
77
78 var toppos = 0;
79 var rightpos = 0;
80 var bottompos = formdiv.getSize().y;
81
82 if(type == WINDOW_CHANNEL) {
83 this.topic = new Element("div");
84 this.topic.addClass("topic");
85 this.topic.set("html", " ");
86 this.topic.setStyle("right", "0px");
87 this.window.appendChild(this.topic);
88
89 toppos = this.topic.getSize().y;
90
91 this.nicklist = new Element("div");
92 this.nicklist.addClass("nicklist");
93 this.nicklist.setStyle("top", toppos + "px");
94 this.nicklist.setStyle("bottom", (bottompos - 1) + "px");
95
96 this.window.appendChild(this.nicklist);
97 rightpos = this.nicklist.getSize().x;
98 }
99
100 this.lines.setStyle("top", toppos + "px");
101 this.lines.setStyle("bottom", bottompos + "px");
102 this.lines.setStyle("right", rightpos + "px");
103 this.lines.addClass("lines");
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 }.bind(this));
113 },
114 updateNickList: function(nicks) {
115 this.parent(nicks);
116
117 var n = this.nicklist;
118 while(n.firstChild)
119 n.removeChild(n.firstChild);
120
121 nicks.each(function(nick) {
122 var e = new Element("div");
123 n.appendChild(e);
124 e.appendChild(document.createTextNode(nick));
125 });
126 },
127 updateTopic: function(topic) {
128 this.parent(topic);
129
130 var t = this.topic;
131
132 while(t.firstChild)
133 t.removeChild(t.firstChild);
134
135 if(topic) {
136 Colourise(topic, "[" + topic + "]");
137 } else {
138 var e = new Element("(no topic set)");
139 e.addClass("emptytopic");
140 topic.appendChild(e);
141 }
142 },
143 select: function() {
144 this.window.removeClass("tab-invisible");
145 this.tab.removeClass("tab-unselected");
146 this.tab.addClass("tab-selected");
147 this.parent();
148
149 this.inputbox.focus();
150 },
151 deselect: function() {
152 this.parent();
153
154 this.window.addClass("tab-invisible");
155 this.tab.removeClass("tab-selected");
156 this.tab.addClass("tab-unselected");
157 },
158 close: function() {
159 this.parent();
160
161 this.parentObject.container.removeChild(this.window);
162 this.parentObject.tabs.removeChild(this.tab);
163 },
164 addLine: function(type, line, colour) {
165 var e = new Element("div");
166
167 if(colour) {
168 e.setStyles({"background": colour});
169 } else if(this.lastcolour) {
170 e.addClass("linestyle1");
171 } else {
172 e.addClass("linestyle2");
173 }
174 this.lastcolour = !this.lastcolour;
175
176 this.parent(type, line, colour, e);
177 },
178 setHilighted: function(state) {
179 this.parent(state);
180
181 if(state) {
182 this.tab.addClass("tab-hilighted");
183 } else {
184 this.tab.removeClass("tab-hilighted");
185 }
186 }
187 });
188
189 var QUI = new Class({
190 Extends: UI,
191 initialize: function(parentElement, theme) {
192 this.parent(parentElement, QUIWindow, "qui");
193 this.theme = theme;
194 this.parentElement = parentElement;
195 },
196 reflow: function() {
197 var tabheight = this.tabs.getSize().y;
198 this.container.setStyle("top", tabheight + "px");
199 },
200 postInitialize: function() {
201 this.outerContainer = new Element("div");
202 this.outerContainer.addClass("outercontainer");
203 this.parentElement.appendChild(this.outerContainer);
204
205 this.tabs = new Element("div");
206 this.tabs.addClass("tabbar");
207 this.outerContainer.appendChild(this.tabs);
208
209 var tester = new Element("span");
210 this.tabs.appendChild(tester);
211
212 this.tabheight = this.tabs.getSize().y;
213 this.tabs.removeChild(tester);
214
215 this.container = new Element("div");
216 this.container.addClass("container");
217 this.outerContainer.appendChild(this.container);
218 },
219 loginBox: function(callbackfn, intialNickname, initialChannels, autoConnect, autoNick) {
220 this.parent(function(options) {
221 this.postInitialize();
222 callbackfn(options);
223 }.bind(this), intialNickname, initialChannels, autoConnect, autoNick);
224 }
225 });