]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/mochaui.js
Rework old UI's to support custom/connect windows.
[irc/quakenet/qwebirc.git] / js / ui / mochaui.js
1 var QMochaUIWindow = new Class({
2 Extends: UIWindow,
3
4 initialize: function(parentObject, client, type, name) {
5 this.parent(parentObject, client, type, name);
6
7 this.lines = new Element("div", {styles: {overflow: "auto", "width": "90"}});
8
9 var toolbar = type != WINDOW_CUSTOM && type != WINDOW_CONNECT;
10
11 if(toolbar) {
12 this.form = new Element("form");
13 this.inputbox = new Element("input", {styles: {border: 0, width: "100%"}});
14 this.inputbox.addClass("input");
15
16 this.inputbox.addEvent("focus", function() {
17 /* TODO: bring to top */
18 //alert(":O");
19 //alert(this.windowObject.windowEl);
20 //MochaUI.focusWindow.pass(this.windowObject.windowEl, this.windowObject);
21 //this.windowObject.focusWindow();
22 this.parentObject.selectWindow(this);
23 }.bind(this));
24
25 this.form.addEvent("submit", function(e) {
26 new Event(e).stop();
27
28 this.client.exec(this.inputbox.value);
29 this.inputbox.value = "";
30 }.bind(this));
31 //this.container.appendChild(form);
32 this.form.appendChild(this.inputbox);
33 }
34
35 var prefs = {
36 width: 800,
37 height: 400,
38 title: name,
39 footerHeight: 0,
40 container: $("pageWrapper"),
41 toolbarHeight: parentObject.inputHeight,
42 toolbarPosition: "bottom",
43 toolbarContent: "",
44 //toolbarURL: "",
45 toolbarLoadMethod: "html",
46 content: this.lines,
47 minimized: true,
48 addClass: "hidenewwin",
49 onFocus: function() {
50 parentObject.selectWindow(this);
51 }.bind(this),
52 onClose: function() {
53 if(type == WINDOW_CHANNEL)
54 this.client.exec("/PART " + name);
55 this.close();
56 }.bind(this)
57 };
58
59 prefs.toolbar = toolbar;
60 prefs.closable = type != WINDOW_STATUS && type != WINDOW_CONNECT;
61
62 /* HACK */
63 /* var oldIndexLevel = MochaUI.Windows.indexLevel;
64
65 var focus = false;
66 var oldfocus = MochaUI.focusWindow;
67 if(!focus) {
68 MochaUI.Windows.indexLevel = 0;
69 MochaUI.focusWindow = null;
70 }
71 */
72 var nw = new MochaUI.Window(prefs);
73 this.window = nw;
74
75 /*if(!focus) {
76 MochaUI.Windows.indexLevel = oldIndexLevel;
77 MochaUI.focusWindow = oldfocus;
78 }*/
79
80 /* HACK */
81 if(toolbar) {
82 var toolbar = $(nw.options.id + "_toolbar");
83 toolbar.appendChild(this.form);
84 }
85 this.titleText = $(nw.options.id + "_title");
86 this.tabText = $(nw.options.id + "_dockTabText");
87
88 /*alert(toolbar.parentNode.getStyle("background"));*/
89 /*this.inputbox.setStyle("background", toolbar.parentNode.getStyle("background"));*/
90 this.windowObject = nw;
91
92 this.scroller = this.lines.parentNode.parentNode;
93
94 return;
95 /*
96 if(type == WINDOW_CHANNEL) {
97 this.nicklist = new Element("div");
98 this.nicklist.addClass("nicklist");
99
100 this.outerContainer.appendChild(this.nicklist);
101 }
102
103 var innerContainer = new Element("div");
104 innerContainer.addClass("innercontainer");
105 this.outerContainer.appendChild(innerContainer);
106
107 if(type == WINDOW_CHANNEL) {
108 this.topic = new Element("div");
109 this.topic.addClass("topic");
110 innerContainer.appendChild(this.topic);
111 }
112 */
113 },
114 updateNickList: function(nicks) {
115 this.parent(nicks);
116
117 return;
118 var n = this.nicklist;
119 while(n.firstChild)
120 n.removeChild(n.firstChild);
121
122 nicks.each(function(nick) {
123 var e = new Element("div");
124 n.appendChild(e);
125 e.appendChild(document.createTextNode(nick));
126 });
127 },
128 updateTopic: function(topic) {
129 this.parent(topic);
130 return;
131 var t = this.topic;
132
133 while(t.firstChild)
134 t.removeChild(t.firstChild);
135
136 Colourise(topic, t);
137 },
138 addLine: function(type, line, colour) {
139 var e = new Element("div");
140
141 if(colour) {
142 e.setStyles({"background": colour});
143 } else if(this.lastcolour) {
144 e.addClass("linestyle1");
145 } else {
146 e.addClass("linestyle2");
147 }
148 this.lastcolour = !this.lastcolour;
149
150 this.parent(type, line, colour, e, this.lines);
151 },
152 select: function() {
153 this.parent();
154
155 if(this.inputbox)
156 this.inputbox.focus();
157 },
158 setHilighted: function(state) {
159 this.parent(state);
160
161 if(state) {
162 this.titleText.setStyle("color", "#ff0000");
163 this.tabText.setStyle("background-color", "#ff0000");
164 this.tabText.setStyle("color", "#000000");
165 } else {
166 this.titleText.setStyle("color", null);
167 this.tabText.setStyle("background-color", null);
168 this.tabText.setStyle("color", null);
169 }
170 },
171 close: function() {
172 this.parent();
173
174 MochaUI.closeWindow(this.window.windowEl);
175 },
176 });
177
178 var QMochaUI = new Class({
179 Extends: NewLoginUI,
180 initialize: function(parentElement, theme) {
181 this.parent(parentElement, QMochaUIWindow, "mochaui");
182 this.theme = theme;
183 this.parentElement = parentElement;
184
185 window.addEvent("domready", function() {
186 /* determine input size */
187 var l = new Element("input", {styles: {border: 0}});
188 this.parentElement.appendChild(l);
189 this.inputHeight = l.getSize().y;
190 this.parentElement.removeChild(l);
191
192 MochaUI.Desktop = new MochaUI.Desktop();
193 MochaUI.Dock = new MochaUI.Dock({
194 dockPosition: "top"
195 });
196
197 MochaUI.Modal = new MochaUI.Modal();
198 MochaUI.options.useEffects = false;
199 }.bind(this));
200
201 window.addEvent("unload", function() {
202 if(MochaUI)
203 MochaUI.garbageCleanUp();
204 });
205 },
206 postInitialize: function() {
207 return;
208 this.tabs = new Element("div");
209 this.tabs.addClass("tabbar");
210
211 this.parentElement.appendChild(this.tabs);
212
213 this.container = new Element("div");
214 this.container.addClass("container");
215
216 this.parentElement.appendChild(this.container);
217
218 var form = new Element("form");
219 var inputbox = new Element("input");
220 inputbox.addClass("input");
221
222 form.addEvent("submit", function(e) {
223 new Event(e).stop();
224
225 this.getActiveWindow().client.exec(inputbox.value);
226 inputbox.value = "";
227 }.bind(this));
228 this.parentElement.appendChild(form);
229 form.appendChild(inputbox);
230 inputbox.focus();
231 }
232 });