]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/swmui.js
Add URL parsing for channels/nick selection.
[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) {
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 },
76 deselect: function() {
77 this.parent();
78
79 this.contentPanel.setHidden(true);
80 this.parentObject.resize();
81 this.tab.removeClass("tab-selected");
82 this.tab.addClass("tab-unselected");
83 },
84 close: function() {
85 this.parent();
86
87 this.parentObject.mainPanel.removeChild(this.contentPanel.element);
88 this.parentObject.tabPanel.removeChild(this.tab);
89 },
90 addLine: function(type, line, colour) {
91 var e = new Element("div");
92
93 if(colour) {
94 e.setStyles({"background": colour});
95 } else if(this.lastcolour) {
96 e.addClass("linestyle1");
97 } else {
98 e.addClass("linestyle2");
99 }
100
101 this.lastcolour = !this.lastcolour;
102
103 this.parent(type, line, colour, e);
104 },
105 setHilighted: function(state) {
106 this.parent(state);
107
108 if(state) {
109 this.tab.addClass("tab-highlighted");
110 } else {
111 this.tab.removeClass("tab-highlighted");
112 }
113 }
114 });
115
116 var SWMUI = new Class({
117 Extends: UI,
118 initialize: function(parentElement, theme) {
119 this.parent(parentElement, SWMUIWindow, "swmui");
120
121 this.parentElement = parentElement;
122 this.theme = theme;
123 },
124 postInitialize: function() {
125 this.rootFrame = new SWMFrame(this.parentElement);
126
127 this.tabPanel = new SWMPanel(this.rootFrame);
128 this.tabPanel.anchor = SWM_ANCHOR_TOP;
129 this.tabPanel.addClass("tabs");
130
131 this.mainPanel = new SWMPanel(this.rootFrame);
132 this.mainPanel.addClass("main");
133
134 this.entryPanel = new SWMPanel(this.rootFrame);
135 this.entryPanel.anchor = SWM_ANCHOR_BOTTOM;
136 this.entryPanel.addClass("entry");
137
138 var form = new Element("form");
139
140 var inputbox = new Element("input");
141 inputbox.setStyle("border", "0px");
142
143 window.addEvent("resize", function() {
144 var s = this.entryPanel.getInnerSize().x;
145 inputbox.setStyle("width", s + "px");
146 }.bind(this));
147
148 form.addEvent("submit", function(e) {
149 new Event(e).stop();
150
151 this.getActiveWindow().client.exec(inputbox.value);
152 inputbox.value = "";
153 }.bind(this));
154
155 this.entryPanel.appendChild(form);
156 form.appendChild(inputbox);
157 inputbox.focus();
158
159 this.resize();
160 },
161 resize: function() {
162 window.fireEvent("resize");
163 },
164 loginBox: function(callback, initialNickname, initialChannels, autoConnect) {
165 this.parent(function(options) {
166 this.postInitialize();
167 callbackfn(options);
168 }.bind(this), intialNickname, initialChannels, autoConnect);
169 }
170 });