]>
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 newClient: function(client
) {
28 client
.id
= this.clientId
++;
29 client
.hilightController
= new qwebirc
.ui
.HilightController(client
);
31 this.windows
[client
.id
] = {}
32 this.clients
[client
.id
] = client
;
33 var w
= this.newWindow(client
, qwebirc
.ui
.WINDOW_STATUS
, "Status");
35 if(!this.firstClient
) {
36 this.firstClient
= true;
37 w
.addLine("", "qwebirc v" + qwebirc
.VERSION
);
38 w
.addLine("", "Copyright (C) 2008-2009 Chris Porter and the qwebirc project.");
39 w
.addLine("", "http://www.qwebirc.org");
40 w
.addLine("", "Licensed under the GNU General Public License, Version 2.");
44 getClientId: function(client
) {
45 if(client
== qwebirc
.ui
.CUSTOM_CLIENT
) {
46 return qwebirc
.ui
.CUSTOM_CLIENT
;
51 getWindowIdentifier: function(client
, type
, name
) {
52 if(type
== qwebirc
.ui
.WINDOW_MESSAGES
)
54 if(type
== qwebirc
.ui
.WINDOW_STATUS
)
57 if(client
== qwebirc
.ui
.CUSTOM_CLIENT
) /* HACK */
60 return "_" + client
.toIRCLower(name
);
62 newWindow: function(client
, type
, name
) {
63 var w
= this.getWindow(client
, type
, name
);
67 var wId
= this.getWindowIdentifier(client
, type
, name
);
68 var w
= this.windows
[this.getClientId(client
)][wId
] = new this.windowClass(this, client
, type
, name
, wId
);
69 this.windowArray
.push(w
);
73 getWindow: function(client
, type
, name
) {
74 var c
= this.windows
[this.getClientId(client
)];
78 return c
[this.getWindowIdentifier(client
, type
, name
)];
80 getActiveWindow: function() {
83 getActiveIRCWindow: function(client
) {
84 if(!this.active
|| this.active
.type
== qwebirc
.ui
.WINDOW_CUSTOM
) {
85 return this.windows
[this.getClientId(client
)][this.getWindowIdentifier(client
, qwebirc
.ui
.WINDOW_STATUS
)];
90 __setActiveWindow: function(window
) {
93 selectWindow: function(window
) {
95 this.active
.deselect();
96 window
.select(); /* calls setActiveWindow */
97 this.updateTitle(window
.name
+ " - " + this.options
.appTitle
);
99 updateTitle: function(text
) {
100 document
.title
= text
;
102 nextWindow: function(direction
) {
103 if(this.windowArray
.length
== 0 || !this.active
)
109 var index
= this.windowArray
.indexOf(this.active
);
113 index
= index
+ direction
;
115 index
= this.windowArray
.length
- 1;
116 } else if(index
>= this.windowArray
.length
) {
120 this.selectWindow(this.windowArray
[index
]);
122 prevWindow: function() {
125 __closed: function(window
) {
127 this.active
= undefined;
128 if(this.windowArray
.length
== 1) {
129 this.windowArray
= [];
131 var index
= this.windowArray
.indexOf(window
);
134 } else if(index
== 0) {
135 this.selectWindow(this.windowArray
[1]);
137 this.selectWindow(this.windowArray
[index
- 1]);
142 this.windowArray
= this.windowArray
.erase(window
);
143 delete this.windows
[this.getClientId(window
.client
)][window
.identifier
];
146 this shouldn't be called by overriding classes!
147 they should implement their own!
148 some form of user input MUST be received before an
149 IRC connection is made, else users are going to get
150 tricked into getting themselves glined
152 loginBox: function(callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
153 qwebirc
.ui
.GenericLoginBox(this.parentElement
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this.options
.networkName
);
157 qwebirc
.ui
.StandardUI
= new Class({
158 Extends: qwebirc
.ui
.BaseUI
,
159 UICommands: qwebirc
.ui
.UI_COMMANDS
,
160 initialize: function(parentElement
, windowClass
, uiName
, options
) {
161 this.parent(parentElement
, windowClass
, uiName
, options
);
163 this.tabCompleter
= new qwebirc
.ui
.TabCompleterFactory(this);
164 this.uiOptions
= new qwebirc
.ui
.DefaultOptionsClass(this);
165 this.customWindows
= {};
168 if(Browser
.Engine
.trident
) {
173 document
.addEvent(ev
, this.__handleHotkey
.bind(this));
175 __handleHotkey: function(x
) {
176 if(!x
.alt
|| x
.control
) {
177 if(x
.key
== "backspace" || x
.key
== "/")
178 if(!this.getInputFocused(x
))
183 if(x
.key
== "a" || x
.key
== "A") {
185 var highestIndex
= -1;
189 for(var i
=0;i
<this.windowArray
.length
;i
++) {
190 var h
= this.windowArray
[i
].hilighted
;
196 if(highestIndex
> -1)
197 this.selectWindow(this.windowArray
[highestIndex
]);
198 } else if(x
.key
>= '0' && x
.key
<= '9') {
201 number
= x
.key
- '0';
207 if(number
>= this.windowArray
.length
)
210 this.selectWindow(this.windowArray
[number
]);
211 } else if(x
.key
== "left") {
214 } else if(x
.key
== "right") {
221 getInputFocused: function(x
) {
222 if($$("input").indexOf(x
.target
) == -1 && $$("textarea").indexOf(x
.target
) == -1)
226 newCustomWindow: function(name
, select
, type
) {
228 type
= qwebirc
.ui
.WINDOW_CUSTOM
;
230 var w
= this.newWindow(qwebirc
.ui
.CUSTOM_CLIENT
, type
, name
);
231 w
.addEvent("close", function(w
) {
232 delete this.windows
[qwebirc
.ui
.CUSTOM_CLIENT
][w
.identifier
];
236 this.selectWindow(w
);
240 addCustomWindow: function(windowName
, class_
, cssClass
, options
) {
241 if(!$defined(options
))
244 if(this.customWindows
[windowName
]) {
245 this.selectWindow(this.customWindows
[windowName
]);
249 var d
= this.newCustomWindow(windowName
, true);
250 this.customWindows
[windowName
] = d
;
252 d
.addEvent("close", function() {
253 this.customWindows
[windowName
] = null;
257 d
.lines
.addClass("qwebirc-" + cssClass
);
259 var ew
= new class_(d
.lines
, options
);
260 ew
.addEvent("close", function() {
266 embeddedWindow: function() {
267 this.addCustomWindow("Embedding wizard", qwebirc
.ui
.EmbedWizard
, "embeddedwizard", {baseURL: this.options
.baseURL
});
269 optionsWindow: function() {
270 this.addCustomWindow("Options", qwebirc
.ui
.OptionsPane
, "optionspane", this.uiOptions
);
272 aboutWindow: function() {
273 this.addCustomWindow("About", qwebirc
.ui
.AboutPane
, "aboutpane", this.uiOptions
);
275 privacyWindow: function() {
276 this.addCustomWindow("Privacy policy", qwebirc
.ui
.PrivacyPolicyPane
, "privacypolicypane", this.uiOptions
);
278 feedbackWindow: function() {
279 this.addCustomWindow("Feedback", qwebirc
.ui
.FeedbackPane
, "feedbackpane", this.uiOptions
);
281 faqWindow: function() {
282 this.addCustomWindow("FAQ", qwebirc
.ui
.FAQPane
, "faqpane", this.uiOptions
);
284 urlDispatcher: function(name
, window
) {
285 if(name
== "embedded")
286 return ["a", this.embeddedWindow
.bind(this)];
288 if(name
== "options")
289 return ["a", this.optionsWindow
.bind(this)];
291 /* doesn't really belong here */
292 if(name
== "whois") {
293 return ["span", function(nick
) {
294 this.client
.exec("/WHOIS " + nick
);
300 tabComplete: function(element
) {
301 this.tabCompleter
.tabComplete(element
);
303 resetTabComplete: function() {
304 this.tabCompleter
.reset();
308 qwebirc
.ui
.NotificationUI
= new Class({
309 Extends: qwebirc
.ui
.StandardUI
,
310 initialize: function(parentElement
, windowClass
, uiName
, options
) {
311 this.parent(parentElement
, windowClass
, uiName
, options
);
313 this.__beeper
= new qwebirc
.ui
.Beeper(this.uiOptions
);
314 this.__flasher
= new qwebirc
.ui
.Flasher(this.uiOptions
);
316 this.beep
= this.__beeper
.beep
.bind(this.__beeper
);
318 this.flash
= this.__flasher
.flash
.bind(this.__flasher
);
319 this.cancelFlash
= this.__flasher
.cancelFlash
.bind(this.__flasher
);
321 setBeepOnMention: function(value
) {
323 this.__beeper
.soundInit();
325 updateTitle: function(text
) {
326 if(this.__flasher
.updateTitle(text
))
331 qwebirc
.ui
.NewLoginUI
= new Class({
332 Extends: qwebirc
.ui
.NotificationUI
,
333 loginBox: function(callbackfn
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
334 this.postInitialize();
336 var w
= this.newCustomWindow("Connect", true, qwebirc
.ui
.WINDOW_CONNECT
);
337 var callback = function(args
) {
342 qwebirc
.ui
.GenericLoginBox(w
.lines
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this.options
.networkName
);
346 qwebirc
.ui
.QuakeNetUI
= new Class({
347 Extends: qwebirc
.ui
.NewLoginUI
,
348 urlDispatcher: function(name
, window
) {
349 if(name
== "qwhois") {
350 return ["span", function(auth
) {
351 this.client
.exec("/MSG Q whois #" + auth
);
354 return this.parent(name
, window
);
357 if(!qwebirc
.auth
.loggedin())
359 if(confirm("Log out?")) {
360 for(var client
in this.clients
) {
361 this.clients
[client
].quit("Logged out");
365 var foo = function() { document
.location
= "/auth?logout=1"; };
371 qwebirc
.ui
.RootUI
= qwebirc
.ui
.QuakeNetUI
;