]>
Commit | Line | Data |
---|---|---|
1 | var WINDOW_STATUS = 1; | |
2 | var WINDOW_QUERY = 2; | |
3 | var WINDOW_CHANNEL = 3; | |
4 | var WINDOW_CUSTOM = 4; | |
5 | var WINDOW_CONNECT = 5; | |
6 | var CUSTOM_CLIENT = "custom"; | |
7 | ||
8 | var BaseUI = new Class({ | |
9 | Implements: [Events, Options], | |
10 | options: { | |
11 | appTitle: "QuakeNet Web IRC", | |
12 | singleWindow: true | |
13 | }, | |
14 | initialize: function(parentElement, windowClass, uiName, options) { | |
15 | this.setOptions(options); | |
16 | ||
17 | this.windows = {}; | |
18 | this.windows[CUSTOM_CLIENT] = {}; | |
19 | this.windowArray = []; | |
20 | this.windowClass = windowClass; | |
21 | this.parentElement = parentElement; | |
22 | this.parentElement.addClass("qwebirc"); | |
23 | this.parentElement.addClass("qwebirc-" + uiName); | |
24 | this.firstClient = false; | |
25 | this.commandhistory = new CommandHistory(); | |
26 | }, | |
27 | newClient: function(client) { | |
28 | this.windows[client] = {} | |
29 | var w = this.newWindow(client, WINDOW_STATUS, "Status"); | |
30 | this.selectWindow(w); | |
31 | if(!this.firstClient) { | |
32 | this.firstClient = true; | |
33 | w.addLine("", "qwebirc v" + QWEBIRC_VERSION); | |
34 | w.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved."); | |
35 | w.addLine("", "http://webchat.quakenet.org/"); | |
36 | w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org"); | |
37 | } | |
38 | return w; | |
39 | }, | |
40 | newWindow: function(client, type, name) { | |
41 | var identifier = name; | |
42 | if(type == WINDOW_STATUS) | |
43 | identifier = ""; | |
44 | ||
45 | var w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier); | |
46 | this.windowArray.push(w); | |
47 | ||
48 | return w; | |
49 | }, | |
50 | getActiveWindow: function() { | |
51 | return this.active; | |
52 | }, | |
53 | __setActiveWindow: function(window) { | |
54 | this.active = window; | |
55 | }, | |
56 | selectWindow: function(window) { | |
57 | if(this.active) | |
58 | this.active.deselect(); | |
59 | window.select(); /* calls setActiveWindow */ | |
60 | document.title = window.name + " - " + this.options.appTitle; | |
61 | }, | |
62 | __closed: function(window) { | |
63 | if(window.active) { | |
64 | this.active = undefined; | |
65 | if(this.windowArray.length == 1) { | |
66 | this.windowArray = []; | |
67 | } else { | |
68 | var index = this.windowArray.indexOf(window); | |
69 | if(index == -1) { | |
70 | return; | |
71 | } else if(index == 0) { | |
72 | this.selectWindow(this.windowArray[1]); | |
73 | } else { | |
74 | this.selectWindow(this.windowArray[index - 1]); | |
75 | } | |
76 | ||
77 | this.windowArray = this.windowArray.erase(window); | |
78 | } | |
79 | } | |
80 | ||
81 | delete this.windows[window.client][window.identifier]; | |
82 | }, | |
83 | /* | |
84 | this shouldn't be called by overriding classes! | |
85 | they should implement their own! | |
86 | some form of user input MUST be received before an | |
87 | IRC connection is made, else users are going to get | |
88 | tricked into getting themselves glined | |
89 | */ | |
90 | loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) { | |
91 | GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick); | |
92 | } | |
93 | }); | |
94 | ||
95 | var UI = new Class({ | |
96 | Extends: BaseUI, | |
97 | initialize: function(parentElement, windowClass, uiName, options) { | |
98 | this.parent(parentElement, windowClass, uiName, options); | |
99 | window.addEvent("keydown", function(x) { | |
100 | if(!x.alt) | |
101 | return; | |
102 | ||
103 | if(x.key == "a" || x.key == "A") { | |
104 | new Event(x).stop(); | |
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 | new Event(x).stop(); | |
113 | ||
114 | number = x.key - '0'; | |
115 | if(number == 0) | |
116 | number = 10 | |
117 | ||
118 | number = number - 1; | |
119 | ||
120 | if(number >= this.windowArray.length) | |
121 | return; | |
122 | ||
123 | this.selectWindow(this.windowArray[number]); | |
124 | } | |
125 | }.bind(this)); | |
126 | }, | |
127 | newCustomWindow: function(name, select, type) { | |
128 | if(!type) | |
129 | type = WINDOW_CUSTOM; | |
130 | ||
131 | var w = this.newWindow(CUSTOM_CLIENT, type, name); | |
132 | w.addEvent("close", function(w) { | |
133 | delete this.windows[name]; | |
134 | }.bind(this)); | |
135 | ||
136 | if(select) | |
137 | this.selectWindow(w); | |
138 | ||
139 | return w; | |
140 | }, | |
141 | embeddedWindow: function() { | |
142 | if(this.embedded) { | |
143 | this.selectWindow(this.embedded) | |
144 | return; | |
145 | } | |
146 | ||
147 | this.embedded = this.newCustomWindow("Embedding wizard", true); | |
148 | this.embedded.addEvent("close", function() { | |
149 | this.embedded = null; | |
150 | }.bind(this)); | |
151 | ||
152 | var ew = new WebmasterGuide({parent: this.embedded.lines}); | |
153 | ew.addEvent("close", function() { | |
154 | this.embedded.close(); | |
155 | }.bind(this)); | |
156 | }, | |
157 | urlDispatcher: function(name) { | |
158 | if(name == "embedded") | |
159 | return this.embeddedWindow.bind(this); | |
160 | ||
161 | return null; | |
162 | } | |
163 | }); | |
164 | ||
165 | var NewLoginUI = new Class({ | |
166 | Extends: UI, | |
167 | loginBox: function(callbackfn, initialNickname, initialChannels, autoConnect, autoNick) { | |
168 | this.postInitialize(); | |
169 | var w = this.newCustomWindow("Connect", true, WINDOW_CONNECT); | |
170 | var callback = function(args) { | |
171 | w.close(); | |
172 | callbackfn(args); | |
173 | }; | |
174 | ||
175 | GenericLoginBox(w.lines, callback, initialNickname, initialChannels, autoConnect, autoNick); | |
176 | } | |
177 | }); |