]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/baseui.js
Fix scrolling and colours in mochaui.
[irc/quakenet/qwebirc.git] / js / ui / baseui.js
1 var WINDOW_STATUS = 1;
2 var WINDOW_QUERY = 2;
3 var WINDOW_CHANNEL = 3;
4
5 var UI = new Class({
6 initialize: function(parentElement, windowClass, uiName) {
7 this.windows = {};
8 this.windowArray = [];
9 this.windowClass = windowClass;
10 this.parentElement = parentElement;
11 this.parentElement.addClass("qwebirc");
12 this.parentElement.addClass("qwebirc-" + uiName);
13 this.firstClient = false;
14 },
15 newClient: function(client) {
16 this.windows[client] = {}
17 var w = this.newWindow(client, WINDOW_STATUS, "Status");
18 this.selectWindow(w);
19 if(!this.firstClient) {
20 this.firstClient = true;
21 w.addLine("", "qwebirc v" + QWEBIRC_VERSION);
22 w.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved.");
23 w.addLine("", "http://webchat.quakenet.org/");
24 w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org");
25 }
26 return w;
27 },
28 newWindow: function(client, type, name) {
29 var identifier = name;
30 if(type == WINDOW_STATUS)
31 identifier = "";
32
33 var w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier);
34 this.windowArray.push(w);
35
36 return w;
37 },
38 getActiveWindow: function() {
39 return this.active;
40 },
41 __setActiveWindow: function(window) {
42 this.active = window;
43 },
44 selectWindow: function(window) {
45 if(this.active)
46 this.active.deselect();
47 window.select(); /* calls setActiveWindow */
48 },
49 __closed: function(window) {
50 if(window.active) {
51 this.active = undefined;
52 if(this.windowArray.length == 1) {
53 this.windowArray = [];
54 } else {
55 var index = this.windowArray.indexOf(window);
56 if(index == 0) {
57 this.selectWindow(this.windowArray[1]);
58 } else {
59 this.selectWindow(this.windowArray[index - 1]);
60 }
61
62 this.windowArray = this.windowArray.erase(window);
63 }
64 }
65
66 delete this.windows[window.client][window.identifier];
67 },
68 loginBox: function(callback, initialNickname, initialChannels) {
69 /*
70 this shouldn't be called by overriding classes!
71 some form of user input MUST be received before an
72 IRC connection is made, else users are going to get
73 tricked into getting themselves glined
74 */
75
76 var nick = prompt("Nickname:", initialNickname);
77 if(!nick) {
78 alert("Aborted.");
79 return;
80 }
81
82 var chans = prompt("Channels (seperate by comma):", initialChannels);
83 callback({"nickname": nick, "autojoin": chans});
84 }
85 });