]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/baseui.js
1 qwebirc
.ui
.WINDOW_STATUS
= 0x01;
2 qwebirc
.ui
.WINDOW_QUERY
= 0x02;
3 qwebirc
.ui
.WINDOW_CHANNEL
= 0x04;
4 qwebirc
.ui
.WINDOW_CUSTOM
= 0x08;
5 qwebirc
.ui
.WINDOW_CONNECT
= 0x10;
6 qwebirc
.ui
.WINDOW_MESSAGES
= 0x32;
8 qwebirc
.ui
.CUSTOM_CLIENT
= "custom";
10 qwebirc
.ui
.BaseUI
= new Class({
12 initialize: function(parentElement
, windowClass
, uiName
, options
) {
13 this.options
= options
;
17 this.windows
[qwebirc
.ui
.CUSTOM_CLIENT
] = {};
18 this.windowArray
= [];
19 this.windowClass
= windowClass
;
20 this.parentElement
= parentElement
;
21 this.parentElement
.addClass("qwebirc");
22 this.parentElement
.addClass("qwebirc-" + uiName
);
23 this.firstClient
= false;
24 this.commandhistory
= new qwebirc
.irc
.CommandHistory();
27 this.windowFocused
= true;
28 window
.addEvent("blur", function() { if(this.windowFocused
) { this.windowFocused
= false; this.focusChange(false); } }.bind(this));
29 window
.addEvent("focus", function() { if(!this.windowFocused
) { this.windowFocused
= true; this.focusChange(true); } }.bind(this));
31 newClient: function(client
) {
32 client
.id
= this.clientId
++;
33 client
.hilightController
= new qwebirc
.ui
.HilightController(client
);
35 this.windows
[client
.id
] = {}
36 this.clients
[client
.id
] = client
;
37 var w
= this.newWindow(client
, qwebirc
.ui
.WINDOW_STATUS
, "Status");
39 if(!this.firstClient
) {
40 this.firstClient
= true;
41 w
.addLine("", "qwebirc v" + qwebirc
.VERSION
);
42 w
.addLine("", "Copyright (C) 2008-2009 Chris Porter and the qwebirc project.");
43 w
.addLine("", "http://www.qwebirc.org");
44 w
.addLine("", "Licensed under the GNU General Public License, Version 2.");
48 getClientId: function(client
) {
49 if(client
== qwebirc
.ui
.CUSTOM_CLIENT
) {
50 return qwebirc
.ui
.CUSTOM_CLIENT
;
55 getWindowIdentifier: function(client
, type
, name
) {
56 if(type
== qwebirc
.ui
.WINDOW_MESSAGES
)
58 if(type
== qwebirc
.ui
.WINDOW_STATUS
)
61 if(client
== qwebirc
.ui
.CUSTOM_CLIENT
) /* HACK */
64 return "_" + client
.toIRCLower(name
);
66 newWindow: function(client
, type
, name
) {
67 var w
= this.getWindow(client
, type
, name
);
71 var wId
= this.getWindowIdentifier(client
, type
, name
);
72 var w
= this.windows
[this.getClientId(client
)][wId
] = new this.windowClass(this, client
, type
, name
, wId
);
73 this.windowArray
.push(w
);
77 getWindow: function(client
, type
, name
) {
78 var c
= this.windows
[this.getClientId(client
)];
82 return c
[this.getWindowIdentifier(client
, type
, name
)];
84 getActiveWindow: function() {
87 getActiveIRCWindow: function(client
) {
88 if(!this.active
|| this.active
.type
== qwebirc
.ui
.WINDOW_CUSTOM
) {
89 return this.windows
[this.getClientId(client
)][this.getWindowIdentifier(client
, qwebirc
.ui
.WINDOW_STATUS
)];
94 __setActiveWindow: function(window
) {
97 selectWindow: function(window
) {
99 this.active
.deselect();
100 window
.select(); /* calls setActiveWindow */
101 this.updateTitle(window
.name
+ " - " + this.options
.appTitle
);
103 updateTitle: function(text
) {
104 document
.title
= text
;
106 nextWindow: function(direction
) {
107 if(this.windowArray
.length
== 0 || !this.active
)
113 var index
= this.windowArray
.indexOf(this.active
);
117 index
= index
+ direction
;
119 index
= this.windowArray
.length
- 1;
120 } else if(index
>= this.windowArray
.length
) {
124 this.selectWindow(this.windowArray
[index
]);
126 prevWindow: function() {
129 __closed: function(window
) {
131 this.active
= undefined;
132 if(this.windowArray
.length
== 1) {
133 this.windowArray
= [];
135 var index
= this.windowArray
.indexOf(window
);
138 } else if(index
== 0) {
139 this.selectWindow(this.windowArray
[1]);
141 this.selectWindow(this.windowArray
[index
- 1]);
146 this.windowArray
= this.windowArray
.erase(window
);
147 delete this.windows
[this.getClientId(window
.client
)][window
.identifier
];
150 this shouldn't be called by overriding classes!
151 they should implement their own!
152 some form of user input MUST be received before an
153 IRC connection is made, else users are going to get
154 tricked into getting themselves glined
156 loginBox: function(callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
157 qwebirc
.ui
.GenericLoginBox(this.parentElement
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this.options
.networkName
);
159 focusChange: function(newValue
) {
160 var window_
= this.getActiveWindow();
161 if($defined(window_
))
162 window_
.focusChange(newValue
);
166 qwebirc
.ui
.StandardUI
= new Class({
167 Extends: qwebirc
.ui
.BaseUI
,
168 UICommands: qwebirc
.ui
.UI_COMMANDS
,
169 initialize: function(parentElement
, windowClass
, uiName
, options
) {
170 this.parent(parentElement
, windowClass
, uiName
, options
);
172 this.tabCompleter
= new qwebirc
.ui
.TabCompleterFactory(this);
173 this.uiOptions
= new qwebirc
.ui
.DefaultOptionsClass(this);
174 this.customWindows
= {};
177 if(Browser
.Engine
.trident
) {
182 document
.addEvent(ev
, this.__handleHotkey
.bind(this));
184 __handleHotkey: function(x
) {
185 if(!x
.alt
|| x
.control
) {
186 if(x
.key
== "backspace" || x
.key
== "/")
187 if(!this.getInputFocused(x
))
192 if(x
.key
== "a" || x
.key
== "A") {
194 var highestIndex
= -1;
198 for(var i
=0;i
<this.windowArray
.length
;i
++) {
199 var h
= this.windowArray
[i
].hilighted
;
205 if(highestIndex
> -1)
206 this.selectWindow(this.windowArray
[highestIndex
]);
207 } else if(x
.key
>= '0' && x
.key
<= '9') {
210 number
= x
.key
- '0';
216 if(number
>= this.windowArray
.length
)
219 this.selectWindow(this.windowArray
[number
]);
220 } else if(x
.key
== "left") {
223 } else if(x
.key
== "right") {
230 getInputFocused: function(x
) {
231 if($$("input").indexOf(x
.target
) == -1 && $$("textarea").indexOf(x
.target
) == -1)
235 newCustomWindow: function(name
, select
, type
) {
237 type
= qwebirc
.ui
.WINDOW_CUSTOM
;
239 var w
= this.newWindow(qwebirc
.ui
.CUSTOM_CLIENT
, type
, name
);
240 w
.addEvent("close", function(w
) {
241 delete this.windows
[qwebirc
.ui
.CUSTOM_CLIENT
][w
.identifier
];
245 this.selectWindow(w
);
249 addCustomWindow: function(windowName
, class_
, cssClass
, options
) {
250 if(!$defined(options
))
253 if(this.customWindows
[windowName
]) {
254 this.selectWindow(this.customWindows
[windowName
]);
258 var d
= this.newCustomWindow(windowName
, true);
259 this.customWindows
[windowName
] = d
;
261 d
.addEvent("close", function() {
262 this.customWindows
[windowName
] = null;
266 d
.lines
.addClass("qwebirc-" + cssClass
);
268 var ew
= new class_(d
.lines
, options
);
269 ew
.addEvent("close", function() {
275 embeddedWindow: function() {
276 this.addCustomWindow("Embedding wizard", qwebirc
.ui
.EmbedWizard
, "embeddedwizard", {baseURL: this.options
.baseURL
});
278 optionsWindow: function() {
279 this.addCustomWindow("Options", qwebirc
.ui
.OptionsPane
, "optionspane", this.uiOptions
);
281 aboutWindow: function() {
282 this.addCustomWindow("About", qwebirc
.ui
.AboutPane
, "aboutpane", this.uiOptions
);
284 privacyWindow: function() {
285 this.addCustomWindow("Privacy policy", qwebirc
.ui
.PrivacyPolicyPane
, "privacypolicypane", this.uiOptions
);
287 feedbackWindow: function() {
288 this.addCustomWindow("Feedback", qwebirc
.ui
.FeedbackPane
, "feedbackpane", this.uiOptions
);
290 faqWindow: function() {
291 this.addCustomWindow("FAQ", qwebirc
.ui
.FAQPane
, "faqpane", this.uiOptions
);
293 urlDispatcher: function(name
, window
) {
294 if(name
== "embedded")
295 return ["a", this.embeddedWindow
.bind(this)];
297 if(name
== "options")
298 return ["a", this.optionsWindow
.bind(this)];
300 /* doesn't really belong here */
301 if(name
== "whois") {
302 return ["span", function(nick
) {
303 this.client
.exec("/WHOIS " + nick
);
309 tabComplete: function(element
) {
310 this.tabCompleter
.tabComplete(element
);
312 resetTabComplete: function() {
313 this.tabCompleter
.reset();
317 qwebirc
.ui
.NotificationUI
= new Class({
318 Extends: qwebirc
.ui
.StandardUI
,
319 initialize: function(parentElement
, windowClass
, uiName
, options
) {
320 this.parent(parentElement
, windowClass
, uiName
, options
);
322 this.__beeper
= new qwebirc
.ui
.Beeper(this.uiOptions
);
323 this.__flasher
= new qwebirc
.ui
.Flasher(this.uiOptions
);
325 this.beep
= this.__beeper
.beep
.bind(this.__beeper
);
327 this.flash
= this.__flasher
.flash
.bind(this.__flasher
);
328 this.cancelFlash
= this.__flasher
.cancelFlash
.bind(this.__flasher
);
330 setBeepOnMention: function(value
) {
332 this.__beeper
.soundInit();
334 updateTitle: function(text
) {
335 if(this.__flasher
.updateTitle(text
))
338 focusChange: function(value
) {
340 this.__flasher
.focusChange(value
);
344 qwebirc
.ui
.NewLoginUI
= new Class({
345 Extends: qwebirc
.ui
.NotificationUI
,
346 loginBox: function(callbackfn
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
347 this.postInitialize();
349 var w
= this.newCustomWindow("Connect", true, qwebirc
.ui
.WINDOW_CONNECT
);
350 var callback = function(args
) {
355 qwebirc
.ui
.GenericLoginBox(w
.lines
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this.options
.networkName
);
359 qwebirc
.ui
.QuakeNetUI
= new Class({
360 Extends: qwebirc
.ui
.NewLoginUI
,
361 urlDispatcher: function(name
, window
) {
362 if(name
== "qwhois") {
363 return ["span", function(auth
) {
364 this.client
.exec("/MSG Q whois #" + auth
);
367 return this.parent(name
, window
);
370 if(!qwebirc
.auth
.loggedin())
372 if(confirm("Log out?")) {
373 for(var client
in this.clients
) {
374 this.clients
[client
].quit("Logged out");
378 var foo = function() { document
.location
= "/auth?logout=1"; };
384 qwebirc
.ui
.RootUI
= qwebirc
.ui
.QuakeNetUI
;