]> jfr.im git - irc/quakenet/qwebirc.git/blame_incremental - js/ui/baseui.js
Add resize scroll position saving.
[irc/quakenet/qwebirc.git] / js / ui / baseui.js
... / ...
CommitLineData
1var WINDOW_STATUS = 1;
2var WINDOW_QUERY = 2;
3var WINDOW_CHANNEL = 3;
4
5var BaseUI = new Class({
6 Implements: [Events, Options],
7 options: {
8 appTitle: "QuakeNet Web IRC",
9 singleWindow: true
10 },
11 initialize: function(parentElement, windowClass, uiName, options) {
12 this.setOptions(options);
13
14 this.windows = {};
15 this.windowArray = [];
16 this.windowClass = windowClass;
17 this.parentElement = parentElement;
18 this.parentElement.addClass("qwebirc");
19 this.parentElement.addClass("qwebirc-" + uiName);
20 this.firstClient = false;
21 this.commandhistory = new CommandHistory();
22 },
23 newClient: function(client) {
24 this.windows[client] = {}
25 var w = this.newWindow(client, WINDOW_STATUS, "Status");
26 this.selectWindow(w);
27 if(!this.firstClient) {
28 this.firstClient = true;
29 w.addLine("", "qwebirc v" + QWEBIRC_VERSION);
30 w.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved.");
31 w.addLine("", "http://webchat.quakenet.org/");
32 w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org");
33 }
34 return w;
35 },
36 newWindow: function(client, type, name) {
37 var identifier = name;
38 if(type == WINDOW_STATUS)
39 identifier = "";
40
41 var w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier);
42 this.windowArray.push(w);
43
44 return w;
45 },
46 getActiveWindow: function() {
47 return this.active;
48 },
49 __setActiveWindow: function(window) {
50 this.active = window;
51 },
52 selectWindow: function(window) {
53 if(this.active)
54 this.active.deselect();
55 window.select(); /* calls setActiveWindow */
56 document.title = window.name + " - " + this.options.appTitle;
57 },
58 __closed: function(window) {
59 if(window.active) {
60 this.active = undefined;
61 if(this.windowArray.length == 1) {
62 this.windowArray = [];
63 } else {
64 var index = this.windowArray.indexOf(window);
65 if(index == 0) {
66 this.selectWindow(this.windowArray[1]);
67 } else {
68 this.selectWindow(this.windowArray[index - 1]);
69 }
70
71 this.windowArray = this.windowArray.erase(window);
72 }
73 }
74
75 delete this.windows[window.client][window.identifier];
76 },
77 loginBox: function(callback, initialNickname, initialChannels) {
78 /*
79 this shouldn't be called by overriding classes!
80 some form of user input MUST be received before an
81 IRC connection is made, else users are going to get
82 tricked into getting themselves glined
83 */
84
85 var nick = prompt("Nickname:", initialNickname);
86 if(!nick) {
87 alert("Aborted.");
88 return;
89 }
90
91 var chans = prompt("Channels (seperate by comma):", initialChannels);
92 callback({"nickname": nick, "autojoin": chans});
93 }
94});
95
96var UI = new Class({
97 Extends: BaseUI,
98 initialize: function(parentElement, windowClass, uiName, options) {
99 this.parent(parentElement, windowClass, uiName, options);
100 window.addEvent("keydown", function(x) {
101 if(!x.alt)
102 return;
103
104 if(x.key == "a" || x.key == "A") {
105 for(var i=0;i<this.windowArray.length;i++) {
106 if(this.windowArray[i].hilighted) {
107 this.selectWindow(this.windowArray[i]);
108 break;
109 }
110 }
111 } else if(x.key >= '0' && x.key <= '9') {
112 number = x.key - '0';
113 if(number == 0)
114 number = 10
115
116 number = number - 1;
117
118 if(number >= this.windowArray.length)
119 return;
120
121 this.selectWindow(this.windowArray[number]);
122 }
123 }.bind(this));
124 }
125});