]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/mochaui.js
Abandoning mochaui.
[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 this.form = new Element("form");
10 this.inputbox = new Element("input", {styles: {border: 0, width: "100%"}});
11 this.inputbox.addClass("input");
12 this.scrolltimeout = null;
13
14 this.inputbox.addEvent("focus", function() {
15 /* TODO: bring to top */
16 //alert(":O");
17 //alert(this.windowObject.windowEl);
18 //MochaUI.focusWindow.pass(this.windowObject.windowEl, this.windowObject);
19 //this.windowObject.focusWindow();
20 this.parentObject.selectWindow(this);
21 }.bind(this));
22
23 this.form.addEvent("submit", function(e) {
24 new Event(e).stop();
25
26 this.client.exec(this.inputbox.value);
27 this.inputbox.value = "";
28 }.bind(this));
29 //this.container.appendChild(form);
30 this.form.appendChild(this.inputbox);
31
32 var prefs = {
33 width: 800,
34 height: 400,
35 title: name,
36 footerHeight: 0,
37 toolbar: true,
38 container: $("pageWrapper"),
39 toolbarHeight: parentObject.inputHeight,
40 toolbarPosition: "bottom",
41 toolbarContent: "",
42 //toolbarURL: "",
43 toolbarLoadMethod: "html",
44 content: this.lines,
45 minimized: true,
46 addClass: "hidenewwin",
47 onFocus: function() {
48 parentObject.selectWindow(this);
49 }.bind(this),
50 onClose: function() {
51 if(type == WINDOW_CHANNEL)
52 this.client.exec("/PART " + name);
53 if($defined(this.scrolltimeout)) {
54 $clear(this.scrolltimeout);
55 this.scrolltimeout = null;
56 }
57 this.close();
58 }.bind(this)
59 };
60
61 if(type == WINDOW_STATUS)
62 prefs.closable = false;
63
64 /* HACK */
65 /* var oldIndexLevel = MochaUI.Windows.indexLevel;
66
67 var focus = false;
68 var oldfocus = MochaUI.focusWindow;
69 if(!focus) {
70 MochaUI.Windows.indexLevel = 0;
71 MochaUI.focusWindow = null;
72 }
73 */
74 var nw = new MochaUI.Window(prefs);
75
76 /*if(!focus) {
77 MochaUI.Windows.indexLevel = oldIndexLevel;
78 MochaUI.focusWindow = oldfocus;
79 }*/
80
81 /* HACK */
82 var toolbar = $(nw.options.id + "_toolbar");
83 this.titleText = $(nw.options.id + "_title");
84 this.tabText = $(nw.options.id + "_dockTabText");
85
86 /*alert(toolbar.parentNode.getStyle("background"));*/
87 /*this.inputbox.setStyle("background", toolbar.parentNode.getStyle("background"));*/
88 toolbar.appendChild(this.form);
89 this.windowObject = nw;
90
91 return;
92 /*
93 if(type == WINDOW_CHANNEL) {
94 this.nicklist = new Element("div");
95 this.nicklist.addClass("nicklist");
96
97 this.outerContainer.appendChild(this.nicklist);
98 }
99
100 var innerContainer = new Element("div");
101 innerContainer.addClass("innercontainer");
102 this.outerContainer.appendChild(innerContainer);
103
104 if(type == WINDOW_CHANNEL) {
105 this.topic = new Element("div");
106 this.topic.addClass("topic");
107 innerContainer.appendChild(this.topic);
108 }
109 */
110 },
111 updateNickList: function(nicks) {
112 this.parent(nicks);
113
114 return;
115 var n = this.nicklist;
116 while(n.firstChild)
117 n.removeChild(n.firstChild);
118
119 nicks.each(function(nick) {
120 var e = new Element("div");
121 n.appendChild(e);
122 e.appendChild(document.createTextNode(nick));
123 });
124 },
125 updateTopic: function(topic) {
126 this.parent(topic);
127 return;
128 var t = this.topic;
129
130 while(t.firstChild)
131 t.removeChild(t.firstChild);
132
133 Colourise(topic, t);
134 },
135 addLine: function(type, line, colour) {
136 this.parent(type, line, colour);
137
138 var e = new Element("div");
139
140 if(colour) {
141 e.setStyles({"background": colour});
142 } else if(this.lastcolour) {
143 e.addClass("linestyle1");
144 } else {
145 e.addClass("linestyle2");
146 }
147
148 if(type)
149 line = this.parentObject.theme.message(type, line);
150
151 Colourise(IRCTimestamp(new Date()) + " " + line, e);
152
153 this.lastcolour = !this.lastcolour;
154
155 this.__scrollbottom(false, e);
156
157 if(!this.active)
158 this.__setAlert(true);
159 },
160 __setAlert: function(state) {
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 __scrollbottom: function(timed, element) {
172 var pe = this.lines.parentNode.parentNode;
173 //alert(pe);
174 var prev = pe.getScroll();
175 var prevbottom = pe.getScrollSize().y;
176 var prevsize = pe.getSize();
177
178 /* scroll in bursts, else the browser gets really slow */
179 if(!timed) {
180 this.lines.appendChild(element);
181 if(this.scrolltimeout || (prev.y + prevsize.y == prevbottom)) {
182 if(this.scrolltimeout)
183 $clear(this.scrolltimeout);
184 this.scrolltimeout = this.__scrollbottom.delay(10, this, true);
185 }
186 } else {
187 pe.scrollTo(prev.x, pe.getScrollSize().y);
188 this.scrolltimeout = null;
189 }
190 },
191 select: function() {
192 this.parent();
193
194 this.__setAlert(false);
195
196 this.inputbox.focus();
197 }
198 });
199
200 var QMochaUI = new Class({
201 Extends: UI,
202 initialize: function(parentElement, theme) {
203 this.parent(parentElement, QMochaUIWindow, "mochaui");
204 this.theme = theme;
205 this.parentElement = parentElement;
206
207 window.addEvent("domready", function() {
208 /* determine input size */
209 var l = new Element("input", {styles: {border: 0}});
210 this.parentElement.appendChild(l);
211 this.inputHeight = l.getSize().y;
212 this.parentElement.removeChild(l);
213
214 MochaUI.Desktop = new MochaUI.Desktop();
215 MochaUI.Dock = new MochaUI.Dock({
216 dockPosition: "top"
217 });
218
219 MochaUI.Modal = new MochaUI.Modal();
220 MochaUI.options.useEffects = false;
221 }.bind(this));
222
223 window.addEvent("unload", function() {
224 if(MochaUI)
225 MochaUI.garbageCleanUp();
226 });
227 },
228 postInitialize: function() {
229 return;
230 this.tabs = new Element("div");
231 this.tabs.addClass("tabbar");
232
233 this.parentElement.appendChild(this.tabs);
234
235 this.container = new Element("div");
236 this.container.addClass("container");
237
238 this.parentElement.appendChild(this.container);
239
240 var form = new Element("form");
241 var inputbox = new Element("input");
242 inputbox.addClass("input");
243
244 form.addEvent("submit", function(e) {
245 new Event(e).stop();
246
247 this.getActiveWindow().client.exec(inputbox.value);
248 inputbox.value = "";
249 }.bind(this));
250 this.parentElement.appendChild(form);
251 form.appendChild(inputbox);
252 inputbox.focus();
253 },
254 loginBox: function(callbackfn, intialNickname, initialChannels) {
255 this.parent(function(options) {
256 this.postInitialize();
257 callbackfn(options);
258 }.bind(this), intialNickname, initialChannels);
259 }
260 });