]> jfr.im git - irc/quakenet/qwebirc.git/blob - static/js/ui/uglyui.js
Add command parsing and lots of other stuff...
[irc/quakenet/qwebirc.git] / static / js / ui / uglyui.js
1 function UglyUI(parent, theme) {
2 var self = this;
3 var active;
4
5 var tabs = new Element("div", {"styles": { "border": "1px solid black", "padding": "4px", "font-family": "Lucida Console" } });
6 parent.appendChild(tabs);
7 var tabhash = {};
8
9 var window = new Element("div", {"styles": { "border": "1px solid black", "margin": "2px 0px 0px 0px", "height": "480px" } });
10 parent.appendChild(window);
11
12 var form = new Element("form");
13 var inputbox = new Element("input", {"styles": { "width": "400px", "border": "1px solid black", "margin": "2px 0px 0px 0px"} });
14
15 form.addEvent("submit", function(e) {
16 new Event(e).stop();
17
18 self.send(inputbox.value);
19 inputbox.value = "";
20 });
21 parent.appendChild(form);
22 form.appendChild(inputbox);
23 inputbox.focus();
24
25 this.newWindow = function(windowname, ischannel, displayname) {
26 var o = tabhash[windowname];
27 if(o)
28 return o;
29
30 var container = new Element("div", { "styles": { "display": "none", "font-family": "Lucida Console" } });
31 window.appendChild(container);
32
33 var nicklist;
34 var topic;
35
36 if(ischannel) {
37 nicklist = new Element("div", {"styles": { "border-left": "1px solid black", "width": "125px", "float": "right", "height": "480px", "clear": "both", "overflow": "auto", "background": "white"} });
38 container.appendChild(nicklist);
39 }
40
41 var x = new Element("div", {"styles": { "height": "480px" }});
42 container.appendChild(x);
43
44 if(ischannel) {
45 topic = new Element("div", {"styles": { "background": "#fef", "height": "20px" } });
46 x.appendChild(topic);
47 }
48
49 var e = new Element("div", {"styles": { "height": "460px", "overflow": "auto", "word-wrap": "break-word" }});
50 x.appendChild(e);
51
52 var tab = new Element("span", {"styles": { "border": "1px black solid", "padding": "2px", "cursor": "default", "margin-right": "2px", "background": "#eee", "clear": "both" } });
53 if(displayname) {
54 tab.appendText(displayname);
55 } else {
56 tab.appendText(windowname);
57 }
58 tab.addEvent("click", function() {
59 self.selectTab(windowname);
60 });
61 tabs.appendChild(tab);
62
63 if(windowname != "") {
64 var tabclose = new Element("span", {"styles": { "border": "1px black solid", "margin-left": "5px", "padding": "2px", "font-size": "0.5em" } });
65 tabclose.addEvent("click", function() {
66 if(ischannel)
67 self.send("/PART " + windowname);
68
69 self.closeWindow(windowname);
70 });
71 tabclose.setText("X");
72 tab.appendChild(tabclose);
73 }
74 tabhash[windowname] = { "name": windowname, "container": container, "tab": tab, "element": e, "lastcolour": false, "nicklist": nicklist, "topic": topic, "ischannel": ischannel };
75
76 return tabhash[windowname];
77 }
78
79 this.getWindow = function(windowname) {
80 return tabhash[windowname];
81 }
82
83 this.updateNickList = function(windowname, nicks) {
84 var w = tabhash[windowname];
85 if(!w)
86 return;
87 var n = w.nicklist;
88
89 while(n.firstChild)
90 n.removeChild(n.firstChild);
91
92 forEach(nicks, function(nick) {
93 var e = document.createElement("div");
94 n.appendChild(e);
95 e.appendChild(document.createTextNode(nick));
96 });
97 }
98
99 this.updateTopic = function(windowname, topic) {
100 var w = tabhash[windowname];
101 if(!w)
102 return;
103
104 var t = w.topic;
105
106 while(t.firstChild)
107 t.removeChild(t.firstChild);
108
109 colourise(topic, t);
110 }
111
112 this.selectTab = function(windowname) {
113 var w = tabhash[windowname];
114 if(!w)
115 return;
116
117 for(var i in tabhash) {
118 var o = tabhash[i];
119 o.container.setStyle("display", "none");
120 o.tab.setStyle("background", "#eee");
121 }
122
123 w.container.setStyle("display", "block");
124 w.tab.setStyle("background", "#dff");
125 w.tab.setStyle("color", "");
126 self.active = windowname;
127 }
128
129 this.newLine = function(windowname, type, line, colour) {
130 var window = tabhash[windowname];
131 if(!window) {
132 if(windowname == false) {
133 windowname = self.active;
134 window = tabhash[self.active];
135 } else {
136 window = tabhash[""];
137 windowname = "";
138 }
139 }
140
141 var wx = window;
142 window = window.element;
143 var c;
144 if(colour) {
145 c = colour;
146 } else if(wx.lastcolour) {
147 c = "#efefef";
148 } else {
149 c = "#eeffff";
150 }
151
152 var e = new Element("div", { "styles": { "background": c } });
153 if(type)
154 line = theme.message(type, line);
155
156 colourise(line, e);
157
158 wx.lastcolour = !wx.lastcolour;
159 window.appendChild(e);
160
161 if(windowname != self.active)
162 wx.tab.setStyle("color", "red");
163 }
164
165 this.getActiveWindow = function() {
166 return tabhash[self.active];
167 }
168
169 this.closeWindow = function(windowname) {
170 var w = tabhash[windowname];
171 if(!w)
172 return;
173
174 window.removeChild(w.container);
175 tabs.removeChild(w.tab);
176
177 if(self.active == windowname)
178 self.selectTab("");
179
180 delete tabhash[windowname];
181 }
182
183 this.errorMessage = function(message) {
184 self.newLine(false, "", message, "red");
185 }
186 }