]> jfr.im git - irc/quakenet/qwebirc.git/blame - static/js/ui/uglyui.js
Upgrade mootools, work on scrolling and issue with splitMax.
[irc/quakenet/qwebirc.git] / static / js / ui / uglyui.js
CommitLineData
c3efd9cc 1function UglyUI(parent, theme) {\r
4d256d41
CP
2 var self = this;\r
3 var active;\r
4 \r
b15204e3 5 var tabs = new Element("div", {"styles": { "border": "1px solid black", "padding": "4px", "font-family": "Lucida Console" } });\r
4d256d41
CP
6 parent.appendChild(tabs);\r
7 var tabhash = {};\r
8 \r
9 var window = new Element("div", {"styles": { "border": "1px solid black", "margin": "2px 0px 0px 0px", "height": "480px" } });\r
10 parent.appendChild(window);\r
11 \r
12 var form = new Element("form");\r
13 var inputbox = new Element("input", {"styles": { "width": "400px", "border": "1px solid black", "margin": "2px 0px 0px 0px"} });\r
14 \r
15 form.addEvent("submit", function(e) {\r
16 new Event(e).stop();\r
17 \r
18 self.send(inputbox.value);\r
19 inputbox.value = "";\r
20 });\r
21 parent.appendChild(form); \r
22 form.appendChild(inputbox);\r
23 inputbox.focus();\r
24\r
c3efd9cc
CP
25 this.newWindow = function(windowname, ischannel, displayname) {\r
26 var o = tabhash[windowname];\r
27 if(o)\r
28 return o;\r
29 \r
30 var container = new Element("div", { "styles": { "display": "none", "font-family": "Lucida Console" } });\r
4d256d41
CP
31 window.appendChild(container);\r
32 \r
33 var nicklist;\r
34 var topic;\r
35 \r
c3efd9cc 36 if(ischannel) {\r
4d256d41
CP
37 nicklist = new Element("div", {"styles": { "border-left": "1px solid black", "width": "125px", "float": "right", "height": "480px", "clear": "both", "overflow": "auto", "background": "white"} });\r
38 container.appendChild(nicklist);\r
39 }\r
40 \r
41 var x = new Element("div", {"styles": { "height": "480px" }});\r
42 container.appendChild(x);\r
43\r
c3efd9cc 44 if(ischannel) {\r
4d256d41
CP
45 topic = new Element("div", {"styles": { "background": "#fef", "height": "20px" } });\r
46 x.appendChild(topic); \r
47 }\r
48 \r
49 var e = new Element("div", {"styles": { "height": "460px", "overflow": "auto", "word-wrap": "break-word" }});\r
50 x.appendChild(e);\r
51\r
52 var tab = new Element("span", {"styles": { "border": "1px black solid", "padding": "2px", "cursor": "default", "margin-right": "2px", "background": "#eee", "clear": "both" } });\r
53 if(displayname) {\r
54 tab.appendText(displayname);\r
55 } else {\r
56 tab.appendText(windowname);\r
57 }\r
58 tab.addEvent("click", function() {\r
59 self.selectTab(windowname);\r
60 });\r
61 tabs.appendChild(tab);\r
62 \r
c3efd9cc 63 if(windowname != "") {\r
b15204e3 64 var tabclose = new Element("span", {"styles": { "border": "1px black solid", "margin-left": "5px", "padding": "2px", "font-size": "0.5em" } });\r
c3efd9cc
CP
65 tabclose.addEvent("click", function() {\r
66 if(ischannel)\r
b15204e3
CP
67 self.send("/PART " + windowname);\r
68\r
c3efd9cc
CP
69 self.closeWindow(windowname);\r
70 });\r
a67a945d 71 tabclose.set("text", "X");\r
c3efd9cc
CP
72 tab.appendChild(tabclose);\r
73 }\r
b15204e3 74 tabhash[windowname] = { "name": windowname, "container": container, "tab": tab, "element": e, "lastcolour": false, "nicklist": nicklist, "topic": topic, "ischannel": ischannel };\r
4d256d41 75 \r
4d256d41
CP
76 return tabhash[windowname];\r
77 }\r
78 \r
b15204e3
CP
79 this.getWindow = function(windowname) {\r
80 return tabhash[windowname];\r
81 }\r
82 \r
4d256d41
CP
83 this.updateNickList = function(windowname, nicks) {\r
84 var w = tabhash[windowname];\r
c3efd9cc
CP
85 if(!w)\r
86 return;\r
4d256d41
CP
87 var n = w.nicklist;\r
88 \r
89 while(n.firstChild)\r
90 n.removeChild(n.firstChild);\r
91\r
92 forEach(nicks, function(nick) {\r
93 var e = document.createElement("div");\r
94 n.appendChild(e);\r
95 e.appendChild(document.createTextNode(nick));\r
96 });\r
97 }\r
98 \r
99 this.updateTopic = function(windowname, topic) {\r
100 var w = tabhash[windowname];\r
c3efd9cc
CP
101 if(!w)\r
102 return;\r
103 \r
4d256d41
CP
104 var t = w.topic;\r
105 \r
106 while(t.firstChild)\r
107 t.removeChild(t.firstChild);\r
108\r
c3efd9cc 109 colourise(topic, t);\r
4d256d41
CP
110 }\r
111 \r
112 this.selectTab = function(windowname) {\r
b15204e3
CP
113 var w = tabhash[windowname];\r
114 if(!w)\r
115 return;\r
116 \r
4d256d41
CP
117 for(var i in tabhash) {\r
118 var o = tabhash[i];\r
119 o.container.setStyle("display", "none");\r
120 o.tab.setStyle("background", "#eee");\r
121 }\r
122 \r
b15204e3
CP
123 w.container.setStyle("display", "block");\r
124 w.tab.setStyle("background", "#dff");\r
125 w.tab.setStyle("color", "");\r
4d256d41
CP
126 self.active = windowname;\r
127 }\r
128 \r
b15204e3 129 this.newLine = function(windowname, type, line, colour) {\r
4d256d41 130 var window = tabhash[windowname];\r
c3efd9cc 131 if(!window) {\r
b15204e3
CP
132 if(windowname == false) {\r
133 windowname = self.active;\r
134 window = tabhash[self.active];\r
135 } else {\r
136 window = tabhash[""];\r
137 windowname = "";\r
138 }\r
c3efd9cc 139 }\r
4d256d41
CP
140 \r
141 var wx = window;\r
142 window = window.element;\r
c3efd9cc
CP
143 var c;\r
144 if(colour) {\r
145 c = colour;\r
146 } else if(wx.lastcolour) {\r
4d256d41
CP
147 c = "#efefef";\r
148 } else {\r
149 c = "#eeffff";\r
150 }\r
151 \r
152 var e = new Element("div", { "styles": { "background": c } });\r
c3efd9cc
CP
153 if(type)\r
154 line = theme.message(type, line);\r
155 \r
156 colourise(line, e);\r
4d256d41
CP
157 \r
158 wx.lastcolour = !wx.lastcolour;\r
a67a945d
CP
159\r
160 var prev = window.getScroll();\r
161 var prevbottom = window.getScrollSize().y;\r
162 var prevsize = window.getSize();\r
4d256d41
CP
163 window.appendChild(e);\r
164 \r
a67a945d
CP
165 if(prev.y + prevsize.y == prevbottom)\r
166 window.scrollTo(prev.x, window.getScrollSize().y);\r
167 \r
4d256d41
CP
168 if(windowname != self.active)\r
169 wx.tab.setStyle("color", "red");\r
170 }\r
c3efd9cc 171 \r
b15204e3
CP
172 this.getActiveWindow = function() {\r
173 return tabhash[self.active];\r
174 }\r
175 \r
c3efd9cc
CP
176 this.closeWindow = function(windowname) {\r
177 var w = tabhash[windowname];\r
178 if(!w)\r
179 return;\r
180 \r
181 window.removeChild(w.container);\r
182 tabs.removeChild(w.tab);\r
b15204e3
CP
183 \r
184 if(self.active == windowname)\r
185 self.selectTab("");\r
c3efd9cc
CP
186 \r
187 delete tabhash[windowname];\r
188 }\r
b15204e3
CP
189 \r
190 this.errorMessage = function(message) {\r
191 self.newLine(false, "", message, "red");\r
192 }\r
4d256d41 193}\r