]>
Commit | Line | Data |
---|---|---|
65152b01 CP |
1 | var WINDOW_STATUS = 1; |
2 | var WINDOW_QUERY = 2; | |
3 | var WINDOW_CHANNEL = 3; | |
9e769c12 CP |
4 | |
5 | var UIWindow = new Class({ | |
6 | Implements: [Events], | |
7 | initialize: function(parentObject, client, type, name, identifier) { | |
8 | this.parentObject = parentObject; | |
9 | this.type = type; | |
10 | this.name = name; | |
11 | this.active = false; | |
12 | this.client = client; | |
13 | this.identifier = identifier; | |
14 | }, | |
15 | updateNickList: function(nicks) { | |
16 | }, | |
17 | updateTopic: function(topic) { | |
18 | }, | |
19 | close: function() { | |
20 | this.parentObject.__closed(this); | |
21 | this.fireEvent("close", this); | |
22 | }, | |
23 | select: function() { | |
24 | this.active = true; | |
25 | this.parentObject.__setActiveWindow(this); | |
26 | }, | |
27 | deselect: function() { | |
28 | this.active = false; | |
29 | }, | |
30 | addLine: function(type, line, colour) { | |
31 | }, | |
32 | errorMessage: function(message) { | |
33 | this.addLine("", message, "red"); | |
34 | } | |
35 | }); | |
36 | ||
37 | var UI = new Class({ | |
38 | initialize: function(parentElement, windowClass, uiName) { | |
39 | this.windows = {}; | |
40 | this.windowArray = []; | |
41 | this.windowClass = windowClass; | |
42 | this.parentElement = parentElement; | |
43 | this.parentElement.addClass("qwebirc"); | |
44 | this.parentElement.addClass("qwebirc-" + uiName); | |
e8db8558 | 45 | this.firstClient = false; |
9e769c12 CP |
46 | }, |
47 | newClient: function(client) { | |
48 | this.windows[client] = {} | |
49 | var w = this.newWindow(client, WINDOW_STATUS, "Status"); | |
50 | this.selectWindow(w); | |
e8db8558 CP |
51 | if(!this.firstClient) { |
52 | this.firstClient = true; | |
53 | w.addLine("", "qwebirc v" + QWEBIRC_VERSION + " -- Copyright (C) 2008 Chris Porter. All rights reserved."); | |
54 | w.addLine("", "http://webchat.quakenet.org/"); | |
55 | } | |
9e769c12 CP |
56 | return w; |
57 | }, | |
58 | newWindow: function(client, type, name) { | |
59 | var identifier = name; | |
60 | if(type == WINDOW_STATUS) | |
61 | identifier = ""; | |
62 | ||
63 | var w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier); | |
64 | this.windowArray.push(w); | |
65 | ||
66 | return w; | |
67 | }, | |
68 | getActiveWindow: function() { | |
69 | return this.active; | |
70 | }, | |
71 | __setActiveWindow: function(window) { | |
72 | this.active = window; | |
73 | }, | |
74 | selectWindow: function(window) { | |
75 | if(this.active) | |
76 | this.active.deselect(); | |
77 | window.select(); /* calls setActiveWindow */ | |
78 | }, | |
79 | __closed: function(window) { | |
80 | if(window.active) { | |
81 | this.active = undefined; | |
82 | if(this.windowArray.length == 1) { | |
83 | this.windowArray = []; | |
84 | } else { | |
85 | var index = this.windowArray.indexOf(window); | |
86 | if(index == 0) { | |
87 | this.selectWindow(this.windowArray[1]); | |
88 | } else { | |
89 | this.selectWindow(this.windowArray[index - 1]); | |
90 | } | |
91 | ||
92 | this.windowArray = this.windowArray.erase(window); | |
93 | } | |
94 | } | |
95 | ||
96 | delete this.windows[window.client][window.identifier]; | |
eb9b087b | 97 | }, |
d65fe45f | 98 | loginBox: function(callback, initialNickname, initialChannels) { |
eb9b087b CP |
99 | /* |
100 | this shouldn't be called by overriding classes! | |
101 | some form of user input MUST be received before an | |
102 | IRC connection is made, else users are going to get | |
103 | tricked into getting themselves glined | |
104 | */ | |
105 | ||
d65fe45f | 106 | var nick = prompt("Nickname:", initialNickname); |
eb9b087b CP |
107 | if(!nick) { |
108 | alert("Aborted."); | |
109 | return; | |
110 | } | |
111 | ||
d65fe45f | 112 | var chans = prompt("Channels (seperate by comma):", initialChannels); |
4656ff82 | 113 | callback({"nickname": nick, "autojoin": chans}); |
9e769c12 CP |
114 | } |
115 | }); |