]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/baseui.js
IE6 fix.
[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) {
28 this.windows[client] = {}
e20e5a6b 29 var w = this.newWindow(client, qwebirc.ui.WINDOW_STATUS, "Status");
9e769c12 30 this.selectWindow(w);
e8db8558
CP
31 if(!this.firstClient) {
32 this.firstClient = true;
e20e5a6b 33 w.addLine("", "qwebirc v" + qwebirc.VERSION);
4094890f 34 w.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved.");
e8db8558 35 w.addLine("", "http://webchat.quakenet.org/");
4094890f 36 w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org");
e8db8558 37 }
9e769c12
CP
38 return w;
39 },
40 newWindow: function(client, type, name) {
41 var identifier = name;
e20e5a6b 42 if(type == qwebirc.ui.WINDOW_STATUS)
9e769c12
CP
43 identifier = "";
44
45 var w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier);
46 this.windowArray.push(w);
47
48 return w;
49 },
50 getActiveWindow: function() {
51 return this.active;
52 },
53 __setActiveWindow: function(window) {
54 this.active = window;
55 },
56 selectWindow: function(window) {
57 if(this.active)
58 this.active.deselect();
59 window.select(); /* calls setActiveWindow */
a59dc700 60 document.title = window.name + " - " + this.options.appTitle;
9e769c12
CP
61 },
62 __closed: function(window) {
63 if(window.active) {
64 this.active = undefined;
65 if(this.windowArray.length == 1) {
66 this.windowArray = [];
67 } else {
68 var index = this.windowArray.indexOf(window);
6f2e4a37
CP
69 if(index == -1) {
70 return;
71 } else if(index == 0) {
9e769c12
CP
72 this.selectWindow(this.windowArray[1]);
73 } else {
74 this.selectWindow(this.windowArray[index - 1]);
75 }
9e769c12
CP
76 }
77 }
78
404cfb58 79 this.windowArray = this.windowArray.erase(window);
9e769c12 80 delete this.windows[window.client][window.identifier];
eb9b087b 81 },
eb9b087b
CP
82 /*
83 this shouldn't be called by overriding classes!
66de775f 84 they should implement their own!
eb9b087b
CP
85 some form of user input MUST be received before an
86 IRC connection is made, else users are going to get
87 tricked into getting themselves glined
88 */
66de775f 89 loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) {
e20e5a6b 90 qwebirc.ui.GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick);
9e769c12
CP
91 }
92});
381fddfd 93
e20e5a6b
CP
94qwebirc.ui.StandardUI = new Class({
95 Extends: qwebirc.ui.BaseUI,
381fddfd
CP
96 initialize: function(parentElement, windowClass, uiName, options) {
97 this.parent(parentElement, windowClass, uiName, options);
381fddfd 98 window.addEvent("keydown", function(x) {
bc4d9f4a 99 if(!x.alt || x.control)
381fddfd
CP
100 return;
101
102 if(x.key == "a" || x.key == "A") {
424608ac 103 new Event(x).stop();
381fddfd
CP
104 for(var i=0;i<this.windowArray.length;i++) {
105 if(this.windowArray[i].hilighted) {
106 this.selectWindow(this.windowArray[i]);
107 break;
108 }
109 }
110 } else if(x.key >= '0' && x.key <= '9') {
424608ac
CP
111 new Event(x).stop();
112
381fddfd
CP
113 number = x.key - '0';
114 if(number == 0)
115 number = 10
116
117 number = number - 1;
118
119 if(number >= this.windowArray.length)
120 return;
121
122 this.selectWindow(this.windowArray[number]);
123 }
124 }.bind(this));
841a451d 125 },
8af49135
CP
126 newCustomWindow: function(name, select, type) {
127 if(!type)
e20e5a6b 128 type = qwebirc.ui.WINDOW_CUSTOM;
8af49135 129
e20e5a6b 130 var w = this.newWindow(qwebirc.ui.CUSTOM_CLIENT, type, name);
8af49135
CP
131 w.addEvent("close", function(w) {
132 delete this.windows[name];
133 }.bind(this));
134
135 if(select)
136 this.selectWindow(w);
6c19eb8f 137
8af49135
CP
138 return w;
139 },
140 embeddedWindow: function() {
141 if(this.embedded) {
142 this.selectWindow(this.embedded)
143 return;
841a451d 144 }
8af49135 145
6c19eb8f 146 this.embedded = this.newCustomWindow("Embedding wizard", true);
8af49135
CP
147 this.embedded.addEvent("close", function() {
148 this.embedded = null;
149 }.bind(this));
150
e20e5a6b 151 var ew = new qwebirc.ui.EmbedWizard({parent: this.embedded.lines});
8af49135
CP
152 ew.addEvent("close", function() {
153 this.embedded.close();
154 }.bind(this));
841a451d 155 },
8af49135
CP
156 urlDispatcher: function(name) {
157 if(name == "embedded")
158 return this.embeddedWindow.bind(this);
159
160 return null;
161 }
381fddfd 162});
6f2e4a37 163
2cd9e32d 164qwebirc.ui.QuakeNetUI = new Class({
e20e5a6b 165 Extends: qwebirc.ui.StandardUI,
2cd9e32d
CP
166 urlDispatcher: function(name, window) {
167 if(name == "qwhois") {
168 return function(auth) {
169 this.client.exec("/MSG Q whois #" + auth);
170 }.bind(window);
171 }
172
173 return this.parent(name);
174 }
175});
176
177qwebirc.ui.NewLoginUI = new Class({
178 Extends: qwebirc.ui.QuakeNetUI,
6f2e4a37
CP
179 loginBox: function(callbackfn, initialNickname, initialChannels, autoConnect, autoNick) {
180 this.postInitialize();
e20e5a6b 181 var w = this.newCustomWindow("Connect", true, qwebirc.ui.WINDOW_CONNECT);
6f2e4a37
CP
182 var callback = function(args) {
183 w.close();
184 callbackfn(args);
185 };
186
e20e5a6b 187 qwebirc.ui.GenericLoginBox(w.lines, callback, initialNickname, initialChannels, autoConnect, autoNick);
6f2e4a37
CP
188 }
189});