]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/swmui.js
Alt hotkeys should stop the event.
[irc/quakenet/qwebirc.git] / js / ui / swmui.js
CommitLineData
9e769c12
CP
1var SWMUIWindow = new Class({
2 Extends: UIWindow,
3
4 initialize: function(parentObject, client, type, name) {
5 this.parent(parentObject, client, type, name);
18559d33
CP
6 this.contentPanel = new SWMPanel(parentObject.mainPanel, true);
7 this.contentPanel.addClass("content");
9e769c12
CP
8
9 if(type == WINDOW_CHANNEL) {
18559d33 10 this.nickList = new SWMPanel(this.contentPanel);
9e769c12 11 this.nickList.anchor = SWM_ANCHOR_RIGHT;
18559d33 12 this.nickList.addClass("nicklist");
9e769c12 13
18559d33 14 this.topic = new SWMPanel(this.contentPanel);
9e769c12 15 this.topic.anchor = SWM_ANCHOR_TOP;
18559d33 16 this.topic.addClass("topic");
9e769c12
CP
17 }
18
381fddfd
CP
19 this.xlines = new SWMPanel(this.contentPanel);
20 this.lines = this.xlines.element;
9e769c12
CP
21
22 this.tab = new Element("span");
23 this.tab.addClass("tab");
24
25 this.tab.appendText(name);
26 this.tab.addEvent("click", function() {
27 parentObject.selectWindow(this);
28 }.bind(this));
29
18559d33 30 parentObject.tabPanel.appendChild(this.tab);
9e769c12
CP
31 parentObject.resize();
32
33 if(type != WINDOW_STATUS) {
34 tabclose = new Element("span");
35 tabclose.addClass("tabclose");
36 tabclose.addEvent("click", function(e) {
37 new Event(e).stop();
38
39 if(type == WINDOW_CHANNEL)
40 this.client.exec("/PART " + name);
41
42 this.close();
43 }.bind(this));
44 tabclose.set("text", "X");
45 this.tab.appendChild(tabclose);
46 }
47 },
48 updateNickList: function(nicks) {
49 this.parent(nicks);
50
18559d33 51 this.nickList.removeAllChildren();
9e769c12
CP
52 nicks.each(function(nick) {
53 var e = new Element("div");
18559d33 54 this.nickList.appendChild(e);
9e769c12 55 e.appendChild(document.createTextNode(nick));
18559d33 56 }.bind(this));
9e769c12
CP
57
58 this.parentObject.resize();
59 },
60 updateTopic: function(topic) {
61 this.parent(topic);
9e769c12 62
18559d33
CP
63 this.topic.removeAllChildren();
64 Colourise(topic, this.topic.element);
9e769c12
CP
65
66 this.parentObject.resize();
67 },
68 select: function() {
69 this.parent();
70
71 this.contentPanel.setHidden(false);
72 this.parentObject.resize();
9e769c12
CP
73 this.tab.removeClass("tab-unselected");
74 this.tab.addClass("tab-selected");
75 },
76 deselect: function() {
77 this.parent();
78
79 this.contentPanel.setHidden(true);
80 this.parentObject.resize();
81 this.tab.removeClass("tab-selected");
82 this.tab.addClass("tab-unselected");
83 },
84 close: function() {
85 this.parent();
86
18559d33
CP
87 this.parentObject.mainPanel.removeChild(this.contentPanel.element);
88 this.parentObject.tabPanel.removeChild(this.tab);
9e769c12
CP
89 },
90 addLine: function(type, line, colour) {
9e769c12
CP
91 var e = new Element("div");
92
93 if(colour) {
65152b01 94 e.setStyles({"background": colour});
9e769c12
CP
95 } else if(this.lastcolour) {
96 e.addClass("linestyle1");
97 } else {
98 e.addClass("linestyle2");
99 }
100
9e769c12 101 this.lastcolour = !this.lastcolour;
18559d33 102
381fddfd
CP
103 this.parent(type, line, colour, e);
104 },
105 setHilighted: function(state) {
106 this.parent(state);
18559d33 107
381fddfd 108 if(state) {
9e769c12 109 this.tab.addClass("tab-highlighted");
381fddfd
CP
110 } else {
111 this.tab.removeClass("tab-highlighted");
112 }
9e769c12
CP
113 }
114});
115
116var SWMUI = new Class({
117 Extends: UI,
118 initialize: function(parentElement, theme) {
119 this.parent(parentElement, SWMUIWindow, "swmui");
18559d33 120
eb9b087b 121 this.parentElement = parentElement;
9e769c12 122 this.theme = theme;
eb9b087b
CP
123 },
124 postInitialize: function() {
18559d33
CP
125 this.rootFrame = new SWMFrame(this.parentElement);
126
127 this.tabPanel = new SWMPanel(this.rootFrame);
9e769c12 128 this.tabPanel.anchor = SWM_ANCHOR_TOP;
18559d33 129 this.tabPanel.addClass("tabs");
9e769c12 130
18559d33
CP
131 this.mainPanel = new SWMPanel(this.rootFrame);
132 this.mainPanel.addClass("main");
9e769c12 133
18559d33 134 this.entryPanel = new SWMPanel(this.rootFrame);
9e769c12 135 this.entryPanel.anchor = SWM_ANCHOR_BOTTOM;
18559d33 136 this.entryPanel.addClass("entry");
9e769c12
CP
137
138 var form = new Element("form");
139
140 var inputbox = new Element("input");
18559d33 141 inputbox.setStyle("border", "0px");
9e769c12
CP
142
143 window.addEvent("resize", function() {
18559d33 144 var s = this.entryPanel.getInnerSize().x;
9e769c12
CP
145 inputbox.setStyle("width", s + "px");
146 }.bind(this));
147
148 form.addEvent("submit", function(e) {
149 new Event(e).stop();
150
151 this.getActiveWindow().client.exec(inputbox.value);
152 inputbox.value = "";
153 }.bind(this));
154
18559d33 155 this.entryPanel.appendChild(form);
9e769c12
CP
156 form.appendChild(inputbox);
157 inputbox.focus();
158
159 this.resize();
160 },
161 resize: function() {
162 window.fireEvent("resize");
eb9b087b 163 },
d65fe45f 164 loginBox: function(callback, initialNickname, initialChannels) {
eb9b087b 165 var box = new Element("div");
3aaa4f2f 166 this.parentElement.appendChild(box);
eb9b087b
CP
167
168 var header = new Element("h1");
169 header.set("text", "qwebirc");
170 box.appendChild(header);
171
172 var form = new Element("form");
3aaa4f2f 173 box.appendChild(form);
eb9b087b
CP
174
175 var boxtable = new Element("table");
3aaa4f2f 176 form.appendChild(boxtable);
eb9b087b 177
3aaa4f2f
CP
178 var tbody = new Element("tbody");
179 boxtable.appendChild(tbody); /* stupid IE */
eb9b087b 180
3aaa4f2f
CP
181 function createRow(label, e2) {
182 var r = new Element("tr");
183 tbody.appendChild(r);
eb9b087b 184
3aaa4f2f
CP
185 var d1 = new Element("td");
186 if(label)
187 d1.set("text", label);
188 r.appendChild(d1);
eb9b087b 189
3aaa4f2f
CP
190 var d2 = new Element("td");
191 r.appendChild(d2);
192 d2.appendChild(e2);
193 return d1;
194 }
195
196 var nick = new Element("input");
197 createRow("Nickname:", nick);
eb9b087b 198 var chan = new Element("input");
3aaa4f2f 199 createRow("Channels (comma seperated):", chan);
eb9b087b 200
eb9b087b
CP
201 var connbutton = new Element("input", {"type": "submit"});
202 connbutton.set("value", "Connect");
3aaa4f2f 203 createRow(undefined, connbutton)
eb9b087b
CP
204
205 form.addEvent("submit", function(e) {
206 new Event(e).stop();
207 var nickname = nick.value;
208 var chans = chan.value;
d65fe45f
CP
209 if(chans == "#") /* sorry channel "#" :P */
210 chans = "";
211
eb9b087b
CP
212 if(!nickname) {
213 alert("You must supply a nickname.");
214 nick.focus();
215 return;
216 }
217
218 this.parentElement.removeChild(box);
219 this.postInitialize();
4656ff82 220 callback({"nickname": nickname, "autojoin": chans});
eb9b087b
CP
221 }.bind(this));
222
d65fe45f
CP
223 nick.set("value", initialNickname);
224 chan.set("value", initialChannels);
eb9b087b
CP
225
226 nick.focus();
9e769c12
CP
227 }
228});