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