]> jfr.im git - irc/quakenet/qwebirc.git/blame_incremental - js/ui/baseui.js
Rework the entire URL and prompting interface.
[irc/quakenet/qwebirc.git] / js / ui / baseui.js
... / ...
CommitLineData
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";
7
8qwebirc.ui.BaseUI = new Class({
9 Implements: [Events, Options],
10 options: {
11 appTitle: "QuakeNet Web IRC",
12 singleWindow: true
13 },
14 initialize: function(parentElement, windowClass, uiName, options) {
15 this.setOptions(options);
16
17 this.windows = {};
18 this.windows[qwebirc.ui.CUSTOM_CLIENT] = {};
19 this.windowArray = [];
20 this.windowClass = windowClass;
21 this.parentElement = parentElement;
22 this.parentElement.addClass("qwebirc");
23 this.parentElement.addClass("qwebirc-" + uiName);
24 this.firstClient = false;
25 this.commandhistory = new qwebirc.irc.CommandHistory();
26 },
27 newClient: function(client) {
28 client.hilightController = new qwebirc.ui.HilightController(client);
29
30 this.windows[client] = {}
31 var w = this.newWindow(client, qwebirc.ui.WINDOW_STATUS, "Status");
32 this.selectWindow(w);
33 if(!this.firstClient) {
34 this.firstClient = true;
35 w.addLine("", "qwebirc v" + qwebirc.VERSION);
36 w.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved.");
37 w.addLine("", "http://webchat.quakenet.org/");
38 w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org");
39 }
40 return w;
41 },
42 newWindow: function(client, type, name) {
43 var identifier = name;
44 if(type == qwebirc.ui.WINDOW_STATUS)
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 */
62 document.title = window.name + " - " + this.options.appTitle;
63 },
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 },
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);
94 if(index == -1) {
95 return;
96 } else if(index == 0) {
97 this.selectWindow(this.windowArray[1]);
98 } else {
99 this.selectWindow(this.windowArray[index - 1]);
100 }
101 }
102 }
103
104 this.windowArray = this.windowArray.erase(window);
105 delete this.windows[window.client][window.identifier];
106 },
107 /*
108 this shouldn't be called by overriding classes!
109 they should implement their own!
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 */
114 loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) {
115 qwebirc.ui.GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick);
116 }
117});
118
119qwebirc.ui.StandardUI = new Class({
120 Extends: qwebirc.ui.BaseUI,
121 initialize: function(parentElement, windowClass, uiName, options) {
122 this.parent(parentElement, windowClass, uiName, options);
123
124 this.tabCompleter = new qwebirc.ui.TabCompleterFactory(this);
125
126 window.addEvent("keydown", function(x) {
127 if(!x.alt || x.control)
128 return;
129
130 var success = false;
131 if(x.key == "a" || x.key == "A") {
132 var highestNum = 0;
133 var highestIndex = -1;
134 success = true;
135
136 new Event(x).stop();
137 for(var i=0;i<this.windowArray.length;i++) {
138 var h = this.windowArray[i].hilighted;
139 if(h > highestNum) {
140 highestIndex = i;
141 highestNum = h;
142 }
143 }
144 if(highestIndex > -1)
145 this.selectWindow(this.windowArray[highestIndex]);
146 } else if(x.key >= '0' && x.key <= '9') {
147 success = true;
148
149 number = x.key - '0';
150 if(number == 0)
151 number = 10
152
153 number = number - 1;
154
155 if(number >= this.windowArray.length)
156 return;
157
158 this.selectWindow(this.windowArray[number]);
159 } else if(x.key == "left") {
160 this.prevWindow();
161 success = true;
162 } else if(x.key == "right") {
163 this.nextWindow();
164 success = true;
165 }
166 if(success)
167 new Event(x).stop();
168 }.bind(this));
169 },
170 newCustomWindow: function(name, select, type) {
171 if(!type)
172 type = qwebirc.ui.WINDOW_CUSTOM;
173
174 var w = this.newWindow(qwebirc.ui.CUSTOM_CLIENT, type, name);
175 w.addEvent("close", function(w) {
176 delete this.windows[name];
177 }.bind(this));
178
179 if(select)
180 this.selectWindow(w);
181
182 return w;
183 },
184 embeddedWindow: function() {
185 if(this.embedded) {
186 this.selectWindow(this.embedded)
187 return;
188 }
189
190 this.embedded = this.newCustomWindow("Embedding wizard", true);
191 this.embedded.addEvent("close", function() {
192 this.embedded = null;
193 }.bind(this));
194
195 var ew = new qwebirc.ui.EmbedWizard({parent: this.embedded.lines});
196 ew.addEvent("close", function() {
197 this.embedded.close();
198 }.bind(this));
199 },
200 urlDispatcher: function(name) {
201 if(name == "embedded")
202 return ["a", this.embeddedWindow.bind(this)];
203
204 return null;
205 },
206 tabComplete: function(element) {
207 this.tabCompleter.tabComplete(element);
208 },
209 resetTabComplete: function() {
210 this.tabCompleter.reset();
211 }
212});
213
214qwebirc.ui.QuakeNetUI = new Class({
215 Extends: qwebirc.ui.StandardUI,
216 urlDispatcher: function(name, window) {
217 if(name == "qwhois") {
218 return ["a", function(auth) {
219 this.client.exec("/MSG Q whois #" + auth);
220 }.bind(window)];
221 }
222 if(name == "whois") {
223 return ["span", function(nick) {
224 this.client.exec("/WHOIS " + nick);
225 }.bind(window)];
226 }
227
228 return this.parent(name);
229 }
230});
231
232qwebirc.ui.NewLoginUI = new Class({
233 Extends: qwebirc.ui.QuakeNetUI,
234 loginBox: function(callbackfn, initialNickname, initialChannels, autoConnect, autoNick) {
235 this.postInitialize();
236 var w = this.newCustomWindow("Connect", true, qwebirc.ui.WINDOW_CONNECT);
237 var callback = function(args) {
238 w.close();
239 callbackfn(args);
240 };
241
242 qwebirc.ui.GenericLoginBox(w.lines, callback, initialNickname, initialChannels, autoConnect, autoNick);
243 }
244});