]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/baseui.js
New favicon courtesy of meeb.
[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
CP
63 },
64 __closed: function(window) {
65 if(window.active) {
66 this.active = undefined;
67 if(this.windowArray.length == 1) {
68 this.windowArray = [];
69 } else {
70 var index = this.windowArray.indexOf(window);
6f2e4a37
CP
71 if(index == -1) {
72 return;
73 } else if(index == 0) {
9e769c12
CP
74 this.selectWindow(this.windowArray[1]);
75 } else {
76 this.selectWindow(this.windowArray[index - 1]);
77 }
9e769c12
CP
78 }
79 }
80
404cfb58 81 this.windowArray = this.windowArray.erase(window);
9e769c12 82 delete this.windows[window.client][window.identifier];
eb9b087b 83 },
eb9b087b
CP
84 /*
85 this shouldn't be called by overriding classes!
66de775f 86 they should implement their own!
eb9b087b
CP
87 some form of user input MUST be received before an
88 IRC connection is made, else users are going to get
89 tricked into getting themselves glined
90 */
66de775f 91 loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) {
e20e5a6b 92 qwebirc.ui.GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick);
9e769c12
CP
93 }
94});
381fddfd 95
e20e5a6b
CP
96qwebirc.ui.StandardUI = new Class({
97 Extends: qwebirc.ui.BaseUI,
381fddfd
CP
98 initialize: function(parentElement, windowClass, uiName, options) {
99 this.parent(parentElement, windowClass, uiName, options);
381fddfd 100 window.addEvent("keydown", function(x) {
bc4d9f4a 101 if(!x.alt || x.control)
381fddfd
CP
102 return;
103
104 if(x.key == "a" || x.key == "A") {
ffe442b0
CP
105 var highestNum = 0;
106 var highestIndex = -1;
424608ac 107 new Event(x).stop();
381fddfd 108 for(var i=0;i<this.windowArray.length;i++) {
ffe442b0
CP
109 var h = this.windowArray[i].hilighted;
110 if(h > highestNum) {
111 highestIndex = i;
112 highestNum = h;
381fddfd
CP
113 }
114 }
ffe442b0
CP
115 if(highestIndex > -1)
116 this.selectWindow(this.windowArray[highestIndex]);
381fddfd 117 } else if(x.key >= '0' && x.key <= '9') {
424608ac
CP
118 new Event(x).stop();
119
381fddfd
CP
120 number = x.key - '0';
121 if(number == 0)
122 number = 10
123
124 number = number - 1;
125
126 if(number >= this.windowArray.length)
127 return;
128
129 this.selectWindow(this.windowArray[number]);
130 }
131 }.bind(this));
841a451d 132 },
8af49135
CP
133 newCustomWindow: function(name, select, type) {
134 if(!type)
e20e5a6b 135 type = qwebirc.ui.WINDOW_CUSTOM;
8af49135 136
e20e5a6b 137 var w = this.newWindow(qwebirc.ui.CUSTOM_CLIENT, type, name);
8af49135
CP
138 w.addEvent("close", function(w) {
139 delete this.windows[name];
140 }.bind(this));
141
142 if(select)
143 this.selectWindow(w);
6c19eb8f 144
8af49135
CP
145 return w;
146 },
147 embeddedWindow: function() {
148 if(this.embedded) {
149 this.selectWindow(this.embedded)
150 return;
841a451d 151 }
8af49135 152
6c19eb8f 153 this.embedded = this.newCustomWindow("Embedding wizard", true);
8af49135
CP
154 this.embedded.addEvent("close", function() {
155 this.embedded = null;
156 }.bind(this));
157
e20e5a6b 158 var ew = new qwebirc.ui.EmbedWizard({parent: this.embedded.lines});
8af49135
CP
159 ew.addEvent("close", function() {
160 this.embedded.close();
161 }.bind(this));
841a451d 162 },
8af49135
CP
163 urlDispatcher: function(name) {
164 if(name == "embedded")
925fc357 165 return ["a", this.embeddedWindow.bind(this)];
8af49135
CP
166
167 return null;
168 }
381fddfd 169});
6f2e4a37 170
2cd9e32d 171qwebirc.ui.QuakeNetUI = new Class({
e20e5a6b 172 Extends: qwebirc.ui.StandardUI,
2cd9e32d
CP
173 urlDispatcher: function(name, window) {
174 if(name == "qwhois") {
925fc357 175 return ["a", function(auth) {
2cd9e32d 176 this.client.exec("/MSG Q whois #" + auth);
925fc357
CP
177 }.bind(window)];
178 }
179 if(name == "whois") {
180 return ["span", function(nick) {
181 this.client.exec("/WHOIS " + nick);
182 }.bind(window)];
2cd9e32d
CP
183 }
184
185 return this.parent(name);
186 }
187});
188
189qwebirc.ui.NewLoginUI = new Class({
190 Extends: qwebirc.ui.QuakeNetUI,
6f2e4a37
CP
191 loginBox: function(callbackfn, initialNickname, initialChannels, autoConnect, autoNick) {
192 this.postInitialize();
e20e5a6b 193 var w = this.newCustomWindow("Connect", true, qwebirc.ui.WINDOW_CONNECT);
6f2e4a37
CP
194 var callback = function(args) {
195 w.close();
196 callbackfn(args);
197 };
198
e20e5a6b 199 qwebirc.ui.GenericLoginBox(w.lines, callback, initialNickname, initialChannels, autoConnect, autoNick);
6f2e4a37
CP
200 }
201});