]>
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
.WINDOW_MESSAGES
= 6;
7 qwebirc
.ui
.CUSTOM_CLIENT
= "custom";
9 qwebirc
.ui
.BaseUI
= new Class({
10 Implements: [Events
, Options
],
12 appTitle: "QuakeNet Web IRC",
15 initialize: function(parentElement
, windowClass
, uiName
, options
) {
16 this.setOptions(options
);
20 this.windows
[qwebirc
.ui
.CUSTOM_CLIENT
] = {};
21 this.windowArray
= [];
22 this.windowClass
= windowClass
;
23 this.parentElement
= parentElement
;
24 this.parentElement
.addClass("qwebirc");
25 this.parentElement
.addClass("qwebirc-" + uiName
);
26 this.firstClient
= false;
27 this.commandhistory
= new qwebirc
.irc
.CommandHistory();
30 newClient: function(client
) {
31 client
.id
= this.clientId
++;
32 client
.hilightController
= new qwebirc
.ui
.HilightController(client
);
34 this.windows
[client
.id
] = {}
35 this.clients
[client
.id
] = client
;
36 var w
= this.newWindow(client
, qwebirc
.ui
.WINDOW_STATUS
, "Status");
38 if(!this.firstClient
) {
39 this.firstClient
= true;
40 w
.addLine("", "qwebirc v" + qwebirc
.VERSION
);
41 w
.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved.");
42 w
.addLine("", "http://webchat.quakenet.org/");
43 w
.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org");
47 getClientId: function(client
) {
48 if(client
== qwebirc
.ui
.CUSTOM_CLIENT
) {
49 return qwebirc
.ui
.CUSTOM_CLIENT
;
54 getWindowIdentifier: function(type
, name
) {
55 if(type
== qwebirc
.ui
.WINDOW_MESSAGES
)
57 if(type
== qwebirc
.ui
.WINDOW_STATUS
)
59 return "_" + name
.toIRCLower();
61 newWindow: function(client
, type
, name
) {
62 var w
= this.getWindow(client
, type
, name
);
66 var wId
= this.getWindowIdentifier(type
, name
);
67 var w
= this.windows
[this.getClientId(client
)][wId
] = new this.windowClass(this, client
, type
, name
, wId
);
68 this.windowArray
.push(w
);
72 getWindow: function(client
, type
, name
) {
73 var c
= this.windows
[this.getClientId(client
)];
77 return c
[this.getWindowIdentifier(type
, name
)];
79 getActiveWindow: function() {
82 getActiveIRCWindow: function(client
) {
83 if(!this.active
|| this.active
.type
== qwebirc
.ui
.WINDOW_CUSTOM
) {
84 return this.windows
[this.getClientId(client
)][this.getWindowIdentifier(qwebirc
.ui
.WINDOW_STATUS
)];
89 __setActiveWindow: function(window
) {
92 selectWindow: function(window
) {
94 this.active
.deselect();
95 window
.select(); /* calls setActiveWindow */
96 document
.title
= window
.name
+ " - " + this.options
.appTitle
;
98 nextWindow: function(direction
) {
99 if(this.windowArray
.length
== 0 || !this.active
)
105 var index
= this.windowArray
.indexOf(this.active
);
109 index
= index
+ direction
;
111 index
= this.windowArray
.length
- 1;
112 } else if(index
>= this.windowArray
.length
) {
116 this.selectWindow(this.windowArray
[index
]);
118 prevWindow: function() {
121 __closed: function(window
) {
123 this.active
= undefined;
124 if(this.windowArray
.length
== 1) {
125 this.windowArray
= [];
127 var index
= this.windowArray
.indexOf(window
);
130 } else if(index
== 0) {
131 this.selectWindow(this.windowArray
[1]);
133 this.selectWindow(this.windowArray
[index
- 1]);
138 this.windowArray
= this.windowArray
.erase(window
);
139 delete this.windows
[this.getClientId(window
.client
)][window
.identifier
];
142 this shouldn't be called by overriding classes!
143 they should implement their own!
144 some form of user input MUST be received before an
145 IRC connection is made, else users are going to get
146 tricked into getting themselves glined
148 loginBox: function(callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
149 qwebirc
.ui
.GenericLoginBox(this.parentElement
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
);
153 qwebirc
.ui
.StandardUI
= new Class({
154 Extends: qwebirc
.ui
.BaseUI
,
155 initialize: function(parentElement
, windowClass
, uiName
, options
) {
156 this.parent(parentElement
, windowClass
, uiName
, options
);
158 this.tabCompleter
= new qwebirc
.ui
.TabCompleterFactory(this);
159 this.uiOptions
= new qwebirc
.ui
.DefaultOptionsClass(this);
160 this.customWindows
= {};
162 window
.addEvent("keydown", function(x
) {
163 if(!x
.alt
|| x
.control
)
167 if(x
.key
== "a" || x
.key
== "A") {
169 var highestIndex
= -1;
173 for(var i
=0;i
<this.windowArray
.length
;i
++) {
174 var h
= this.windowArray
[i
].hilighted
;
180 if(highestIndex
> -1)
181 this.selectWindow(this.windowArray
[highestIndex
]);
182 } else if(x
.key
>= '0' && x
.key
<= '9') {
185 number
= x
.key
- '0';
191 if(number
>= this.windowArray
.length
)
194 this.selectWindow(this.windowArray
[number
]);
195 } else if(x
.key
== "left") {
198 } else if(x
.key
== "right") {
206 newCustomWindow: function(name
, select
, type
) {
208 type
= qwebirc
.ui
.WINDOW_CUSTOM
;
210 var w
= this.newWindow(qwebirc
.ui
.CUSTOM_CLIENT
, type
, name
);
211 w
.addEvent("close", function(w
) {
212 delete this.windows
[qwebirc
.ui
.CUSTOM_CLIENT
][w
.identifier
];
216 this.selectWindow(w
);
220 addCustomWindow: function(windowName
, class_
, cssClass
, options
) {
221 if(!$defined(options
))
224 if(this.customWindows
[windowName
]) {
225 this.selectWindow(this.customWindows
[windowName
]);
229 var d
= this.newCustomWindow(windowName
, true);
230 this.customWindows
[windowName
] = d
;
232 d
.addEvent("close", function() {
233 this.customWindows
[windowName
] = null;
237 d
.lines
.addClass(cssClass
);
239 var ew
= new class_(d
.lines
, options
);
240 ew
.addEvent("close", function() {
244 embeddedWindow: function() {
245 this.addCustomWindow("Embedded Wizard", qwebirc
.ui
.EmbedWizard
, "embeddedwizard");
247 optionsWindow: function() {
248 this.addCustomWindow("Options", qwebirc
.ui
.OptionsPane
, "optionspane", this.uiOptions
);
250 urlDispatcher: function(name
) {
251 if(name
== "embedded")
252 return ["a", this.embeddedWindow
.bind(this)];
254 if(name
== "options")
255 return ["a", this.optionsWindow
.bind(this)];
259 tabComplete: function(element
) {
260 this.tabCompleter
.tabComplete(element
);
262 resetTabComplete: function() {
263 this.tabCompleter
.reset();
267 qwebirc
.ui
.SoundUI
= new Class({
268 Extends: qwebirc
.ui
.StandardUI
,
269 initialize: function(parentElement
, windowClass
, uiName
, options
) {
270 this.parent(parentElement
, windowClass
, uiName
, options
);
272 this.soundInited
= false;
273 this.soundReady
= false;
275 this.setBeepOnMention(this.uiOptions
.BEEP_ON_MENTION
);
277 soundInit: function() {
280 if(!$defined(Browser
.Plugins
.Flash
) || Browser
.Plugins
.Flash
.version
< 8)
282 this.soundInited
= true;
284 this.soundPlayer
= new qwebirc
.sound
.SoundPlayer();
285 this.soundPlayer
.addEvent("ready", function() {
286 this.soundReady
= true;
288 this.soundPlayer
.go();
290 setBeepOnMention: function(value
) {
293 this.beepOnMention
= value
;
296 if(!this.soundReady
|| !this.beepOnMention
)
299 this.soundPlayer
.beep();
303 qwebirc
.ui
.QuakeNetUI
= new Class({
304 Extends: qwebirc
.ui
.SoundUI
,
305 urlDispatcher: function(name
, window
) {
306 if(name
== "qwhois") {
307 return ["span", function(auth
) {
308 this.client
.exec("/MSG Q whois #" + auth
);
311 if(name
== "whois") {
312 return ["span", function(nick
) {
313 this.client
.exec("/WHOIS " + nick
);
316 return this.parent(name
);
319 if(!qwebirc
.auth
.loggedin())
321 if(confirm("Log out?")) {
322 for(var client
in this.clients
) {
323 this.clients
[client
].quit("Logged out");
325 document
.location
= "/auth?logout=1";
330 qwebirc
.ui
.NewLoginUI
= new Class({
331 Extends: qwebirc
.ui
.QuakeNetUI
,
332 loginBox: function(callbackfn
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
333 this.postInitialize();
335 var w
= this.newCustomWindow("Connect", true, qwebirc
.ui
.WINDOW_CONNECT
);
336 var callback = function(args
) {
341 qwebirc
.ui
.GenericLoginBox(w
.lines
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
);