]> jfr.im git - irc/quakenet/qwebirc.git/blob - static/js/ui/uglyui.js
Lots of new 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" } });
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" } });
65 tabclose.addEvent("click", function() {
66 if(ischannel)
67 self.send("PART " + windowname);
68 self.closeWindow(windowname);
69 });
70 tabclose.setText("X");
71 tab.appendChild(tabclose);
72 }
73 tabhash[windowname] = { "container": container, "tab": tab, "element": e, "lastcolour": false, "nicklist": nicklist, "topic": topic };
74
75 return tabhash[windowname];
76 }
77
78 this.updateNickList = function(windowname, nicks) {
79 var w = tabhash[windowname];
80 if(!w)
81 return;
82 var n = w.nicklist;
83
84 while(n.firstChild)
85 n.removeChild(n.firstChild);
86
87 forEach(nicks, function(nick) {
88 var e = document.createElement("div");
89 n.appendChild(e);
90 e.appendChild(document.createTextNode(nick));
91 });
92 }
93
94 this.updateTopic = function(windowname, topic) {
95 var w = tabhash[windowname];
96 if(!w)
97 return;
98
99 var t = w.topic;
100
101 while(t.firstChild)
102 t.removeChild(t.firstChild);
103
104 colourise(topic, t);
105 }
106
107 this.selectTab = function(windowname) {
108 for(var i in tabhash) {
109 var o = tabhash[i];
110 o.container.setStyle("display", "none");
111 o.tab.setStyle("background", "#eee");
112 }
113
114 tabhash[windowname].container.setStyle("display", "block");
115 tabhash[windowname].tab.setStyle("background", "#dff");
116 tabhash[windowname].tab.setStyle("color", "");
117 self.active = windowname;
118 }
119
120 this.newLine = function(windowname, type, line, colour) {
121 var window = tabhash[windowname];
122 if(!window) {
123 window = tabhash[""];
124 windowname = "";
125 }
126
127 var wx = window;
128 window = window.element;
129 var c;
130 if(colour) {
131 c = colour;
132 } else if(wx.lastcolour) {
133 c = "#efefef";
134 } else {
135 c = "#eeffff";
136 }
137
138 var e = new Element("div", { "styles": { "background": c } });
139 if(type)
140 line = theme.message(type, line);
141
142 colourise(line, e);
143
144 wx.lastcolour = !wx.lastcolour;
145 window.appendChild(e);
146
147 if(windowname != self.active)
148 wx.tab.setStyle("color", "red");
149 }
150
151 this.closeWindow = function(windowname) {
152 var w = tabhash[windowname];
153 if(!w)
154 return;
155
156 window.removeChild(w.container);
157 tabs.removeChild(w.tab);
158 self.selectTab("");
159
160 delete tabhash[windowname];
161 }
162 }