]>
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 this.updateTitle(window
.name
+ " - " + this.options
.appTitle
);
98 updateTitle: function(text
) {
99 document
.title
= text
;
101 nextWindow: function(direction
) {
102 if(this.windowArray
.length
== 0 || !this.active
)
108 var index
= this.windowArray
.indexOf(this.active
);
112 index
= index
+ direction
;
114 index
= this.windowArray
.length
- 1;
115 } else if(index
>= this.windowArray
.length
) {
119 this.selectWindow(this.windowArray
[index
]);
121 prevWindow: function() {
124 __closed: function(window
) {
126 this.active
= undefined;
127 if(this.windowArray
.length
== 1) {
128 this.windowArray
= [];
130 var index
= this.windowArray
.indexOf(window
);
133 } else if(index
== 0) {
134 this.selectWindow(this.windowArray
[1]);
136 this.selectWindow(this.windowArray
[index
- 1]);
141 this.windowArray
= this.windowArray
.erase(window
);
142 delete this.windows
[this.getClientId(window
.client
)][window
.identifier
];
145 this shouldn't be called by overriding classes!
146 they should implement their own!
147 some form of user input MUST be received before an
148 IRC connection is made, else users are going to get
149 tricked into getting themselves glined
151 loginBox: function(callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
152 qwebirc
.ui
.GenericLoginBox(this.parentElement
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this.options
.networkName
);
156 qwebirc
.ui
.StandardUI
= new Class({
157 Extends: qwebirc
.ui
.BaseUI
,
158 UICommands: qwebirc
.ui
.UI_COMMANDS
,
159 initialize: function(parentElement
, windowClass
, uiName
, options
) {
160 this.parent(parentElement
, windowClass
, uiName
, options
);
162 this.tabCompleter
= new qwebirc
.ui
.TabCompleterFactory(this);
163 this.uiOptions
= new qwebirc
.ui
.DefaultOptionsClass(this);
164 this.customWindows
= {};
167 if(Browser
.Engine
.trident
) {
172 document
.addEvent(ev
, this.__handleHotkey
.bind(this));
174 __handleHotkey: function(x
) {
175 if(!x
.alt
|| x
.control
) {
176 if(x
.key
== "backspace" || x
.key
== "/")
177 if(!this.getInputFocused(x
))
182 if(x
.key
== "a" || x
.key
== "A") {
184 var highestIndex
= -1;
188 for(var i
=0;i
<this.windowArray
.length
;i
++) {
189 var h
= this.windowArray
[i
].hilighted
;
195 if(highestIndex
> -1)
196 this.selectWindow(this.windowArray
[highestIndex
]);
197 } else if(x
.key
>= '0' && x
.key
<= '9') {
200 number
= x
.key
- '0';
206 if(number
>= this.windowArray
.length
)
209 this.selectWindow(this.windowArray
[number
]);
210 } else if(x
.key
== "left") {
213 } else if(x
.key
== "right") {
220 getInputFocused: function(x
) {
221 if($$("input").indexOf(x
.target
) == -1 && $$("textarea").indexOf(x
.target
) == -1)
225 newCustomWindow: function(name
, select
, type
) {
227 type
= qwebirc
.ui
.WINDOW_CUSTOM
;
229 var w
= this.newWindow(qwebirc
.ui
.CUSTOM_CLIENT
, type
, name
);
230 w
.addEvent("close", function(w
) {
231 delete this.windows
[qwebirc
.ui
.CUSTOM_CLIENT
][w
.identifier
];
235 this.selectWindow(w
);
239 addCustomWindow: function(windowName
, class_
, cssClass
, options
) {
240 if(!$defined(options
))
243 if(this.customWindows
[windowName
]) {
244 this.selectWindow(this.customWindows
[windowName
]);
248 var d
= this.newCustomWindow(windowName
, true);
249 this.customWindows
[windowName
] = d
;
251 d
.addEvent("close", function() {
252 this.customWindows
[windowName
] = null;
256 d
.lines
.addClass("qwebirc-" + cssClass
);
258 var ew
= new class_(d
.lines
, options
);
259 ew
.addEvent("close", function() {
265 embeddedWindow: function() {
266 this.addCustomWindow("Embedding wizard", qwebirc
.ui
.EmbedWizard
, "embeddedwizard", {baseURL: this.options
.baseURL
});
268 optionsWindow: function() {
269 this.addCustomWindow("Options", qwebirc
.ui
.OptionsPane
, "optionspane", this.uiOptions
);
271 aboutWindow: function() {
272 this.addCustomWindow("About", qwebirc
.ui
.AboutPane
, "aboutpane", this.uiOptions
);
274 privacyWindow: function() {
275 this.addCustomWindow("Privacy policy", qwebirc
.ui
.PrivacyPolicyPane
, "privacypolicypane", this.uiOptions
);
277 feedbackWindow: function() {
278 this.addCustomWindow("Feedback", qwebirc
.ui
.FeedbackPane
, "feedbackpane", this.uiOptions
);
280 faqWindow: function() {
281 this.addCustomWindow("FAQ", qwebirc
.ui
.FAQPane
, "faqpane", this.uiOptions
);
283 urlDispatcher: function(name
, window
) {
284 if(name
== "embedded")
285 return ["a", this.embeddedWindow
.bind(this)];
287 if(name
== "options")
288 return ["a", this.optionsWindow
.bind(this)];
290 /* doesn't really belong here */
291 if(name
== "whois") {
292 return ["span", function(nick
) {
293 this.client
.exec("/WHOIS " + nick
);
299 tabComplete: function(element
) {
300 this.tabCompleter
.tabComplete(element
);
302 resetTabComplete: function() {
303 this.tabCompleter
.reset();
307 qwebirc
.ui
.NotificationUI
= new Class({
308 Extends: qwebirc
.ui
.StandardUI
,
309 initialize: function(parentElement
, windowClass
, uiName
, options
) {
310 this.parent(parentElement
, windowClass
, uiName
, options
);
312 this.__beeper
= new qwebirc
.ui
.Beeper(this.uiOptions
);
313 this.__flasher
= new qwebirc
.ui
.Flasher(this.uiOptions
);
315 this.beep
= this.__beeper
.beep
.bind(this.__beeper
);
317 this.flash
= this.__flasher
.flash
.bind(this.__flasher
);
318 this.cancelFlash
= this.__flasher
.cancelFlash
.bind(this.__flasher
);
320 setBeepOnMention: function(value
) {
322 this.__beeper
.soundInit();
324 updateTitle: function(text
) {
325 if(this.__flasher
.updateTitle(text
))
330 qwebirc
.ui
.NewLoginUI
= new Class({
331 Extends: qwebirc
.ui
.NotificationUI
,
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
, this.options
.networkName
);
345 qwebirc
.ui
.QuakeNetUI
= new Class({
346 Extends: qwebirc
.ui
.NewLoginUI
,
347 urlDispatcher: function(name
, window
) {
348 if(name
== "qwhois") {
349 return ["span", function(auth
) {
350 this.client
.exec("/MSG Q whois #" + auth
);
353 return this.parent(name
, window
);
356 if(!qwebirc
.auth
.loggedin())
358 if(confirm("Log out?")) {
359 for(var client
in this.clients
) {
360 this.clients
[client
].quit("Logged out");
364 var foo = function() { document
.location
= "/auth?logout=1"; };
370 qwebirc
.ui
.RootUI
= qwebirc
.ui
.QuakeNetUI
;