]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/qui.js
Fix scrolling in alternate window bug.
[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
76 var toppos = 0;
77 var rightpos = 0;
78 var bottompos = formdiv.getSize().y;
79
80 if(type == WINDOW_CHANNEL) {
81 this.nicklist = new Element("div");
82 this.nicklist.addClass("nicklist");
83 this.nicklist.setStyle("bottom", (bottompos - 1) + "px");
84
85 this.window.appendChild(this.nicklist);
86 rightpos = this.nicklist.getSize().x;
87
88 this.topic = new Element("div");
89 this.topic.addClass("topic");
90 this.topic.set("html", " ");
91 this.topic.setStyle("right", rightpos + "px");
92 this.window.appendChild(this.topic);
93
94 toppos = this.topic.getSize().y;
95 }
96
97 this.lines.setStyle("top", toppos + "px");
98 this.lines.setStyle("bottom", bottompos + "px");
99 this.lines.setStyle("right", rightpos + "px");
100 this.lines.addClass("lines");
101 },
102 updateNickList: function(nicks) {
103 this.parent(nicks);
104
105 var n = this.nicklist;
106 while(n.firstChild)
107 n.removeChild(n.firstChild);
108
109 nicks.each(function(nick) {
110 var e = new Element("div");
111 n.appendChild(e);
112 e.appendChild(document.createTextNode(nick));
113 });
114 },
115 updateTopic: function(topic) {
116 this.parent(topic);
117
118 var t = this.topic;
119
120 while(t.firstChild)
121 t.removeChild(t.firstChild);
122
123 Colourise(topic, t);
124 },
125 select: function() {
126 this.window.removeClass("tab-invisible");
127 this.tab.removeClass("tab-unselected");
128 this.tab.addClass("tab-selected");
129 this.parent();
130 },
131 deselect: function() {
132 this.parent();
133
134 this.window.addClass("tab-invisible");
135 this.tab.removeClass("tab-selected");
136 this.tab.addClass("tab-unselected");
137 },
138 close: function() {
139 this.parent();
140
141 this.parentObject.container.removeChild(this.window);
142 this.parentObject.tabs.removeChild(this.tab);
143 },
144 addLine: function(type, line, colour) {
145 var e = new Element("div");
146
147 if(colour) {
148 e.setStyles({"background": colour});
149 } else if(this.lastcolour) {
150 e.addClass("linestyle1");
151 } else {
152 e.addClass("linestyle2");
153 }
154 this.lastcolour = !this.lastcolour;
155
156 this.parent(type, line, colour, e);
157 },
158 setHilighted: function(state) {
159 this.parent(state);
160
161 if(state) {
162 this.tab.addClass("tab-hilighted");
163 } else {
164 this.tab.removeClass("tab-hilighted");
165 }
166 }
167 });
168
169 var QUI = new Class({
170 Extends: UI,
171 initialize: function(parentElement, theme) {
172 this.parent(parentElement, QUIWindow, "qui");
173 this.theme = theme;
174 this.parentElement = parentElement;
175 },
176 reflow: function() {
177 var tabheight = this.tabs.getSize().y;
178 this.container.setStyle("top", tabheight + "px");
179 },
180 postInitialize: function() {
181 this.outerContainer = new Element("div");
182 this.outerContainer.addClass("outercontainer");
183 this.parentElement.appendChild(this.outerContainer);
184
185 this.tabs = new Element("div");
186 this.tabs.addClass("tabbar");
187 this.outerContainer.appendChild(this.tabs);
188
189 var tester = new Element("span");
190 this.tabs.appendChild(tester);
191
192 this.tabheight = this.tabs.getSize().y;
193 this.tabs.removeChild(tester);
194
195 this.container = new Element("div");
196 this.container.addClass("container");
197 this.outerContainer.appendChild(this.container);
198 },
199 loginBox: function(callbackfn, intialNickname, initialChannels) {
200 this.parent(function(options) {
201 this.postInitialize();
202 callbackfn(options);
203 }.bind(this), intialNickname, initialChannels);
204 }
205 });