]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/mochaui.js
Add title changing.
[irc/quakenet/qwebirc.git] / js / ui / mochaui.js
CommitLineData
cfd8616d
CP
1var 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");
a59dc700
CP
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
cfd8616d
CP
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 = {
a59dc700 33 width: 800,
cfd8616d
CP
34 height: 400,
35 title: name,
36 footerHeight: 0,
37 toolbar: true,
38 container: $("pageWrapper"),
39 toolbarHeight: parentObject.inputHeight,
40 toolbarPosition: "bottom",
41 toolbarContent: "",
a59dc700
CP
42 //toolbarURL: "",
43 toolbarLoadMethod: "html",
cfd8616d
CP
44 content: this.lines,
45 onFocus: function() {
46 parentObject.selectWindow(this);
47 }.bind(this),
48 onClose: function() {
49 if(type == WINDOW_CHANNEL)
50 this.client.exec("/PART " + name);
a59dc700
CP
51 if($defined(this.scrolltimeout)) {
52 $clear(this.scrolltimeout);
53 this.scrolltimeout = null;
54 }
cfd8616d
CP
55 this.close();
56 }.bind(this)
57 };
58
59 if(type == WINDOW_STATUS)
60 prefs.closable = false;
61
62 var nw = new MochaUI.Window(prefs);
63 /* HACK */
64 var toolbar = $(nw.options.id + "_toolbar");
a59dc700
CP
65 /*alert(toolbar.parentNode.getStyle("background"));*/
66 /*this.inputbox.setStyle("background", toolbar.parentNode.getStyle("background"));*/
cfd8616d 67 toolbar.appendChild(this.form);
a59dc700 68 this.windowObject = nw;
cfd8616d
CP
69
70 return;
71/*
72 if(type == WINDOW_CHANNEL) {
73 this.nicklist = new Element("div");
74 this.nicklist.addClass("nicklist");
75
76 this.outerContainer.appendChild(this.nicklist);
77 }
78
79 var innerContainer = new Element("div");
80 innerContainer.addClass("innercontainer");
81 this.outerContainer.appendChild(innerContainer);
82
83 if(type == WINDOW_CHANNEL) {
84 this.topic = new Element("div");
85 this.topic.addClass("topic");
86 innerContainer.appendChild(this.topic);
87 }
88 */
89 },
90 updateNickList: function(nicks) {
91 this.parent(nicks);
92
93 return;
94 var n = this.nicklist;
95 while(n.firstChild)
96 n.removeChild(n.firstChild);
97
98 nicks.each(function(nick) {
99 var e = new Element("div");
100 n.appendChild(e);
101 e.appendChild(document.createTextNode(nick));
102 });
103 },
104 updateTopic: function(topic) {
105 this.parent(topic);
106 return;
107 var t = this.topic;
108
109 while(t.firstChild)
110 t.removeChild(t.firstChild);
111
112 Colourise(topic, t);
113 },
114 addLine: function(type, line, colour) {
115 this.parent(type, line, colour);
116
117 var e = new Element("div");
118
119 if(colour) {
120 e.setStyles({"background": colour});
121 } else if(this.lastcolour) {
122 e.addClass("linestyle1");
123 } else {
124 e.addClass("linestyle2");
125 }
126
127 if(type)
128 line = this.parentObject.theme.message(type, line);
129
130 Colourise(IRCTimestamp(new Date()) + " " + line, e);
131
132 this.lastcolour = !this.lastcolour;
a59dc700
CP
133
134 this.__scrollbottom(false, e);
135 /*if(!this.active)
136 this.lines.showLoadingIcon();
137 */
138 },
139 __scrollbottom: function(timed, element) {
1e08fdf9 140 var pe = this.lines.parentNode.parentNode;
a59dc700 141 //alert(pe);
1e08fdf9
CP
142 var prev = pe.getScroll();
143 var prevbottom = pe.getScrollSize().y;
144 var prevsize = pe.getSize();
cfd8616d 145
a59dc700
CP
146 /* scroll in bursts, else the browser gets really slow */
147 if(!timed) {
148 this.lines.appendChild(element);
149 if(this.scrolltimeout || (prev.y + prevsize.y == prevbottom)) {
150 if(this.scrolltimeout)
151 $clear(this.scrolltimeout);
152 this.scrolltimeout = this.__scrollbottom.delay(10, this, true);
153 }
154 } else {
1e08fdf9 155 pe.scrollTo(prev.x, pe.getScrollSize().y);
a59dc700
CP
156 this.scrolltimeout = null;
157 }
158 },
159 select: function() {
160 this.parent();
161
162 this.inputbox.focus();
cfd8616d
CP
163 }
164});
165
166var QMochaUI = new Class({
167 Extends: UI,
168 initialize: function(parentElement, theme) {
169 this.parent(parentElement, QMochaUIWindow, "mochaui");
170 this.theme = theme;
171 this.parentElement = parentElement;
172
173 window.addEvent("domready", function() {
174 /* determine input size */
175 var l = new Element("input", {styles: {border: 0}});
176 this.parentElement.appendChild(l);
177 this.inputHeight = l.getSize().y;
178 this.parentElement.removeChild(l);
179
180 MochaUI.Desktop = new MochaUI.Desktop();
08137ae6 181 MochaUI.Dock = new MochaUI.Dock({
9131cbb0 182 dockPosition: "top"
08137ae6
CP
183 });
184
cfd8616d
CP
185 MochaUI.Modal = new MochaUI.Modal();
186 MochaUI.options.useEffects = false;
187 }.bind(this));
188
189 window.addEvent("unload", function() {
190 if(MochaUI)
191 MochaUI.garbageCleanUp();
192 });
193 },
194 postInitialize: function() {
195 return;
196 this.tabs = new Element("div");
197 this.tabs.addClass("tabbar");
198
199 this.parentElement.appendChild(this.tabs);
200
201 this.container = new Element("div");
202 this.container.addClass("container");
203
204 this.parentElement.appendChild(this.container);
205
206 var form = new Element("form");
207 var inputbox = new Element("input");
208 inputbox.addClass("input");
209
210 form.addEvent("submit", function(e) {
211 new Event(e).stop();
212
213 this.getActiveWindow().client.exec(inputbox.value);
214 inputbox.value = "";
215 }.bind(this));
216 this.parentElement.appendChild(form);
217 form.appendChild(inputbox);
218 inputbox.focus();
219 },
220 loginBox: function(callbackfn, intialNickname, initialChannels) {
221 this.parent(function(options) {
222 this.postInitialize();
223 callbackfn(options);
224 }.bind(this), intialNickname, initialChannels);
225 }
226});