]>
jfr.im git - irc/quakenet/qwebirc.git/blob - 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";
8 qwebirc
.ui
.BaseUI
= new Class({
9 Implements: [Events
, Options
],
11 appTitle: "QuakeNet Web IRC",
14 initialize: function(parentElement
, windowClass
, uiName
, options
) {
15 this.setOptions(options
);
19 this.windows
[qwebirc
.ui
.CUSTOM_CLIENT
] = {};
20 this.windowArray
= [];
21 this.windowClass
= windowClass
;
22 this.parentElement
= parentElement
;
23 this.parentElement
.addClass("qwebirc");
24 this.parentElement
.addClass("qwebirc-" + uiName
);
25 this.firstClient
= false;
26 this.commandhistory
= new qwebirc
.irc
.CommandHistory();
29 newClient: function(client
) {
30 client
.id
= this.clientId
++;
31 client
.hilightController
= new qwebirc
.ui
.HilightController(client
);
33 this.windows
[client
.id
] = {}
34 this.clients
[client
.id
] = client
;
35 var w
= this.newWindow(client
, qwebirc
.ui
.WINDOW_STATUS
, "Status");
37 if(!this.firstClient
) {
38 this.firstClient
= true;
39 w
.addLine("", "qwebirc v" + qwebirc
.VERSION
);
40 w
.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved.");
41 w
.addLine("", "http://webchat.quakenet.org/");
42 w
.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org");
46 getClientId: function(client
) {
47 if(client
== qwebirc
.ui
.CUSTOM_CLIENT
) {
48 return qwebirc
.ui
.CUSTOM_CLIENT
;
53 newWindow: function(client
, type
, name
) {
54 var identifier
= name
;
55 if(type
== qwebirc
.ui
.WINDOW_STATUS
)
58 var w
= this.windows
[this.getClientId(client
)][identifier
] = new this.windowClass(this, client
, type
, name
, identifier
);
59 this.windowArray
.push(w
);
63 getActiveWindow: function() {
66 getActiveIRCWindow: function(client
) {
67 if(!this.active
|| this.active
.type
== qwebirc
.ui
.WINDOW_CUSTOM
) {
68 return this.windows
[this.getClientId(client
)][""];
73 __setActiveWindow: function(window
) {
76 selectWindow: function(window
) {
78 this.active
.deselect();
79 window
.select(); /* calls setActiveWindow */
80 document
.title
= window
.name
+ " - " + this.options
.appTitle
;
82 nextWindow: function(direction
) {
83 if(this.windowArray
.length
== 0 || !this.active
)
89 var index
= this.windowArray
.indexOf(this.active
);
93 index
= index
+ direction
;
95 index
= this.windowArray
.length
- 1;
96 } else if(index
>= this.windowArray
.length
) {
100 this.selectWindow(this.windowArray
[index
]);
102 prevWindow: function() {
105 __closed: function(window
) {
107 this.active
= undefined;
108 if(this.windowArray
.length
== 1) {
109 this.windowArray
= [];
111 var index
= this.windowArray
.indexOf(window
);
114 } else if(index
== 0) {
115 this.selectWindow(this.windowArray
[1]);
117 this.selectWindow(this.windowArray
[index
- 1]);
122 this.windowArray
= this.windowArray
.erase(window
);
123 delete this.windows
[this.getClientId(window
.client
)][window
.identifier
];
126 this shouldn't be called by overriding classes!
127 they should implement their own!
128 some form of user input MUST be received before an
129 IRC connection is made, else users are going to get
130 tricked into getting themselves glined
132 loginBox: function(callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
133 qwebirc
.ui
.GenericLoginBox(this.parentElement
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
);
137 qwebirc
.ui
.StandardUI
= new Class({
138 Extends: qwebirc
.ui
.BaseUI
,
139 initialize: function(parentElement
, windowClass
, uiName
, options
) {
140 this.parent(parentElement
, windowClass
, uiName
, options
);
142 this.tabCompleter
= new qwebirc
.ui
.TabCompleterFactory(this);
143 this.uiOptions
= new qwebirc
.ui
.DefaultOptionsClass(this);
144 this.customWindows
= {};
146 window
.addEvent("keydown", function(x
) {
147 if(!x
.alt
|| x
.control
)
151 if(x
.key
== "a" || x
.key
== "A") {
153 var highestIndex
= -1;
157 for(var i
=0;i
<this.windowArray
.length
;i
++) {
158 var h
= this.windowArray
[i
].hilighted
;
164 if(highestIndex
> -1)
165 this.selectWindow(this.windowArray
[highestIndex
]);
166 } else if(x
.key
>= '0' && x
.key
<= '9') {
169 number
= x
.key
- '0';
175 if(number
>= this.windowArray
.length
)
178 this.selectWindow(this.windowArray
[number
]);
179 } else if(x
.key
== "left") {
182 } else if(x
.key
== "right") {
190 newCustomWindow: function(name
, select
, type
) {
192 type
= qwebirc
.ui
.WINDOW_CUSTOM
;
194 var w
= this.newWindow(qwebirc
.ui
.CUSTOM_CLIENT
, type
, name
);
195 w
.addEvent("close", function(w
) {
196 delete this.windows
[qwebirc
.ui
.CUSTOM_CLIENT
][name
];
200 this.selectWindow(w
);
204 addCustomWindow: function(windowName
, class_
, cssClass
, options
) {
205 if(!$defined(options
))
208 if(this.customWindows
[windowName
]) {
209 this.selectWindow(this.customWindows
[windowName
]);
213 var d
= this.newCustomWindow(windowName
, true);
214 this.customWindows
[windowName
] = d
;
216 d
.addEvent("close", function() {
217 this.customWindows
[windowName
] = null;
221 d
.lines
.addClass(cssClass
);
223 var ew
= new class_(d
.lines
, options
);
224 ew
.addEvent("close", function() {
228 embeddedWindow: function() {
229 this.addCustomWindow("Embedded Wizard", qwebirc
.ui
.EmbedWizard
, "embeddedwizard");
231 optionsWindow: function() {
232 this.addCustomWindow("Options", qwebirc
.ui
.OptionsPane
, "optionspane", this.uiOptions
);
234 urlDispatcher: function(name
) {
235 if(name
== "embedded")
236 return ["a", this.embeddedWindow
.bind(this)];
238 if(name
== "options")
239 return ["a", this.optionsWindow
.bind(this)];
243 tabComplete: function(element
) {
244 this.tabCompleter
.tabComplete(element
);
246 resetTabComplete: function() {
247 this.tabCompleter
.reset();
251 qwebirc
.ui
.SoundUI
= new Class({
252 Extends: qwebirc
.ui
.StandardUI
,
253 initialize: function(parentElement
, windowClass
, uiName
, options
) {
254 this.parent(parentElement
, windowClass
, uiName
, options
);
256 this.soundInited
= false;
257 this.soundReady
= false;
259 this.setBeepOnMention(this.uiOptions
.BEEP_ON_MENTION
);
261 soundInit: function() {
264 if(!$defined(Browser
.Plugins
.Flash
) || Browser
.Plugins
.Flash
.version
< 8)
266 this.soundInited
= true;
268 this.soundPlayer
= new qwebirc
.sound
.SoundPlayer();
269 this.soundPlayer
.addEvent("ready", function() {
270 this.soundReady
= true;
272 this.soundPlayer
.go();
274 setBeepOnMention: function(value
) {
277 this.beepOnMention
= value
;
280 if(!this.soundReady
|| !this.beepOnMention
)
283 this.soundPlayer
.beep();
287 qwebirc
.ui
.QuakeNetUI
= new Class({
288 Extends: qwebirc
.ui
.SoundUI
,
289 urlDispatcher: function(name
, window
) {
290 if(name
== "qwhois") {
291 return ["span", function(auth
) {
292 this.client
.exec("/MSG Q whois #" + auth
);
295 if(name
== "whois") {
296 return ["span", function(nick
) {
297 this.client
.exec("/WHOIS " + nick
);
300 return this.parent(name
);
303 if(!qwebirc
.auth
.loggedin())
305 if(confirm("Log out?")) {
306 for(var client
in this.clients
) {
307 this.clients
[client
].quit("Logged out");
309 document
.location
= "/auth?logout=1";
314 qwebirc
.ui
.NewLoginUI
= new Class({
315 Extends: qwebirc
.ui
.QuakeNetUI
,
316 loginBox: function(callbackfn
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
317 this.postInitialize();
319 var w
= this.newCustomWindow("Connect", true, qwebirc
.ui
.WINDOW_CONNECT
);
320 var callback = function(args
) {
325 qwebirc
.ui
.GenericLoginBox(w
.lines
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
);