]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/mochaui.js
Add hot keys, generic activity display (requiring refactoring) and refactor the addli...
[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
13 this.inputbox.addEvent("focus", function() {
14 /* TODO: bring to top */
15 //alert(":O");
16 //alert(this.windowObject.windowEl);
17 //MochaUI.focusWindow.pass(this.windowObject.windowEl, this.windowObject);
18 //this.windowObject.focusWindow();
19 this.parentObject.selectWindow(this);
20 }.bind(this));
21
22 this.form.addEvent("submit", function(e) {
23 new Event(e).stop();
24
25 this.client.exec(this.inputbox.value);
26 this.inputbox.value = "";
27 }.bind(this));
28 //this.container.appendChild(form);
29 this.form.appendChild(this.inputbox);
30
31 var prefs = {
32 width: 800,
33 height: 400,
34 title: name,
35 footerHeight: 0,
36 toolbar: true,
37 container: $("pageWrapper"),
38 toolbarHeight: parentObject.inputHeight,
39 toolbarPosition: "bottom",
40 toolbarContent: "",
41 //toolbarURL: "",
42 toolbarLoadMethod: "html",
43 content: this.lines,
44 minimized: true,
45 addClass: "hidenewwin",
46 onFocus: function() {
47 parentObject.selectWindow(this);
48 }.bind(this),
49 onClose: function() {
50 if(type == WINDOW_CHANNEL)
51 this.client.exec("/PART " + name);
52 this.close();
53 }.bind(this)
54 };
55
56 if(type == WINDOW_STATUS)
57 prefs.closable = false;
58
59 /* HACK */
60 /* var oldIndexLevel = MochaUI.Windows.indexLevel;
61
62 var focus = false;
63 var oldfocus = MochaUI.focusWindow;
64 if(!focus) {
65 MochaUI.Windows.indexLevel = 0;
66 MochaUI.focusWindow = null;
67 }
68 */
69 var nw = new MochaUI.Window(prefs);
70
71 /*if(!focus) {
72 MochaUI.Windows.indexLevel = oldIndexLevel;
73 MochaUI.focusWindow = oldfocus;
74 }*/
75
76 /* HACK */
77 var toolbar = $(nw.options.id + "_toolbar");
78 this.titleText = $(nw.options.id + "_title");
79 this.tabText = $(nw.options.id + "_dockTabText");
80
81 /*alert(toolbar.parentNode.getStyle("background"));*/
82 /*this.inputbox.setStyle("background", toolbar.parentNode.getStyle("background"));*/
83 toolbar.appendChild(this.form);
84 this.windowObject = nw;
85
86 this.scroller = this.lines.parentNode.parentNode;
87
88 return;
89 /*
90 if(type == WINDOW_CHANNEL) {
91 this.nicklist = new Element("div");
92 this.nicklist.addClass("nicklist");
93
94 this.outerContainer.appendChild(this.nicklist);
95 }
96
97 var innerContainer = new Element("div");
98 innerContainer.addClass("innercontainer");
99 this.outerContainer.appendChild(innerContainer);
100
101 if(type == WINDOW_CHANNEL) {
102 this.topic = new Element("div");
103 this.topic.addClass("topic");
104 innerContainer.appendChild(this.topic);
105 }
106 */
107 },
108 updateNickList: function(nicks) {
109 this.parent(nicks);
110
111 return;
112 var n = this.nicklist;
113 while(n.firstChild)
114 n.removeChild(n.firstChild);
115
116 nicks.each(function(nick) {
117 var e = new Element("div");
118 n.appendChild(e);
119 e.appendChild(document.createTextNode(nick));
120 });
121 },
122 updateTopic: function(topic) {
123 this.parent(topic);
124 return;
125 var t = this.topic;
126
127 while(t.firstChild)
128 t.removeChild(t.firstChild);
129
130 Colourise(topic, t);
131 },
132 addLine: function(type, line, colour) {
133 var e = new Element("div");
134
135 if(colour) {
136 e.setStyles({"background": colour});
137 } else if(this.lastcolour) {
138 e.addClass("linestyle1");
139 } else {
140 e.addClass("linestyle2");
141 }
142 this.lastcolour = !this.lastcolour;
143
144 this.parent(type, line, colour, e, this.lines);
145 },
146 select: function() {
147 this.parent();
148
149 this.inputbox.focus();
150 },
151 setHilighted: function(state) {
152 this.parent(state);
153
154 if(state) {
155 this.titleText.setStyle("color", "#ff0000");
156 this.tabText.setStyle("background-color", "#ff0000");
157 this.tabText.setStyle("color", "#000000");
158 } else {
159 this.titleText.setStyle("color", null);
160 this.tabText.setStyle("background-color", null);
161 this.tabText.setStyle("color", null);
162 }
163 }
164 });
165
166 var 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();
181 MochaUI.Dock = new MochaUI.Dock({
182 dockPosition: "top"
183 });
184
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 });