]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/uglyui.js
Reorganise.
[irc/quakenet/qwebirc.git] / 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.exec("/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 nicks.each(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(IRCTimestamp(new Date()) + " " + line, e);
107
108 this.lastcolour = !this.lastcolour;
109
110 var prev = this.lines.getScroll();
111 var prevbottom = this.lines.getScrollSize().y;
112 var prevsize = this.lines.getSize();
113 this.lines.appendChild(e);
114
115 if(prev.y + prevsize.y == prevbottom)
116 this.lines.scrollTo(prev.x, this.lines.getScrollSize().y);
117
118 if(!this.active)
119 this.tab.setStyle("color", "red");
120 }
121 });
122
123 var UglyUI = new Class({
124 Extends: UI,
125 initialize: function(parentElement, theme) {
126 this.parent(UglyUIWindow);
127
128 this.parentElement = parentElement;
129 this.theme = theme;
130
131 this.tabs = new Element("div", {"styles": { "border": "1px solid black", "padding": "4px", "font-family": "Lucida Console" } });
132 parentElement.appendChild(this.tabs);
133
134 this.container = new Element("div", {"styles": { "border": "1px solid black", "margin": "2px 0px 0px 0px", "height": "480px" } });
135 parentElement.appendChild(this.container);
136
137 var form = new Element("form");
138 var inputbox = new Element("input", {"styles": { "width": "400px", "border": "1px solid black", "margin": "2px 0px 0px 0px"} });
139
140 form.addEvent("submit", function(e) {
141 new Event(e).stop();
142
143 this.getActiveWindow().client.exec(inputbox.value);
144 inputbox.value = "";
145 }.bind(this));
146 parentElement.appendChild(form);
147 form.appendChild(inputbox);
148 inputbox.focus();
149 }
150 });