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