]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/mochaui.js
Fix scrolling and colours in mochaui.
[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");
12
13 this.form.addEvent("submit", function(e) {
14 new Event(e).stop();
15
16 this.client.exec(this.inputbox.value);
17 this.inputbox.value = "";
18 }.bind(this));
19 //this.container.appendChild(form);
20 this.form.appendChild(this.inputbox);
21
22 var prefs = {
23 width: 500,
24 height: 400,
25 title: name,
26 footerHeight: 0,
27 toolbar: true,
28 container: $("pageWrapper"),
29 toolbarHeight: parentObject.inputHeight,
30 toolbarPosition: "bottom",
31 toolbarContent: "",
32 content: this.lines,
33 onFocus: function() {
34 parentObject.selectWindow(this);
35 }.bind(this),
36 onClose: function() {
37 if(type == WINDOW_CHANNEL)
38 this.client.exec("/PART " + name);
39
40 this.close();
41 }.bind(this)
42 };
43
44 if(type == WINDOW_STATUS)
45 prefs.closable = false;
46
47 var nw = new MochaUI.Window(prefs);
48 /* HACK */
49 var toolbar = $(nw.options.id + "_toolbar");
50 toolbar.appendChild(this.form);
51
52 return;
53/*
54 if(type == WINDOW_CHANNEL) {
55 this.nicklist = new Element("div");
56 this.nicklist.addClass("nicklist");
57
58 this.outerContainer.appendChild(this.nicklist);
59 }
60
61 var innerContainer = new Element("div");
62 innerContainer.addClass("innercontainer");
63 this.outerContainer.appendChild(innerContainer);
64
65 if(type == WINDOW_CHANNEL) {
66 this.topic = new Element("div");
67 this.topic.addClass("topic");
68 innerContainer.appendChild(this.topic);
69 }
70 */
71 },
72 updateNickList: function(nicks) {
73 this.parent(nicks);
74
75 return;
76 var n = this.nicklist;
77 while(n.firstChild)
78 n.removeChild(n.firstChild);
79
80 nicks.each(function(nick) {
81 var e = new Element("div");
82 n.appendChild(e);
83 e.appendChild(document.createTextNode(nick));
84 });
85 },
86 updateTopic: function(topic) {
87 this.parent(topic);
88 return;
89 var t = this.topic;
90
91 while(t.firstChild)
92 t.removeChild(t.firstChild);
93
94 Colourise(topic, t);
95 },
96 addLine: function(type, line, colour) {
97 this.parent(type, line, colour);
98
99 var e = new Element("div");
100
101 if(colour) {
102 e.setStyles({"background": colour});
103 } else if(this.lastcolour) {
104 e.addClass("linestyle1");
105 } else {
106 e.addClass("linestyle2");
107 }
108
109 if(type)
110 line = this.parentObject.theme.message(type, line);
111
112 Colourise(IRCTimestamp(new Date()) + " " + line, e);
113
114 this.lastcolour = !this.lastcolour;
115
1e08fdf9
CP
116 var pe = this.lines.parentNode.parentNode;
117
118 var prev = pe.getScroll();
119 var prevbottom = pe.getScrollSize().y;
120 var prevsize = pe.getSize();
cfd8616d
CP
121 this.lines.appendChild(e);
122
1e08fdf9
CP
123 if(prev.y + prevsize.y == prevbottom)
124 pe.scrollTo(prev.x, pe.getScrollSize().y);
cfd8616d
CP
125
126 if(!this.active)
127 this.lines.showLoadingIcon();
128 }
129});
130
131var QMochaUI = new Class({
132 Extends: UI,
133 initialize: function(parentElement, theme) {
134 this.parent(parentElement, QMochaUIWindow, "mochaui");
135 this.theme = theme;
136 this.parentElement = parentElement;
137
138 window.addEvent("domready", function() {
139 /* determine input size */
140 var l = new Element("input", {styles: {border: 0}});
141 this.parentElement.appendChild(l);
142 this.inputHeight = l.getSize().y;
143 this.parentElement.removeChild(l);
144
145 MochaUI.Desktop = new MochaUI.Desktop();
08137ae6 146 MochaUI.Dock = new MochaUI.Dock({
9131cbb0 147 dockPosition: "top"
08137ae6
CP
148 });
149
cfd8616d
CP
150 MochaUI.Modal = new MochaUI.Modal();
151 MochaUI.options.useEffects = false;
152 }.bind(this));
153
154 window.addEvent("unload", function() {
155 if(MochaUI)
156 MochaUI.garbageCleanUp();
157 });
158 },
159 postInitialize: function() {
160 return;
161 this.tabs = new Element("div");
162 this.tabs.addClass("tabbar");
163
164 this.parentElement.appendChild(this.tabs);
165
166 this.container = new Element("div");
167 this.container.addClass("container");
168
169 this.parentElement.appendChild(this.container);
170
171 var form = new Element("form");
172 var inputbox = new Element("input");
173 inputbox.addClass("input");
174
175 form.addEvent("submit", function(e) {
176 new Event(e).stop();
177
178 this.getActiveWindow().client.exec(inputbox.value);
179 inputbox.value = "";
180 }.bind(this));
181 this.parentElement.appendChild(form);
182 form.appendChild(inputbox);
183 inputbox.focus();
184 },
185 loginBox: function(callbackfn, intialNickname, initialChannels) {
186 this.parent(function(options) {
187 this.postInitialize();
188 callbackfn(options);
189 }.bind(this), intialNickname, initialChannels);
190 }
191});