]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/baseui.js
Add custom URLs.
[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: {
7c633700
CP
8 appTitle: "QuakeNet Web IRC",
9 singleWindow: true
a59dc700
CP
10 },
11 initialize: function(parentElement, windowClass, uiName, options) {
12 this.setOptions(options);
13
9e769c12
CP
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);
e8db8558 20 this.firstClient = false;
9b63b053 21 this.commandhistory = new CommandHistory();
9e769c12
CP
22 },
23 newClient: function(client) {
24 this.windows[client] = {}
25 var w = this.newWindow(client, WINDOW_STATUS, "Status");
26 this.selectWindow(w);
e8db8558
CP
27 if(!this.firstClient) {
28 this.firstClient = true;
4094890f
CP
29 w.addLine("", "qwebirc v" + QWEBIRC_VERSION);
30 w.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved.");
e8db8558 31 w.addLine("", "http://webchat.quakenet.org/");
4094890f 32 w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org");
e8db8558 33 }
9e769c12
CP
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 */
a59dc700 56 document.title = window.name + " - " + this.options.appTitle;
9e769c12
CP
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];
eb9b087b 76 },
eb9b087b
CP
77 /*
78 this shouldn't be called by overriding classes!
66de775f 79 they should implement their own!
eb9b087b
CP
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 */
66de775f
CP
84 loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) {
85 GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick);
86 /*if(autoConnect) {
87 var c = initialChannels.split(",");
88 var ctext;
89
90 if(c.length > 1) {
91 var last = c.pop();
92 ctext = c.join(", ") + " and " + last;
93 } else {
94 ctext = c[0];
95 }
96
97 var nicktext;
98 if(autoNick) {
99 nicktext = "";
100 } else {
101 nicktext = " (as '" + initialNickname + "')"
102 }
103 if(confirm("Connect to IRC and join channels " + ctext + nicktext + "?"))
104 callback({"nickname": initialNickname, "autojoin": initialChannels});
105 return;
106 }
eb9b087b 107
d65fe45f 108 var nick = prompt("Nickname:", initialNickname);
eb9b087b
CP
109 if(!nick) {
110 alert("Aborted.");
111 return;
112 }
113
d65fe45f 114 var chans = prompt("Channels (seperate by comma):", initialChannels);
4656ff82 115 callback({"nickname": nick, "autojoin": chans});
66de775f 116 */
9e769c12
CP
117 }
118});
381fddfd
CP
119
120var UI = new Class({
121 Extends: BaseUI,
122 initialize: function(parentElement, windowClass, uiName, options) {
123 this.parent(parentElement, windowClass, uiName, options);
381fddfd
CP
124 window.addEvent("keydown", function(x) {
125 if(!x.alt)
126 return;
127
128 if(x.key == "a" || x.key == "A") {
424608ac 129 new Event(x).stop();
381fddfd
CP
130 for(var i=0;i<this.windowArray.length;i++) {
131 if(this.windowArray[i].hilighted) {
132 this.selectWindow(this.windowArray[i]);
133 break;
134 }
135 }
136 } else if(x.key >= '0' && x.key <= '9') {
424608ac
CP
137 new Event(x).stop();
138
381fddfd
CP
139 number = x.key - '0';
140 if(number == 0)
141 number = 10
142
143 number = number - 1;
144
145 if(number >= this.windowArray.length)
146 return;
147
148 this.selectWindow(this.windowArray[number]);
149 }
150 }.bind(this));
841a451d
CP
151 },
152 urlDispatcher: function(name) {
153 if(name == "embedded") {
154 return function() {
155 alert("embedded!");
156 };
157 }
158 return null;
159 },
381fddfd 160});