1 function qwebirc_ui_onbeforeunload(e
) { /* IE sucks */
2 if(qwebirc
.connected
) {
3 var message
= "This action will close all active IRC connections.";
4 var e
= e
|| window
.event
;
6 e
.returnValue
= message
;
11 qwebirc
.ui
.Interface
= new Class({
12 Implements: [Options
],
14 initialNickname: "qwebirc" + Math
.ceil(Math
.random() * 100000),
16 networkName: "ExampleNetwork",
19 appTitle: "ExampleNetwork Web IRC",
35 initialize: function(element
, ui
, options
) {
36 this.setOptions(options
);
37 var extractHost = function() {
38 var uri
= document
.location
.href
;
40 /* IE6 doesn't have document.origin ... */
41 var start
= uri
.indexOf('?');
43 uri
= uri
.substring(0, start
);
44 var start
= uri
.indexOf('#');
46 uri
= uri
.substring(0, start
);
48 if(QWEBIRC_DEBUG
&& uri
.endsWith(".html")) {
49 var last
= uri
.lastIndexOf("/");
50 uri
= uri
.substring(0, last
+ 1);
52 if(uri
.substr(uri
.length
- 1) != "/")
58 options
.baseURL
= extractHost();
62 dynamicBaseURL: options
.dynamicBaseURL
,
63 staticBaseURL: options
.staticBaseURL
,
64 baseURL: options
.baseURL
,
65 helpURL: options
.helpURL
,
66 nicknameValidator: $defined(options
.nickValidation
) ? new qwebirc
.irc
.NicknameValidator(options
.nickValidation
) : new qwebirc
.irc
.DummyNicknameValidator()
69 window
.addEvent("domready", function() {
70 var callback = function(options
) {
71 var IRC
= new qwebirc
.irc
.IRCClient(options
, ui_
);
73 window
.onbeforeunload
= qwebirc_ui_onbeforeunload
;
74 window
.addEvent("unload", function() {
75 IRC
.quit("Page closed");
80 var ichans
= this.options
.initialChannels
;
81 var autoConnect
= false;
83 if(this.options
.searchURL
) {
84 var args
= qwebirc
.util
.parseURI(String(document
.location
));
85 this.options
.hue
= this.getHueArg(args
, "");
86 this.options
.saturation
= this.getSaturationArg(args
, "");
87 this.options
.lightness
= this.getLightnessArg(args
, "");
89 this.options
.thue
= this.getHueArg(args
, "t");
90 this.options
.tsaturation
= this.getSaturationArg(args
, "t");
91 this.options
.tlightness
= this.getLightnessArg(args
, "t");
93 if(args
.contains("uio"))
94 this.options
.uiOptionsArg
= args
.get("uio");
96 var url
= args
.get("url");
97 var chans
, nick
= args
.get("nick");
100 ichans
= this.parseIRCURL(url
);
101 if($defined(chans
) && chans
!= "")
102 canAutoConnect
= true;
104 chans
= args
.get("channels");
106 var canAutoConnect
= false;
109 var cdata
= chans
.split(" ");
111 chans
= cdata
[0].split(",");
114 for(var i
=0;i
<chans
.length
;i
++) {
115 chans2
[i
] = chans
[i
];
117 var prefix
= chans
[i
].charAt(0);
118 if(prefix
!= '#' && prefix
!= '&')
119 chans2
[i
] = "#" + chans2
[i
]
121 cdata
[0] = chans2
.join(",");
122 ichans
= cdata
.join(" ");
123 canAutoConnect
= true;
128 inick
= this.randSub(nick
);
130 if(args
.contains("randomnick") && args
.get("randomnick") == 1)
131 inick
= this.options
.initialNickname
;
133 /* we only consider autoconnecting if the nick hasn't been supplied, or it has and it's not "" */
134 if(canAutoConnect
&& (!$defined(inick
) || ($defined(inick
) && (inick
!= "")))) {
135 var p
= args
.get("prompt");
136 var pdefault
= false;
138 if(!$defined(p
) || p
== "") {
141 } else if(p
== "0") {
147 /* autoconnect if we have channels and nick but only if prompt != 1 */
148 if($defined(inick
) && !p
) {
150 } else if(!pdefault
&& !p
) { /* OR if prompt=0, but not prompt=(nothing) */
156 var ui_
= new ui($(element
), new qwebirc
.ui
.Theme(this.options
.theme
), this.options
);
158 var usingAutoNick
= !$defined(nick
);
159 if(usingAutoNick
&& autoConnect
)
160 inick
= this.options
.initialNickname
;
162 var details
= ui_
.loginBox(callback
, inick
, ichans
, autoConnect
, usingAutoNick
);
165 getHueArg: function(args
, t
) {
166 var hue
= args
.get(t
+ "hue");
170 if(hue
> 360 || hue
< 0)
174 getSaturationArg: function(args
, t
) {
175 var saturation
= args
.get(t
+ "saturation");
176 if(!$defined(saturation
))
178 saturation
= parseInt(saturation
);
179 if(saturation
> 100 || saturation
< -100)
183 getLightnessArg: function(args
, t
) {
184 var lightness
= args
.get(t
+ "lightness");
185 if(!$defined(lightness
))
187 lightness
= parseInt(lightness
);
188 if(lightness
> 100 || lightness
< -100)
192 randSub: function(nick
) {
193 var getDigit = function() { return Math
.floor(Math
.random() * 10); }
195 return nick
.split("").map(function(v
) {
204 parseIRCURL: function(url
) {
205 if(url
.indexOf(":") == 0)
207 var schemeComponents
= url
.splitMax(":", 2);
208 if(schemeComponents
[0].toLowerCase() != "irc" && schemeComponents
[0].toLowerCase() != "ircs") {
209 alert("Bad IRC URL scheme.");
213 if(url
.indexOf("/") == 0) {
218 var pathComponents
= url
.splitMax("/", 4);
219 if(pathComponents
.length
< 4 || pathComponents
[3] == "") {
225 if(pathComponents
[3].indexOf("?") > -1) {
226 queryArgs
= qwebirc
.util
.parseURI(pathComponents
[3]);
227 args
= pathComponents
[3].splitMax("?", 2)[0];
229 args
= pathComponents
[3];
231 var parts
= args
.split(",");
233 var channel
= parts
[0];
234 if(channel
.charAt(0) != "#")
235 channel
= "#" + channel
;
237 var not_supported
= [], needkey
= false, key
;
238 for(var i
=1;i
<parts
.length
;i
++) {
239 var value
= parts
[i
];
240 if(value
== "needkey") {
243 not_supported
.push(value
);
247 if($defined(queryArgs
)) {
248 queryArgs
.each(function(key_
, value
) {
253 not_supported
.push(key_
);
260 key
= prompt("Please enter the password for channel " + channel
+ ":");
262 channel
= channel
+ " " + key
;
265 if(not_supported
.length
> 0)
266 alert("The following IRC URL components were not accepted: " + not_supported
.join(", ") + ".");