]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/baseui.js
Add auth namespace.
[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 },
1d42a76f
CP
55 getActiveIRCWindow: function(client) {
56 if(!this.active || this.active.type == qwebirc.ui.WINDOW_CUSTOM) {
57 return this.windows[client][""];
58 } else {
59 return this.active;
60 }
61 },
9e769c12
CP
62 __setActiveWindow: function(window) {
63 this.active = window;
64 },
65 selectWindow: function(window) {
66 if(this.active)
67 this.active.deselect();
68 window.select(); /* calls setActiveWindow */
a59dc700 69 document.title = window.name + " - " + this.options.appTitle;
9e769c12 70 },
ff4befd8
CP
71 nextWindow: function(direction) {
72 if(this.windowArray.length == 0 || !this.active)
73 return;
74
75 if(!direction)
76 direction = 1;
77
78 var index = this.windowArray.indexOf(this.active);
79 if(index == -1)
80 return;
81
82 index = index + direction;
83 if(index < 0) {
84 index = this.windowArray.length - 1;
85 } else if(index >= this.windowArray.length) {
86 index = 0;
87 }
88
89 this.selectWindow(this.windowArray[index]);
90 },
91 prevWindow: function() {
92 this.nextWindow(-1);
93 },
9e769c12
CP
94 __closed: function(window) {
95 if(window.active) {
96 this.active = undefined;
97 if(this.windowArray.length == 1) {
98 this.windowArray = [];
99 } else {
100 var index = this.windowArray.indexOf(window);
6f2e4a37
CP
101 if(index == -1) {
102 return;
103 } else if(index == 0) {
9e769c12
CP
104 this.selectWindow(this.windowArray[1]);
105 } else {
106 this.selectWindow(this.windowArray[index - 1]);
107 }
9e769c12
CP
108 }
109 }
110
404cfb58 111 this.windowArray = this.windowArray.erase(window);
9e769c12 112 delete this.windows[window.client][window.identifier];
eb9b087b 113 },
eb9b087b
CP
114 /*
115 this shouldn't be called by overriding classes!
66de775f 116 they should implement their own!
eb9b087b
CP
117 some form of user input MUST be received before an
118 IRC connection is made, else users are going to get
119 tricked into getting themselves glined
120 */
66de775f 121 loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) {
e20e5a6b 122 qwebirc.ui.GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick);
9e769c12
CP
123 }
124});
381fddfd 125
e20e5a6b
CP
126qwebirc.ui.StandardUI = new Class({
127 Extends: qwebirc.ui.BaseUI,
381fddfd
CP
128 initialize: function(parentElement, windowClass, uiName, options) {
129 this.parent(parentElement, windowClass, uiName, options);
3184781b
CP
130
131 this.tabCompleter = new qwebirc.ui.TabCompleterFactory(this);
c38a0240 132 this.uiOptions = new qwebirc.ui.DefaultOptionsClass();
ebb21d2e
CP
133 this.customWindows = {};
134
381fddfd 135 window.addEvent("keydown", function(x) {
bc4d9f4a 136 if(!x.alt || x.control)
381fddfd
CP
137 return;
138
cf00dc43 139 var success = false;
381fddfd 140 if(x.key == "a" || x.key == "A") {
ffe442b0
CP
141 var highestNum = 0;
142 var highestIndex = -1;
cf00dc43
CP
143 success = true;
144
424608ac 145 new Event(x).stop();
381fddfd 146 for(var i=0;i<this.windowArray.length;i++) {
ffe442b0
CP
147 var h = this.windowArray[i].hilighted;
148 if(h > highestNum) {
149 highestIndex = i;
150 highestNum = h;
381fddfd
CP
151 }
152 }
ffe442b0
CP
153 if(highestIndex > -1)
154 this.selectWindow(this.windowArray[highestIndex]);
381fddfd 155 } else if(x.key >= '0' && x.key <= '9') {
cf00dc43 156 success = true;
424608ac 157
381fddfd
CP
158 number = x.key - '0';
159 if(number == 0)
160 number = 10
161
162 number = number - 1;
163
164 if(number >= this.windowArray.length)
165 return;
166
167 this.selectWindow(this.windowArray[number]);
ff4befd8
CP
168 } else if(x.key == "left") {
169 this.prevWindow();
cf00dc43 170 success = true;
ff4befd8
CP
171 } else if(x.key == "right") {
172 this.nextWindow();
cf00dc43 173 success = true;
381fddfd 174 }
cf00dc43
CP
175 if(success)
176 new Event(x).stop();
381fddfd 177 }.bind(this));
841a451d 178 },
8af49135
CP
179 newCustomWindow: function(name, select, type) {
180 if(!type)
e20e5a6b 181 type = qwebirc.ui.WINDOW_CUSTOM;
8af49135 182
e20e5a6b 183 var w = this.newWindow(qwebirc.ui.CUSTOM_CLIENT, type, name);
8af49135
CP
184 w.addEvent("close", function(w) {
185 delete this.windows[name];
186 }.bind(this));
187
188 if(select)
189 this.selectWindow(w);
6c19eb8f 190
8af49135
CP
191 return w;
192 },
ebb21d2e
CP
193 addCustomWindow: function(windowName, class_, cssClass, options) {
194 if(!$defined(options))
195 options = {};
196
197 if(this.customWindows[windowName]) {
198 this.selectWindow(this.customWindows[windowName]);
8af49135 199 return;
841a451d 200 }
8af49135 201
ebb21d2e
CP
202 var d = this.newCustomWindow(windowName, true);
203 this.customWindows[windowName] = d;
204
205 d.addEvent("close", function() {
206 this.customWindows[windowName] = null;
8af49135
CP
207 }.bind(this));
208
ebb21d2e
CP
209 if(cssClass)
210 d.lines.addClass(cssClass);
211
212 var ew = new class_(d.lines, options);
8af49135 213 ew.addEvent("close", function() {
ebb21d2e 214 d.close();
8af49135 215 }.bind(this));
841a451d 216 },
ebb21d2e
CP
217 embeddedWindow: function() {
218 this.addCustomWindow("Embedded Wizard", qwebirc.ui.EmbedWizard, "embeddedwizard");
219 },
220 optionsWindow: function() {
221 this.addCustomWindow("Options", qwebirc.ui.OptionsPane, "optionspane", this.uiOptions);
222 },
8af49135
CP
223 urlDispatcher: function(name) {
224 if(name == "embedded")
925fc357 225 return ["a", this.embeddedWindow.bind(this)];
ebb21d2e
CP
226
227 if(name == "options")
228 return ["a", this.optionsWindow.bind(this)];
8af49135
CP
229
230 return null;
3184781b
CP
231 },
232 tabComplete: function(element) {
233 this.tabCompleter.tabComplete(element);
234 },
235 resetTabComplete: function() {
236 this.tabCompleter.reset();
8af49135 237 }
381fddfd 238});
6f2e4a37 239
2cd9e32d 240qwebirc.ui.QuakeNetUI = new Class({
e20e5a6b 241 Extends: qwebirc.ui.StandardUI,
2cd9e32d
CP
242 urlDispatcher: function(name, window) {
243 if(name == "qwhois") {
7cb09779 244 return ["span", function(auth) {
2cd9e32d 245 this.client.exec("/MSG Q whois #" + auth);
925fc357
CP
246 }.bind(window)];
247 }
248 if(name == "whois") {
249 return ["span", function(nick) {
250 this.client.exec("/WHOIS " + nick);
251 }.bind(window)];
2cd9e32d 252 }
2cd9e32d
CP
253 return this.parent(name);
254 }
255});
256
257qwebirc.ui.NewLoginUI = new Class({
258 Extends: qwebirc.ui.QuakeNetUI,
6f2e4a37
CP
259 loginBox: function(callbackfn, initialNickname, initialChannels, autoConnect, autoNick) {
260 this.postInitialize();
c38a0240 261
e20e5a6b 262 var w = this.newCustomWindow("Connect", true, qwebirc.ui.WINDOW_CONNECT);
6f2e4a37
CP
263 var callback = function(args) {
264 w.close();
265 callbackfn(args);
266 };
267
e20e5a6b 268 qwebirc.ui.GenericLoginBox(w.lines, callback, initialNickname, initialChannels, autoConnect, autoNick);
6f2e4a37
CP
269 }
270});