]> jfr.im git - irc/quakenet/qwebirc.git/blob - static/js/ui/uglyui.js
76274bd03344895e303abe4e25d383d6f7105809
[irc/quakenet/qwebirc.git] / static / js / ui / uglyui.js
1 var UglyUIWindow = new Class({
2 Extends: UIWindow,
3
4 initialize: function(parentObject, client, type, name) {
5 this.parent(parentObject, client, type, name);
6
7 this.outerContainer = new Element("div", { "styles": { "display": "none", "font-family": "Lucida Console" } });
8 parentObject.container.appendChild(this.outerContainer);
9
10 if(type == WINDOW_CHANNEL) {
11 this.nicklist = new Element("div", {"styles": { "border-left": "1px solid black", "width": "125px", "float": "right", "height": "480px", "clear": "both", "overflow": "auto", "background": "white"} });
12 this.outerContainer.appendChild(this.nicklist);
13 }
14
15 var innerContainer = new Element("div", {"styles": { "height": "480px" }});
16 this.outerContainer.appendChild(innerContainer);
17
18 if(type == WINDOW_CHANNEL) {
19 this.topic = new Element("div", {"styles": { "background": "#fef", "height": "20px" } });
20 innerContainer.appendChild(this.topic);
21 }
22
23 this.lines = new Element("div", {"styles": { "height": "460px", "overflow": "auto", "word-wrap": "break-word" }});
24 innerContainer.appendChild(this.lines);
25
26 this.tab = new Element("span", {"styles": { "border": "1px black solid", "padding": "2px", "cursor": "default", "margin-right": "2px", "background": "#eee", "clear": "both" } });
27 this.tab.appendText(name);
28 this.tab.addEvent("click", function() {
29 parentObject.selectWindow(this);
30 }.bind(this));
31
32 parentObject.tabs.appendChild(this.tab);
33
34 if(type != WINDOW_STATUS) {
35 tabclose = new Element("span", {"styles": { "border": "1px black solid", "margin-left": "5px", "padding": "2px", "font-size": "0.5em" } });
36 tabclose.addEvent("click", function(e) {
37 new Event(e).stop();
38
39 if(type == WINDOW_CHANNEL)
40 this.client.dispatch("/PART " + name);
41
42 this.close();
43 }.bind(this));
44 tabclose.set("text", "X");
45 this.tab.appendChild(tabclose);
46 }
47 },
48 updateNickList: function(nicks) {
49 this.parent(nicks);
50
51 var n = this.nicklist;
52 while(n.firstChild)
53 n.removeChild(n.firstChild);
54
55 forEach(nicks, function(nick) {
56 var e = new Element("div");
57 n.appendChild(e);
58 e.appendChild(document.createTextNode(nick));
59 });
60 },
61 updateTopic: function(topic) {
62 this.parent(topic);
63
64 var t = this.topic;
65
66 while(t.firstChild)
67 t.removeChild(t.firstChild);
68
69 colourise(topic, t);
70 },
71 select: function() {
72 this.parent();
73
74 this.outerContainer.setStyle("display", "block");
75 this.tab.setStyle("background", "#dff");
76 this.tab.setStyle("color", "");
77 },
78 deselect: function() {
79 this.parent();
80
81 this.outerContainer.setStyle("display", "none");
82 this.tab.setStyle("background", "#eee");
83 },
84 close: function() {
85 this.parent();
86
87 this.parentObject.container.removeChild(this.outerContainer);
88 this.parentObject.tabs.removeChild(this.tab);
89 },
90 addLine: function(type, line, colour) {
91 this.parent(type, line, colour);
92
93 var c;
94 if(colour) {
95 c = colour;
96 } else if(this.lastcolour) {
97 c = "#efefef";
98 } else {
99 c = "#eeffff";
100 }
101
102 var e = new Element("div", { "styles": { "background": c } });
103 if(type)
104 line = this.parentObject.theme.message(type, line);
105
106 colourise(timestamp() + " " + line, e);
107 this.lines.appendChild(e);
108
109 this.lastcolour = !this.lastcolour;
110 }
111 });
112
113 var UglyUI = new Class({
114 Extends: UI,
115 initialize: function(parentElement, theme) {
116 this.parent(UglyUIWindow);
117
118 this.parentElement = parentElement;
119 this.theme = theme;
120
121 this.tabs = new Element("div", {"styles": { "border": "1px solid black", "padding": "4px", "font-family": "Lucida Console" } });
122 parentElement.appendChild(this.tabs);
123
124 this.container = new Element("div", {"styles": { "border": "1px solid black", "margin": "2px 0px 0px 0px", "height": "480px" } });
125 parentElement.appendChild(this.container);
126
127 var form = new Element("form");
128 var inputbox = new Element("input", {"styles": { "width": "400px", "border": "1px solid black", "margin": "2px 0px 0px 0px"} });
129
130 form.addEvent("submit", function(e) {
131 new Event(e).stop();
132
133 this.getActiveWindow().client.dispatch(inputbox.value);
134 inputbox.value = "";
135 }.bind(this));
136 parentElement.appendChild(form);
137 form.appendChild(inputbox);
138 inputbox.focus();
139 },
140 });