]>
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({
11 initialize: function(parentElement
, windowClass
, uiName
, options
) {
12 this.options
= options
;
16 this.windows
[qwebirc
.ui
.CUSTOM_CLIENT
] = {};
17 this.windowArray
= [];
18 this.windowClass
= windowClass
;
19 this.parentElement
= parentElement
;
20 this.parentElement
.addClass("qwebirc");
21 this.parentElement
.addClass("qwebirc-" + uiName
);
22 this.firstClient
= false;
23 this.commandhistory
= new qwebirc
.irc
.CommandHistory();
26 newClient: function(client
) {
27 client
.id
= this.clientId
++;
28 client
.hilightController
= new qwebirc
.ui
.HilightController(client
);
30 this.windows
[client
.id
] = {}
31 this.clients
[client
.id
] = client
;
32 var w
= this.newWindow(client
, qwebirc
.ui
.WINDOW_STATUS
, "Status");
34 if(!this.firstClient
) {
35 this.firstClient
= true;
36 w
.addLine("", "qwebirc v" + qwebirc
.VERSION
);
37 w
.addLine("", "Copyright (C) 2008-2009 Chris Porter. All rights reserved.");
38 w
.addLine("", "http://webchat.quakenet.org/");
39 w
.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org");
43 getClientId: function(client
) {
44 if(client
== qwebirc
.ui
.CUSTOM_CLIENT
) {
45 return qwebirc
.ui
.CUSTOM_CLIENT
;
50 getWindowIdentifier: function(type
, name
) {
51 if(type
== qwebirc
.ui
.WINDOW_MESSAGES
)
53 if(type
== qwebirc
.ui
.WINDOW_STATUS
)
55 return "_" + name
.toIRCLower();
57 newWindow: function(client
, type
, name
) {
58 var w
= this.getWindow(client
, type
, name
);
62 var wId
= this.getWindowIdentifier(type
, name
);
63 var w
= this.windows
[this.getClientId(client
)][wId
] = new this.windowClass(this, client
, type
, name
, wId
);
64 this.windowArray
.push(w
);
68 getWindow: function(client
, type
, name
) {
69 var c
= this.windows
[this.getClientId(client
)];
73 return c
[this.getWindowIdentifier(type
, name
)];
75 getActiveWindow: function() {
78 getActiveIRCWindow: function(client
) {
79 if(!this.active
|| this.active
.type
== qwebirc
.ui
.WINDOW_CUSTOM
) {
80 return this.windows
[this.getClientId(client
)][this.getWindowIdentifier(qwebirc
.ui
.WINDOW_STATUS
)];
85 __setActiveWindow: function(window
) {
88 selectWindow: function(window
) {
90 this.active
.deselect();
91 window
.select(); /* calls setActiveWindow */
92 document
.title
= window
.name
+ " - " + this.options
.appTitle
;
94 nextWindow: function(direction
) {
95 if(this.windowArray
.length
== 0 || !this.active
)
101 var index
= this.windowArray
.indexOf(this.active
);
105 index
= index
+ direction
;
107 index
= this.windowArray
.length
- 1;
108 } else if(index
>= this.windowArray
.length
) {
112 this.selectWindow(this.windowArray
[index
]);
114 prevWindow: function() {
117 __closed: function(window
) {
119 this.active
= undefined;
120 if(this.windowArray
.length
== 1) {
121 this.windowArray
= [];
123 var index
= this.windowArray
.indexOf(window
);
126 } else if(index
== 0) {
127 this.selectWindow(this.windowArray
[1]);
129 this.selectWindow(this.windowArray
[index
- 1]);
134 this.windowArray
= this.windowArray
.erase(window
);
135 delete this.windows
[this.getClientId(window
.client
)][window
.identifier
];
138 this shouldn't be called by overriding classes!
139 they should implement their own!
140 some form of user input MUST be received before an
141 IRC connection is made, else users are going to get
142 tricked into getting themselves glined
144 loginBox: function(callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
145 qwebirc
.ui
.GenericLoginBox(this.parentElement
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this.options
.networkName
);
149 qwebirc
.ui
.StandardUI
= new Class({
150 Extends: qwebirc
.ui
.BaseUI
,
151 UICommands: qwebirc
.ui
.UI_COMMANDS
,
152 initialize: function(parentElement
, windowClass
, uiName
, options
) {
153 this.parent(parentElement
, windowClass
, uiName
, options
);
155 this.tabCompleter
= new qwebirc
.ui
.TabCompleterFactory(this);
156 this.uiOptions
= new qwebirc
.ui
.DefaultOptionsClass(this);
157 this.customWindows
= {};
160 if(Browser
.Engine
.trident
) {
165 document
.addEvent(ev
, this.__handleHotkey
.bind(this));
167 __handleHotkey: function(x
) {
168 if(!x
.alt
|| x
.control
) {
169 if(x
.key
== "backspace" || x
.key
== "/")
170 if(!this.getInputFocused(x
))
175 if(x
.key
== "a" || x
.key
== "A") {
177 var highestIndex
= -1;
181 for(var i
=0;i
<this.windowArray
.length
;i
++) {
182 var h
= this.windowArray
[i
].hilighted
;
188 if(highestIndex
> -1)
189 this.selectWindow(this.windowArray
[highestIndex
]);
190 } else if(x
.key
>= '0' && x
.key
<= '9') {
193 number
= x
.key
- '0';
199 if(number
>= this.windowArray
.length
)
202 this.selectWindow(this.windowArray
[number
]);
203 } else if(x
.key
== "left") {
206 } else if(x
.key
== "right") {
213 getInputFocused: function(x
) {
214 if($$("input").indexOf(x
.target
) == -1 && $$("textarea").indexOf(x
.target
) == -1)
218 newCustomWindow: function(name
, select
, type
) {
220 type
= qwebirc
.ui
.WINDOW_CUSTOM
;
222 var w
= this.newWindow(qwebirc
.ui
.CUSTOM_CLIENT
, type
, name
);
223 w
.addEvent("close", function(w
) {
224 delete this.windows
[qwebirc
.ui
.CUSTOM_CLIENT
][w
.identifier
];
228 this.selectWindow(w
);
232 addCustomWindow: function(windowName
, class_
, cssClass
, options
) {
233 if(!$defined(options
))
236 if(this.customWindows
[windowName
]) {
237 this.selectWindow(this.customWindows
[windowName
]);
241 var d
= this.newCustomWindow(windowName
, true);
242 this.customWindows
[windowName
] = d
;
244 d
.addEvent("close", function() {
245 this.customWindows
[windowName
] = null;
249 d
.lines
.addClass("qwebirc-" + cssClass
);
251 var ew
= new class_(d
.lines
, options
);
252 ew
.addEvent("close", function() {
258 embeddedWindow: function() {
259 this.addCustomWindow("Embedding wizard", qwebirc
.ui
.EmbedWizard
, "embeddedwizard");
261 optionsWindow: function() {
262 this.addCustomWindow("Options", qwebirc
.ui
.OptionsPane
, "optionspane", this.uiOptions
);
264 aboutWindow: function() {
265 this.addCustomWindow("About", qwebirc
.ui
.AboutPane
, "aboutpane", this.uiOptions
);
267 privacyWindow: function() {
268 this.addCustomWindow("Privacy policy", qwebirc
.ui
.PrivacyPolicyPane
, "privacypolicypane", this.uiOptions
);
270 feedbackWindow: function() {
271 this.addCustomWindow("Feedback", qwebirc
.ui
.FeedbackPane
, "feedbackpane", this.uiOptions
);
273 faqWindow: function() {
274 this.addCustomWindow("FAQ", qwebirc
.ui
.FAQPane
, "faqpane", this.uiOptions
);
276 urlDispatcher: function(name
) {
277 if(name
== "embedded")
278 return ["a", this.embeddedWindow
.bind(this)];
280 if(name
== "options")
281 return ["a", this.optionsWindow
.bind(this)];
285 tabComplete: function(element
) {
286 this.tabCompleter
.tabComplete(element
);
288 resetTabComplete: function() {
289 this.tabCompleter
.reset();
293 qwebirc
.ui
.SoundUI
= new Class({
294 Extends: qwebirc
.ui
.StandardUI
,
295 initialize: function(parentElement
, windowClass
, uiName
, options
) {
296 this.parent(parentElement
, windowClass
, uiName
, options
);
298 this.soundInited
= false;
299 this.soundReady
= false;
301 this.setBeepOnMention(this.uiOptions
.BEEP_ON_MENTION
);
303 soundInit: function() {
306 if(!$defined(Browser
.Plugins
.Flash
) || Browser
.Plugins
.Flash
.version
< 8)
308 this.soundInited
= true;
310 this.soundPlayer
= new qwebirc
.sound
.SoundPlayer();
311 this.soundPlayer
.addEvent("ready", function() {
312 this.soundReady
= true;
314 this.soundPlayer
.go();
316 setBeepOnMention: function(value
) {
319 this.beepOnMention
= value
;
322 if(!this.soundReady
|| !this.beepOnMention
)
325 this.soundPlayer
.beep();
329 qwebirc
.ui
.QuakeNetUI
= new Class({
330 Extends: qwebirc
.ui
.SoundUI
,
331 urlDispatcher: function(name
, window
) {
332 if(name
== "qwhois") {
333 return ["span", function(auth
) {
334 this.client
.exec("/MSG Q whois #" + auth
);
337 if(name
== "whois") {
338 return ["span", function(nick
) {
339 this.client
.exec("/WHOIS " + nick
);
342 return this.parent(name
);
345 if(!qwebirc
.auth
.loggedin())
347 if(confirm("Log out?")) {
348 for(var client
in this.clients
) {
349 this.clients
[client
].quit("Logged out");
353 var foo = function() { document
.location
= "/auth?logout=1"; };
359 qwebirc
.ui
.NewLoginUI
= new Class({
360 Extends: qwebirc
.ui
.QuakeNetUI
,
361 loginBox: function(callbackfn
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
362 this.postInitialize();
364 var w
= this.newCustomWindow("Connect", true, qwebirc
.ui
.WINDOW_CONNECT
);
365 var callback = function(args
) {
370 qwebirc
.ui
.GenericLoginBox(w
.lines
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this.options
.networkName
);