]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/baseui.js
Add hot keys, generic activity display (requiring refactoring) and refactor the addli...
[irc/quakenet/qwebirc.git] / js / ui / baseui.js
CommitLineData
65152b01
CP
1var WINDOW_STATUS = 1;
2var WINDOW_QUERY = 2;
3var WINDOW_CHANNEL = 3;
9e769c12 4
381fddfd 5var BaseUI = new Class({
a59dc700
CP
6 Implements: [Events, Options],
7 options: {
8 appTitle: "QuakeNet Web IRC",
9 },
10 initialize: function(parentElement, windowClass, uiName, options) {
11 this.setOptions(options);
12
9e769c12
CP
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);
e8db8558 19 this.firstClient = false;
9e769c12
CP
20 },
21 newClient: function(client) {
22 this.windows[client] = {}
23 var w = this.newWindow(client, WINDOW_STATUS, "Status");
24 this.selectWindow(w);
e8db8558
CP
25 if(!this.firstClient) {
26 this.firstClient = true;
4094890f
CP
27 w.addLine("", "qwebirc v" + QWEBIRC_VERSION);
28 w.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved.");
e8db8558 29 w.addLine("", "http://webchat.quakenet.org/");
4094890f 30 w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org");
e8db8558 31 }
9e769c12
CP
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 */
a59dc700 54 document.title = window.name + " - " + this.options.appTitle;
9e769c12
CP
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];
eb9b087b 74 },
d65fe45f 75 loginBox: function(callback, initialNickname, initialChannels) {
eb9b087b
CP
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
d65fe45f 83 var nick = prompt("Nickname:", initialNickname);
eb9b087b
CP
84 if(!nick) {
85 alert("Aborted.");
86 return;
87 }
88
d65fe45f 89 var chans = prompt("Channels (seperate by comma):", initialChannels);
4656ff82 90 callback({"nickname": nick, "autojoin": chans});
9e769c12
CP
91 }
92});
381fddfd
CP
93
94var UI = new Class({
95 Extends: BaseUI,
96 initialize: function(parentElement, windowClass, uiName, options) {
97 this.parent(parentElement, windowClass, uiName, options);
98
99 window.addEvent("keydown", function(x) {
100 if(!x.alt)
101 return;
102
103 if(x.key == "a" || x.key == "A") {
104 for(var i=0;i<this.windowArray.length;i++) {
105 if(this.windowArray[i].hilighted) {
106 this.selectWindow(this.windowArray[i]);
107 break;
108 }
109 }
110 } else if(x.key >= '0' && x.key <= '9') {
111 number = x.key - '0';
112 if(number == 0)
113 number = 10
114
115 number = number - 1;
116
117 if(number >= this.windowArray.length)
118 return;
119
120 this.selectWindow(this.windowArray[number]);
121 }
122 }.bind(this));
123 }
124});