]>
Commit | Line | Data |
---|---|---|
1 | var SWMUIWindow = new Class({ | |
2 | Extends: UIWindow, | |
3 | ||
4 | initialize: function(parentObject, client, type, name) { | |
5 | this.parent(parentObject, client, type, name); | |
6 | this.contentPanel = new SWMPanel(parentObject.mainPanel.element, true); | |
7 | this.contentPanel.element.addClass("content"); | |
8 | this.contentPanel.element.setStyle("overflow", "auto"); | |
9 | ||
10 | if(type == WINDOW_CHANNEL) { | |
11 | this.nickList = new SWMPanel(this.contentPanel.element); | |
12 | this.nickList.anchor = SWM_ANCHOR_RIGHT; | |
13 | this.nickList.element.setStyle("overflow", "auto"); | |
14 | this.nickList.element.addClass("nicklist"); | |
15 | } | |
16 | ||
17 | if(type == WINDOW_CHANNEL) { | |
18 | this.topic = new SWMPanel(this.contentPanel.element); | |
19 | this.topic.anchor = SWM_ANCHOR_TOP; | |
20 | this.topic.element.addClass("topic"); | |
21 | } | |
22 | ||
23 | this.lines = new SWMPanel(this.contentPanel.element); | |
24 | this.lines.element.setStyle("overflow", "auto"); | |
25 | ||
26 | this.tab = new Element("span"); | |
27 | this.tab.addClass("tab"); | |
28 | ||
29 | this.tab.appendText(name); | |
30 | this.tab.addEvent("click", function() { | |
31 | parentObject.selectWindow(this); | |
32 | }.bind(this)); | |
33 | ||
34 | parentObject.tabPanel.element.appendChild(this.tab); | |
35 | parentObject.resize(); | |
36 | ||
37 | if(type != WINDOW_STATUS) { | |
38 | tabclose = new Element("span"); | |
39 | tabclose.addClass("tabclose"); | |
40 | tabclose.addEvent("click", function(e) { | |
41 | new Event(e).stop(); | |
42 | ||
43 | if(type == WINDOW_CHANNEL) | |
44 | this.client.exec("/PART " + name); | |
45 | ||
46 | this.close(); | |
47 | }.bind(this)); | |
48 | tabclose.set("text", "X"); | |
49 | this.tab.appendChild(tabclose); | |
50 | } | |
51 | }, | |
52 | updateNickList: function(nicks) { | |
53 | this.parent(nicks); | |
54 | ||
55 | var n = this.nickList.element; | |
56 | while(n.firstChild) | |
57 | n.removeChild(n.firstChild); | |
58 | ||
59 | nicks.each(function(nick) { | |
60 | var e = new Element("div"); | |
61 | n.appendChild(e); | |
62 | e.appendChild(document.createTextNode(nick)); | |
63 | }); | |
64 | ||
65 | this.parentObject.resize(); | |
66 | }, | |
67 | updateTopic: function(topic) { | |
68 | this.parent(topic); | |
69 | var t = this.topic.element; | |
70 | ||
71 | while(t.firstChild) | |
72 | t.removeChild(t.firstChild); | |
73 | ||
74 | Colourise(topic, t); | |
75 | ||
76 | this.parentObject.resize(); | |
77 | }, | |
78 | select: function() { | |
79 | this.parent(); | |
80 | ||
81 | this.contentPanel.setHidden(false); | |
82 | this.parentObject.resize(); | |
83 | this.tab.removeClass("tab-highlighted"); | |
84 | this.tab.removeClass("tab-unselected"); | |
85 | this.tab.addClass("tab-selected"); | |
86 | }, | |
87 | deselect: function() { | |
88 | this.parent(); | |
89 | ||
90 | this.contentPanel.setHidden(true); | |
91 | this.parentObject.resize(); | |
92 | this.tab.removeClass("tab-selected"); | |
93 | this.tab.addClass("tab-unselected"); | |
94 | }, | |
95 | close: function() { | |
96 | this.parent(); | |
97 | ||
98 | this.parentObject.mainPanel.element.removeChild(this.contentPanel.element); | |
99 | this.parentObject.tabPanel.element.removeChild(this.tab); | |
100 | }, | |
101 | addLine: function(type, line, colour) { | |
102 | this.parent(type, line, colour); | |
103 | ||
104 | var e = new Element("div"); | |
105 | ||
106 | if(colour) { | |
107 | e.addStyle("background", colour); | |
108 | } else if(this.lastcolour) { | |
109 | e.addClass("linestyle1"); | |
110 | } else { | |
111 | e.addClass("linestyle2"); | |
112 | } | |
113 | ||
114 | if(type) | |
115 | line = this.parentObject.theme.message(type, line); | |
116 | ||
117 | Colourise(IRCTimestamp(new Date()) + " " + line, e); | |
118 | ||
119 | this.lastcolour = !this.lastcolour; | |
120 | ||
121 | var prev = this.lines.element.getScroll(); | |
122 | var prevbottom = this.lines.element.getScrollSize().y; | |
123 | var prevsize = this.lines.element.getSize(); | |
124 | this.lines.element.appendChild(e); | |
125 | ||
126 | if(prev.y + prevsize.y == prevbottom) | |
127 | this.lines.element.scrollTo(prev.x, this.lines.element.getScrollSize().y); | |
128 | ||
129 | if(!this.active) | |
130 | this.tab.addClass("tab-highlighted"); | |
131 | } | |
132 | }); | |
133 | ||
134 | var SWMUI = new Class({ | |
135 | Extends: UI, | |
136 | initialize: function(parentElement, theme) { | |
137 | this.parent(parentElement, SWMUIWindow, "swmui"); | |
138 | this.theme = theme; | |
139 | ||
140 | this.tabPanel = new SWMPanel(parentElement); | |
141 | this.tabPanel.anchor = SWM_ANCHOR_TOP; | |
142 | this.tabPanel.element.addClass("tabs"); | |
143 | ||
144 | this.mainPanel = new SWMPanel(parentElement); | |
145 | this.mainPanel.element.addClass("main"); | |
146 | ||
147 | this.entryPanel = new SWMPanel(parentElement); | |
148 | this.entryPanel.anchor = SWM_ANCHOR_BOTTOM; | |
149 | this.entryPanel.element.addClass("entry"); | |
150 | ||
151 | var form = new Element("form"); | |
152 | ||
153 | var inputbox = new Element("input"); | |
154 | ||
155 | window.addEvent("resize", function() { | |
156 | var s = this.entryPanel.element.getSize().x - 4; | |
157 | inputbox.setStyle("width", s + "px"); | |
158 | }.bind(this)); | |
159 | ||
160 | form.addEvent("submit", function(e) { | |
161 | new Event(e).stop(); | |
162 | ||
163 | this.getActiveWindow().client.exec(inputbox.value); | |
164 | inputbox.value = ""; | |
165 | }.bind(this)); | |
166 | ||
167 | this.entryPanel.element.appendChild(form); | |
168 | form.appendChild(inputbox); | |
169 | inputbox.focus(); | |
170 | ||
171 | this.resize(); | |
172 | }, | |
173 | resize: function() { | |
174 | window.fireEvent("resize"); | |
175 | } | |
176 | }); |