]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/baseui.js
Add /options and /embed.
[irc/quakenet/qwebirc.git] / js / ui / baseui.js
CommitLineData
e20e5a6b
CP
1qwebirc.ui.WINDOW_STATUS = 1;
2qwebirc.ui.WINDOW_QUERY = 2;
3qwebirc.ui.WINDOW_CHANNEL = 3;
4qwebirc.ui.WINDOW_CUSTOM = 4;
5qwebirc.ui.WINDOW_CONNECT = 5;
6qwebirc.ui.CUSTOM_CLIENT = "custom";
9e769c12 7
e20e5a6b 8qwebirc.ui.BaseUI = new Class({
a59dc700
CP
9 Implements: [Events, Options],
10 options: {
7c633700
CP
11 appTitle: "QuakeNet Web IRC",
12 singleWindow: true
a59dc700
CP
13 },
14 initialize: function(parentElement, windowClass, uiName, options) {
15 this.setOptions(options);
16
9e769c12 17 this.windows = {};
e20e5a6b 18 this.windows[qwebirc.ui.CUSTOM_CLIENT] = {};
9e769c12
CP
19 this.windowArray = [];
20 this.windowClass = windowClass;
21 this.parentElement = parentElement;
22 this.parentElement.addClass("qwebirc");
23 this.parentElement.addClass("qwebirc-" + uiName);
e8db8558 24 this.firstClient = false;
e20e5a6b 25 this.commandhistory = new qwebirc.irc.CommandHistory();
9e769c12
CP
26 },
27 newClient: function(client) {
96f28062
CP
28 client.hilightController = new qwebirc.ui.HilightController(client);
29
9e769c12 30 this.windows[client] = {}
e20e5a6b 31 var w = this.newWindow(client, qwebirc.ui.WINDOW_STATUS, "Status");
9e769c12 32 this.selectWindow(w);
e8db8558
CP
33 if(!this.firstClient) {
34 this.firstClient = true;
e20e5a6b 35 w.addLine("", "qwebirc v" + qwebirc.VERSION);
4094890f 36 w.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved.");
e8db8558 37 w.addLine("", "http://webchat.quakenet.org/");
4094890f 38 w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org");
e8db8558 39 }
9e769c12
CP
40 return w;
41 },
42 newWindow: function(client, type, name) {
43 var identifier = name;
e20e5a6b 44 if(type == qwebirc.ui.WINDOW_STATUS)
9e769c12
CP
45 identifier = "";
46
47 var w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier);
48 this.windowArray.push(w);
49
50 return w;
51 },
52 getActiveWindow: function() {
53 return this.active;
54 },
55 __setActiveWindow: function(window) {
56 this.active = window;
57 },
58 selectWindow: function(window) {
59 if(this.active)
60 this.active.deselect();
61 window.select(); /* calls setActiveWindow */
a59dc700 62 document.title = window.name + " - " + this.options.appTitle;
9e769c12 63 },
ff4befd8
CP
64 nextWindow: function(direction) {
65 if(this.windowArray.length == 0 || !this.active)
66 return;
67
68 if(!direction)
69 direction = 1;
70
71 var index = this.windowArray.indexOf(this.active);
72 if(index == -1)
73 return;
74
75 index = index + direction;
76 if(index < 0) {
77 index = this.windowArray.length - 1;
78 } else if(index >= this.windowArray.length) {
79 index = 0;
80 }
81
82 this.selectWindow(this.windowArray[index]);
83 },
84 prevWindow: function() {
85 this.nextWindow(-1);
86 },
9e769c12
CP
87 __closed: function(window) {
88 if(window.active) {
89 this.active = undefined;
90 if(this.windowArray.length == 1) {
91 this.windowArray = [];
92 } else {
93 var index = this.windowArray.indexOf(window);
6f2e4a37
CP
94 if(index == -1) {
95 return;
96 } else if(index == 0) {
9e769c12
CP
97 this.selectWindow(this.windowArray[1]);
98 } else {
99 this.selectWindow(this.windowArray[index - 1]);
100 }
9e769c12
CP
101 }
102 }
103
404cfb58 104 this.windowArray = this.windowArray.erase(window);
9e769c12 105 delete this.windows[window.client][window.identifier];
eb9b087b 106 },
eb9b087b
CP
107 /*
108 this shouldn't be called by overriding classes!
66de775f 109 they should implement their own!
eb9b087b
CP
110 some form of user input MUST be received before an
111 IRC connection is made, else users are going to get
112 tricked into getting themselves glined
113 */
66de775f 114 loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) {
e20e5a6b 115 qwebirc.ui.GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick);
9e769c12
CP
116 }
117});
381fddfd 118
e20e5a6b
CP
119qwebirc.ui.StandardUI = new Class({
120 Extends: qwebirc.ui.BaseUI,
381fddfd
CP
121 initialize: function(parentElement, windowClass, uiName, options) {
122 this.parent(parentElement, windowClass, uiName, options);
3184781b
CP
123
124 this.tabCompleter = new qwebirc.ui.TabCompleterFactory(this);
ebb21d2e
CP
125 this.uiOptions = new qwebirc.ui.Options();
126 this.customWindows = {};
127
381fddfd 128 window.addEvent("keydown", function(x) {
bc4d9f4a 129 if(!x.alt || x.control)
381fddfd
CP
130 return;
131
cf00dc43 132 var success = false;
381fddfd 133 if(x.key == "a" || x.key == "A") {
ffe442b0
CP
134 var highestNum = 0;
135 var highestIndex = -1;
cf00dc43
CP
136 success = true;
137
424608ac 138 new Event(x).stop();
381fddfd 139 for(var i=0;i<this.windowArray.length;i++) {
ffe442b0
CP
140 var h = this.windowArray[i].hilighted;
141 if(h > highestNum) {
142 highestIndex = i;
143 highestNum = h;
381fddfd
CP
144 }
145 }
ffe442b0
CP
146 if(highestIndex > -1)
147 this.selectWindow(this.windowArray[highestIndex]);
381fddfd 148 } else if(x.key >= '0' && x.key <= '9') {
cf00dc43 149 success = true;
424608ac 150
381fddfd
CP
151 number = x.key - '0';
152 if(number == 0)
153 number = 10
154
155 number = number - 1;
156
157 if(number >= this.windowArray.length)
158 return;
159
160 this.selectWindow(this.windowArray[number]);
ff4befd8
CP
161 } else if(x.key == "left") {
162 this.prevWindow();
cf00dc43 163 success = true;
ff4befd8
CP
164 } else if(x.key == "right") {
165 this.nextWindow();
cf00dc43 166 success = true;
381fddfd 167 }
cf00dc43
CP
168 if(success)
169 new Event(x).stop();
381fddfd 170 }.bind(this));
841a451d 171 },
8af49135
CP
172 newCustomWindow: function(name, select, type) {
173 if(!type)
e20e5a6b 174 type = qwebirc.ui.WINDOW_CUSTOM;
8af49135 175
e20e5a6b 176 var w = this.newWindow(qwebirc.ui.CUSTOM_CLIENT, type, name);
8af49135
CP
177 w.addEvent("close", function(w) {
178 delete this.windows[name];
179 }.bind(this));
180
181 if(select)
182 this.selectWindow(w);
6c19eb8f 183
8af49135
CP
184 return w;
185 },
ebb21d2e
CP
186 addCustomWindow: function(windowName, class_, cssClass, options) {
187 if(!$defined(options))
188 options = {};
189
190 if(this.customWindows[windowName]) {
191 this.selectWindow(this.customWindows[windowName]);
8af49135 192 return;
841a451d 193 }
8af49135 194
ebb21d2e
CP
195 var d = this.newCustomWindow(windowName, true);
196 this.customWindows[windowName] = d;
197
198 d.addEvent("close", function() {
199 this.customWindows[windowName] = null;
8af49135
CP
200 }.bind(this));
201
ebb21d2e
CP
202 if(cssClass)
203 d.lines.addClass(cssClass);
204
205 var ew = new class_(d.lines, options);
8af49135 206 ew.addEvent("close", function() {
ebb21d2e 207 d.close();
8af49135 208 }.bind(this));
841a451d 209 },
ebb21d2e
CP
210 embeddedWindow: function() {
211 this.addCustomWindow("Embedded Wizard", qwebirc.ui.EmbedWizard, "embeddedwizard");
212 },
213 optionsWindow: function() {
214 this.addCustomWindow("Options", qwebirc.ui.OptionsPane, "optionspane", this.uiOptions);
215 },
8af49135
CP
216 urlDispatcher: function(name) {
217 if(name == "embedded")
925fc357 218 return ["a", this.embeddedWindow.bind(this)];
ebb21d2e
CP
219
220 if(name == "options")
221 return ["a", this.optionsWindow.bind(this)];
8af49135
CP
222
223 return null;
3184781b
CP
224 },
225 tabComplete: function(element) {
226 this.tabCompleter.tabComplete(element);
227 },
228 resetTabComplete: function() {
229 this.tabCompleter.reset();
8af49135 230 }
381fddfd 231});
6f2e4a37 232
2cd9e32d 233qwebirc.ui.QuakeNetUI = new Class({
e20e5a6b 234 Extends: qwebirc.ui.StandardUI,
2cd9e32d
CP
235 urlDispatcher: function(name, window) {
236 if(name == "qwhois") {
7cb09779 237 return ["span", function(auth) {
2cd9e32d 238 this.client.exec("/MSG Q whois #" + auth);
925fc357
CP
239 }.bind(window)];
240 }
241 if(name == "whois") {
242 return ["span", function(nick) {
243 this.client.exec("/WHOIS " + nick);
244 }.bind(window)];
2cd9e32d 245 }
2cd9e32d
CP
246 return this.parent(name);
247 }
248});
249
250qwebirc.ui.NewLoginUI = new Class({
251 Extends: qwebirc.ui.QuakeNetUI,
6f2e4a37
CP
252 loginBox: function(callbackfn, initialNickname, initialChannels, autoConnect, autoNick) {
253 this.postInitialize();
e20e5a6b 254 var w = this.newCustomWindow("Connect", true, qwebirc.ui.WINDOW_CONNECT);
6f2e4a37
CP
255 var callback = function(args) {
256 w.close();
257 callbackfn(args);
258 };
259
e20e5a6b 260 qwebirc.ui.GenericLoginBox(w.lines, callback, initialNickname, initialChannels, autoConnect, autoNick);
6f2e4a37
CP
261 }
262});