]>
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 and the qwebirc project.");
38 w
.addLine("", "http://www.qwebirc.org");
39 w
.addLine("", "Licensed under the GNU General Public License, Version 2.");
43 getClientId: function(client
) {
44 if(client
== qwebirc
.ui
.CUSTOM_CLIENT
) {
45 return qwebirc
.ui
.CUSTOM_CLIENT
;
50 getWindowIdentifier: function(client
, type
, name
) {
51 if(type
== qwebirc
.ui
.WINDOW_MESSAGES
)
53 if(type
== qwebirc
.ui
.WINDOW_STATUS
)
56 if(client
== qwebirc
.ui
.CUSTOM_CLIENT
) /* HACK */
59 return "_" + client
.toIRCLower(name
);
61 newWindow: function(client
, type
, name
) {
62 var w
= this.getWindow(client
, type
, name
);
66 var wId
= this.getWindowIdentifier(client
, 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(client
, 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(client
, 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
, this.options
.networkName
);
153 qwebirc
.ui
.StandardUI
= new Class({
154 Extends: qwebirc
.ui
.BaseUI
,
155 UICommands: qwebirc
.ui
.UI_COMMANDS
,
156 initialize: function(parentElement
, windowClass
, uiName
, options
) {
157 this.parent(parentElement
, windowClass
, uiName
, options
);
159 this.tabCompleter
= new qwebirc
.ui
.TabCompleterFactory(this);
160 this.uiOptions
= new qwebirc
.ui
.DefaultOptionsClass(this);
161 this.customWindows
= {};
164 if(Browser
.Engine
.trident
) {
169 document
.addEvent(ev
, this.__handleHotkey
.bind(this));
171 __handleHotkey: function(x
) {
172 if(!x
.alt
|| x
.control
) {
173 if(x
.key
== "backspace" || x
.key
== "/")
174 if(!this.getInputFocused(x
))
179 if(x
.key
== "a" || x
.key
== "A") {
181 var highestIndex
= -1;
185 for(var i
=0;i
<this.windowArray
.length
;i
++) {
186 var h
= this.windowArray
[i
].hilighted
;
192 if(highestIndex
> -1)
193 this.selectWindow(this.windowArray
[highestIndex
]);
194 } else if(x
.key
>= '0' && x
.key
<= '9') {
197 number
= x
.key
- '0';
203 if(number
>= this.windowArray
.length
)
206 this.selectWindow(this.windowArray
[number
]);
207 } else if(x
.key
== "left") {
210 } else if(x
.key
== "right") {
217 getInputFocused: function(x
) {
218 if($$("input").indexOf(x
.target
) == -1 && $$("textarea").indexOf(x
.target
) == -1)
222 newCustomWindow: function(name
, select
, type
) {
224 type
= qwebirc
.ui
.WINDOW_CUSTOM
;
226 var w
= this.newWindow(qwebirc
.ui
.CUSTOM_CLIENT
, type
, name
);
227 w
.addEvent("close", function(w
) {
228 delete this.windows
[qwebirc
.ui
.CUSTOM_CLIENT
][w
.identifier
];
232 this.selectWindow(w
);
236 addCustomWindow: function(windowName
, class_
, cssClass
, options
) {
237 if(!$defined(options
))
240 if(this.customWindows
[windowName
]) {
241 this.selectWindow(this.customWindows
[windowName
]);
245 var d
= this.newCustomWindow(windowName
, true);
246 this.customWindows
[windowName
] = d
;
248 d
.addEvent("close", function() {
249 this.customWindows
[windowName
] = null;
253 d
.lines
.addClass("qwebirc-" + cssClass
);
255 var ew
= new class_(d
.lines
, options
);
256 ew
.addEvent("close", function() {
262 embeddedWindow: function() {
263 this.addCustomWindow("Embedding wizard", qwebirc
.ui
.EmbedWizard
, "embeddedwizard", {baseURL: this.options
.baseURL
});
265 optionsWindow: function() {
266 this.addCustomWindow("Options", qwebirc
.ui
.OptionsPane
, "optionspane", this.uiOptions
);
268 aboutWindow: function() {
269 this.addCustomWindow("About", qwebirc
.ui
.AboutPane
, "aboutpane", this.uiOptions
);
271 privacyWindow: function() {
272 this.addCustomWindow("Privacy policy", qwebirc
.ui
.PrivacyPolicyPane
, "privacypolicypane", this.uiOptions
);
274 feedbackWindow: function() {
275 this.addCustomWindow("Feedback", qwebirc
.ui
.FeedbackPane
, "feedbackpane", this.uiOptions
);
277 faqWindow: function() {
278 this.addCustomWindow("FAQ", qwebirc
.ui
.FAQPane
, "faqpane", this.uiOptions
);
280 urlDispatcher: function(name
) {
281 if(name
== "embedded")
282 return ["a", this.embeddedWindow
.bind(this)];
284 if(name
== "options")
285 return ["a", this.optionsWindow
.bind(this)];
289 tabComplete: function(element
) {
290 this.tabCompleter
.tabComplete(element
);
292 resetTabComplete: function() {
293 this.tabCompleter
.reset();
297 qwebirc
.ui
.SoundUI
= new Class({
298 Extends: qwebirc
.ui
.StandardUI
,
299 initialize: function(parentElement
, windowClass
, uiName
, options
) {
300 this.parent(parentElement
, windowClass
, uiName
, options
);
302 this.soundInited
= false;
303 this.soundReady
= false;
305 this.setBeepOnMention(this.uiOptions
.BEEP_ON_MENTION
);
307 soundInit: function() {
310 if(!$defined(Browser
.Plugins
.Flash
) || Browser
.Plugins
.Flash
.version
< 8)
312 this.soundInited
= true;
314 this.soundPlayer
= new qwebirc
.sound
.SoundPlayer();
315 this.soundPlayer
.addEvent("ready", function() {
316 this.soundReady
= true;
318 this.soundPlayer
.go();
320 setBeepOnMention: function(value
) {
323 this.beepOnMention
= value
;
326 if(!this.soundReady
|| !this.beepOnMention
)
329 this.soundPlayer
.beep();
333 qwebirc
.ui
.QuakeNetUI
= new Class({
334 Extends: qwebirc
.ui
.SoundUI
,
335 urlDispatcher: function(name
, window
) {
336 if(name
== "qwhois") {
337 return ["span", function(auth
) {
338 this.client
.exec("/MSG Q whois #" + auth
);
341 if(name
== "whois") {
342 return ["span", function(nick
) {
343 this.client
.exec("/WHOIS " + nick
);
346 return this.parent(name
);
349 if(!qwebirc
.auth
.loggedin())
351 if(confirm("Log out?")) {
352 for(var client
in this.clients
) {
353 this.clients
[client
].quit("Logged out");
357 var foo = function() { document
.location
= "/auth?logout=1"; };
363 qwebirc
.ui
.NewLoginUI
= new Class({
364 Extends: qwebirc
.ui
.QuakeNetUI
,
365 loginBox: function(callbackfn
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
366 this.postInitialize();
368 var w
= this.newCustomWindow("Connect", true, qwebirc
.ui
.WINDOW_CONNECT
);
369 var callback = function(args
) {
374 qwebirc
.ui
.GenericLoginBox(w
.lines
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this.options
.networkName
);