]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/qui.js
First version of QUI.
[irc/quakenet/qwebirc.git] / js / ui / qui.js
CommitLineData
f4ae92cc
CP
1var QUIWindow = new Class({
2 Extends: UIWindow,
3
4 initialize: function(parentObject, client, type, name) {
5 this.parent(parentObject, client, type, name);
be0bd774 6
f4ae92cc
CP
7 this.tab = new Element("span");
8 this.tab.addClass("tab");
9
10 this.tab.appendText(name);
11 this.tab.addEvent("click", function() {
12 parentObject.selectWindow(this);
13 }.bind(this));
14
15 parentObject.tabs.appendChild(this.tab);
16
17 if(type != WINDOW_STATUS) {
18 tabclose = new Element("span");
19 tabclose.addClass("tabclose");
20 tabclose.addEvent("click", function(e) {
21 new Event(e).stop();
22
23 if(type == WINDOW_CHANNEL)
24 this.client.exec("/PART " + name);
25
26 this.close();
27 }.bind(this));
28 tabclose.set("text", "X");
29 this.tab.appendChild(tabclose);
30 }
be0bd774
CP
31
32 this.parentObject.reflow();
33
34 this.window = new Element("div");
35 this.window.addClass("window");
36 parentObject.container.appendChild(this.window);
37
38 this.lines = new Element("div");
39 this.lines.addClass("lines");
40 this.window.appendChild(this.lines);
41
42 var formdiv = new Element("div");
43 this.window.appendChild(formdiv);
44
45 var form = new Element("form");
46 var inputbox = new Element("input");
47 formdiv.addClass("input");
48
49 form.addEvent("submit", function(e) {
50 new Event(e).stop();
51
52 this.client.exec(inputbox.value);
53 inputbox.value = "";
54 }.bind(this));
55 formdiv.appendChild(form);
56 form.appendChild(inputbox);
57
58 var toppos = 0;
59 var rightpos = 0;
60 var bottompos = formdiv.getSize().y;
61
62 if(type == WINDOW_CHANNEL) {
63 this.nicklist = new Element("div");
64 this.nicklist.addClass("nicklist");
65 this.nicklist.setStyle("bottom", (bottompos - 1) + "px");
66
67 this.window.appendChild(this.nicklist);
68 rightpos = this.nicklist.getSize().x;
69
70 this.topic = new Element("div");
71 this.topic.addClass("topic");
72 this.topic.set("html", " ");
73 this.topic.setStyle("right", rightpos + "px");
74 this.window.appendChild(this.topic);
75
76 toppos = this.topic.getSize().y;
77 }
78
79 this.lines.setStyle("top", toppos + "px");
80 this.lines.setStyle("bottom", bottompos + "px");
81 this.lines.setStyle("right", rightpos + "px");
82 this.lines.addClass("lines");
f4ae92cc
CP
83 },
84 updateNickList: function(nicks) {
85 this.parent(nicks);
86
87 var n = this.nicklist;
88 while(n.firstChild)
89 n.removeChild(n.firstChild);
90
91 nicks.each(function(nick) {
92 var e = new Element("div");
93 n.appendChild(e);
94 e.appendChild(document.createTextNode(nick));
95 });
96 },
97 updateTopic: function(topic) {
98 this.parent(topic);
99
100 var t = this.topic;
101
102 while(t.firstChild)
103 t.removeChild(t.firstChild);
104
105 Colourise(topic, t);
106 },
107 select: function() {
108 this.parent();
109
be0bd774 110 this.window.removeClass("tab-invisible");
f4ae92cc 111 this.tab.removeClass("tab-unselected");
f4ae92cc
CP
112 this.tab.addClass("tab-selected");
113 },
114 deselect: function() {
115 this.parent();
116
be0bd774 117 this.window.addClass("tab-invisible");
f4ae92cc
CP
118 this.tab.removeClass("tab-selected");
119 this.tab.addClass("tab-unselected");
120 },
121 close: function() {
122 this.parent();
123
be0bd774 124 this.parentObject.container.removeChild(this.window);
f4ae92cc
CP
125 this.parentObject.tabs.removeChild(this.tab);
126 },
127 addLine: function(type, line, colour) {
f4ae92cc
CP
128 var e = new Element("div");
129
130 if(colour) {
131 e.setStyles({"background": colour});
132 } else if(this.lastcolour) {
133 e.addClass("linestyle1");
134 } else {
135 e.addClass("linestyle2");
136 }
f4ae92cc 137 this.lastcolour = !this.lastcolour;
be0bd774
CP
138
139 this.parent(type, line, colour, e);
140 },
141 setHilighted: function(state) {
142 this.parent(state);
f4ae92cc 143
be0bd774 144 if(state) {
f4ae92cc 145 this.tab.addClass("tab-highlighted");
be0bd774
CP
146 } else {
147 this.tab.removeClass("tab-highlighted");
148 }
f4ae92cc
CP
149 }
150});
151
152var QUI = new Class({
153 Extends: UI,
154 initialize: function(parentElement, theme) {
ba47bd8b 155 this.parent(parentElement, QUIWindow, "qui");
f4ae92cc
CP
156 this.theme = theme;
157 this.parentElement = parentElement;
158 },
be0bd774
CP
159 reflow: function() {
160 var tabheight = this.tabs.getSize().y;
161 this.container.setStyle("top", tabheight + "px");
162 },
163 postInitialize: function() {
164 this.outerContainer = new Element("div");
165 this.outerContainer.addClass("outercontainer");
166 this.parentElement.appendChild(this.outerContainer);
167
f4ae92cc
CP
168 this.tabs = new Element("div");
169 this.tabs.addClass("tabbar");
be0bd774 170 this.outerContainer.appendChild(this.tabs);
f4ae92cc 171
be0bd774
CP
172 var tester = new Element("span");
173 this.tabs.appendChild(tester);
f4ae92cc 174
be0bd774
CP
175 this.tabheight = this.tabs.getSize().y;
176 this.tabs.removeChild(tester);
177
f4ae92cc
CP
178 this.container = new Element("div");
179 this.container.addClass("container");
be0bd774 180 this.outerContainer.appendChild(this.container);
f4ae92cc
CP
181 },
182 loginBox: function(callbackfn, intialNickname, initialChannels) {
183 this.parent(function(options) {
184 this.postInitialize();
185 callbackfn(options);
186 }.bind(this), intialNickname, initialChannels);
187 }
188});