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