]>
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
.CUSTOM_CLIENT
= "custom";
8 qwebirc
.ui
.BaseUI
= new Class({
9 Implements: [Events
, Options
],
11 appTitle: "QuakeNet Web IRC",
14 initialize: function(parentElement
, windowClass
, uiName
, options
) {
15 this.setOptions(options
);
18 this.windows
[qwebirc
.ui
.CUSTOM_CLIENT
] = {};
19 this.windowArray
= [];
20 this.windowClass
= windowClass
;
21 this.parentElement
= parentElement
;
22 this.parentElement
.addClass("qwebirc");
23 this.parentElement
.addClass("qwebirc-" + uiName
);
24 this.firstClient
= false;
25 this.commandhistory
= new qwebirc
.irc
.CommandHistory();
27 newClient: function(client
) {
28 client
.hilightController
= new qwebirc
.ui
.HilightController(client
);
30 this.windows
[client
] = {}
31 var w
= this.newWindow(client
, qwebirc
.ui
.WINDOW_STATUS
, "Status");
33 if(!this.firstClient
) {
34 this.firstClient
= true;
35 w
.addLine("", "qwebirc v" + qwebirc
.VERSION
);
36 w
.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved.");
37 w
.addLine("", "http://webchat.quakenet.org/");
38 w
.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org");
42 newWindow: function(client
, type
, name
) {
43 var identifier
= name
;
44 if(type
== qwebirc
.ui
.WINDOW_STATUS
)
47 var w
= this.windows
[client
][identifier
] = new this.windowClass(this, client
, type
, name
, identifier
);
48 this.windowArray
.push(w
);
52 getActiveWindow: function() {
55 getActiveIRCWindow: function(client
) {
56 if(!this.active
|| this.active
.type
== qwebirc
.ui
.WINDOW_CUSTOM
) {
57 return this.windows
[client
][""];
62 __setActiveWindow: function(window
) {
65 selectWindow: function(window
) {
67 this.active
.deselect();
68 window
.select(); /* calls setActiveWindow */
69 document
.title
= window
.name
+ " - " + this.options
.appTitle
;
71 nextWindow: function(direction
) {
72 if(this.windowArray
.length
== 0 || !this.active
)
78 var index
= this.windowArray
.indexOf(this.active
);
82 index
= index
+ direction
;
84 index
= this.windowArray
.length
- 1;
85 } else if(index
>= this.windowArray
.length
) {
89 this.selectWindow(this.windowArray
[index
]);
91 prevWindow: function() {
94 __closed: function(window
) {
96 this.active
= undefined;
97 if(this.windowArray
.length
== 1) {
98 this.windowArray
= [];
100 var index
= this.windowArray
.indexOf(window
);
103 } else if(index
== 0) {
104 this.selectWindow(this.windowArray
[1]);
106 this.selectWindow(this.windowArray
[index
- 1]);
111 this.windowArray
= this.windowArray
.erase(window
);
112 delete this.windows
[window
.client
][window
.identifier
];
115 this shouldn't be called by overriding classes!
116 they should implement their own!
117 some form of user input MUST be received before an
118 IRC connection is made, else users are going to get
119 tricked into getting themselves glined
121 loginBox: function(callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
122 qwebirc
.ui
.GenericLoginBox(this.parentElement
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
);
126 qwebirc
.ui
.StandardUI
= new Class({
127 Extends: qwebirc
.ui
.BaseUI
,
128 initialize: function(parentElement
, windowClass
, uiName
, options
) {
129 this.parent(parentElement
, windowClass
, uiName
, options
);
131 this.tabCompleter
= new qwebirc
.ui
.TabCompleterFactory(this);
132 this.uiOptions
= new qwebirc
.ui
.DefaultOptionsClass();
133 this.customWindows
= {};
135 window
.addEvent("keydown", function(x
) {
136 if(!x
.alt
|| x
.control
)
140 if(x
.key
== "a" || x
.key
== "A") {
142 var highestIndex
= -1;
146 for(var i
=0;i
<this.windowArray
.length
;i
++) {
147 var h
= this.windowArray
[i
].hilighted
;
153 if(highestIndex
> -1)
154 this.selectWindow(this.windowArray
[highestIndex
]);
155 } else if(x
.key
>= '0' && x
.key
<= '9') {
158 number
= x
.key
- '0';
164 if(number
>= this.windowArray
.length
)
167 this.selectWindow(this.windowArray
[number
]);
168 } else if(x
.key
== "left") {
171 } else if(x
.key
== "right") {
179 newCustomWindow: function(name
, select
, type
) {
181 type
= qwebirc
.ui
.WINDOW_CUSTOM
;
183 var w
= this.newWindow(qwebirc
.ui
.CUSTOM_CLIENT
, type
, name
);
184 w
.addEvent("close", function(w
) {
185 delete this.windows
[name
];
189 this.selectWindow(w
);
193 addCustomWindow: function(windowName
, class_
, cssClass
, options
) {
194 if(!$defined(options
))
197 if(this.customWindows
[windowName
]) {
198 this.selectWindow(this.customWindows
[windowName
]);
202 var d
= this.newCustomWindow(windowName
, true);
203 this.customWindows
[windowName
] = d
;
205 d
.addEvent("close", function() {
206 this.customWindows
[windowName
] = null;
210 d
.lines
.addClass(cssClass
);
212 var ew
= new class_(d
.lines
, options
);
213 ew
.addEvent("close", function() {
217 embeddedWindow: function() {
218 this.addCustomWindow("Embedded Wizard", qwebirc
.ui
.EmbedWizard
, "embeddedwizard");
220 optionsWindow: function() {
221 this.addCustomWindow("Options", qwebirc
.ui
.OptionsPane
, "optionspane", this.uiOptions
);
223 urlDispatcher: function(name
) {
224 if(name
== "embedded")
225 return ["a", this.embeddedWindow
.bind(this)];
227 if(name
== "options")
228 return ["a", this.optionsWindow
.bind(this)];
232 tabComplete: function(element
) {
233 this.tabCompleter
.tabComplete(element
);
235 resetTabComplete: function() {
236 this.tabCompleter
.reset();
240 qwebirc
.ui
.QuakeNetUI
= new Class({
241 Extends: qwebirc
.ui
.StandardUI
,
242 urlDispatcher: function(name
, window
) {
243 if(name
== "qwhois") {
244 return ["span", function(auth
) {
245 this.client
.exec("/MSG Q whois #" + auth
);
248 if(name
== "whois") {
249 return ["span", function(nick
) {
250 this.client
.exec("/WHOIS " + nick
);
253 return this.parent(name
);
257 qwebirc
.ui
.NewLoginUI
= new Class({
258 Extends: qwebirc
.ui
.QuakeNetUI
,
259 loginBox: function(callbackfn
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
260 this.postInitialize();
262 var w
= this.newCustomWindow("Connect", true, qwebirc
.ui
.WINDOW_CONNECT
);
263 var callback = function(args
) {
268 qwebirc
.ui
.GenericLoginBox(w
.lines
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
);