]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/baseui.js
796929e2bb576b3d116a4b61c6469421c6aa1b59
[irc/quakenet/qwebirc.git] / js / ui / baseui.js
1 qwebirc.ui.WINDOW_STATUS = 1;
2 qwebirc.ui.WINDOW_QUERY = 2;
3 qwebirc.ui.WINDOW_CHANNEL = 3;
4 qwebirc.ui.WINDOW_CUSTOM = 4;
5 qwebirc.ui.WINDOW_CONNECT = 5;
6 qwebirc.ui.CUSTOM_CLIENT = "custom";
7
8 qwebirc.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 __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);
71 if(index == -1) {
72 return;
73 } else if(index == 0) {
74 this.selectWindow(this.windowArray[1]);
75 } else {
76 this.selectWindow(this.windowArray[index - 1]);
77 }
78 }
79 }
80
81 this.windowArray = this.windowArray.erase(window);
82 delete this.windows[window.client][window.identifier];
83 },
84 /*
85 this shouldn't be called by overriding classes!
86 they should implement their own!
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 */
91 loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) {
92 qwebirc.ui.GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick);
93 }
94 });
95
96 qwebirc.ui.StandardUI = new Class({
97 Extends: qwebirc.ui.BaseUI,
98 initialize: function(parentElement, windowClass, uiName, options) {
99 this.parent(parentElement, windowClass, uiName, options);
100 window.addEvent("keydown", function(x) {
101 if(!x.alt || x.control)
102 return;
103
104 if(x.key == "a" || x.key == "A") {
105 new Event(x).stop();
106 for(var i=0;i<this.windowArray.length;i++) {
107 if(this.windowArray[i].hilighted) {
108 this.selectWindow(this.windowArray[i]);
109 break;
110 }
111 }
112 } else if(x.key >= '0' && x.key <= '9') {
113 new Event(x).stop();
114
115 number = x.key - '0';
116 if(number == 0)
117 number = 10
118
119 number = number - 1;
120
121 if(number >= this.windowArray.length)
122 return;
123
124 this.selectWindow(this.windowArray[number]);
125 }
126 }.bind(this));
127 },
128 newCustomWindow: function(name, select, type) {
129 if(!type)
130 type = qwebirc.ui.WINDOW_CUSTOM;
131
132 var w = this.newWindow(qwebirc.ui.CUSTOM_CLIENT, type, name);
133 w.addEvent("close", function(w) {
134 delete this.windows[name];
135 }.bind(this));
136
137 if(select)
138 this.selectWindow(w);
139
140 return w;
141 },
142 embeddedWindow: function() {
143 if(this.embedded) {
144 this.selectWindow(this.embedded)
145 return;
146 }
147
148 this.embedded = this.newCustomWindow("Embedding wizard", true);
149 this.embedded.addEvent("close", function() {
150 this.embedded = null;
151 }.bind(this));
152
153 var ew = new qwebirc.ui.EmbedWizard({parent: this.embedded.lines});
154 ew.addEvent("close", function() {
155 this.embedded.close();
156 }.bind(this));
157 },
158 urlDispatcher: function(name) {
159 if(name == "embedded")
160 return this.embeddedWindow.bind(this);
161
162 return null;
163 }
164 });
165
166 qwebirc.ui.QuakeNetUI = new Class({
167 Extends: qwebirc.ui.StandardUI,
168 urlDispatcher: function(name, window) {
169 if(name == "qwhois") {
170 return function(auth) {
171 this.client.exec("/MSG Q whois #" + auth);
172 }.bind(window);
173 }
174
175 return this.parent(name);
176 }
177 });
178
179 qwebirc.ui.NewLoginUI = new Class({
180 Extends: qwebirc.ui.QuakeNetUI,
181 loginBox: function(callbackfn, initialNickname, initialChannels, autoConnect, autoNick) {
182 this.postInitialize();
183 var w = this.newCustomWindow("Connect", true, qwebirc.ui.WINDOW_CONNECT);
184 var callback = function(args) {
185 w.close();
186 callbackfn(args);
187 };
188
189 qwebirc.ui.GenericLoginBox(w.lines, callback, initialNickname, initialChannels, autoConnect, autoNick);
190 }
191 });