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
.origin
+ document
.location
.pathname
;
40 if(QWEBIRC_DEBUG
&& uri
.endsWith(".html")) {
41 var last
= uri
.lastIndexOf("/");
42 uri
= uri
.substring(0, last
+ 1);
44 if(uri
.substr(uri
.length
- 1) != "/")
50 options
.baseURL
= extractHost();
54 dynamicBaseURL: options
.dynamicBaseURL
,
55 staticBaseURL: options
.staticBaseURL
,
56 baseURL: options
.baseURL
,
57 helpURL: options
.helpURL
,
58 nicknameValidator: $defined(options
.nickValidation
) ? new qwebirc
.irc
.NicknameValidator(options
.nickValidation
) : new qwebirc
.irc
.DummyNicknameValidator()
61 window
.addEvent("domready", function() {
62 var callback = function(options
) {
63 var IRC
= new qwebirc
.irc
.IRCClient(options
, ui_
);
65 window
.onbeforeunload
= qwebirc_ui_onbeforeunload
;
66 window
.addEvent("unload", function() {
67 IRC
.quit("Page closed");
72 var ichans
= this.options
.initialChannels
;
73 var autoConnect
= false;
75 if(this.options
.searchURL
) {
76 var args
= qwebirc
.util
.parseURI(String(document
.location
));
77 this.options
.hue
= this.getHueArg(args
, "");
78 this.options
.saturation
= this.getSaturationArg(args
, "");
79 this.options
.lightness
= this.getLightnessArg(args
, "");
81 this.options
.thue
= this.getHueArg(args
, "t");
82 this.options
.tsaturation
= this.getSaturationArg(args
, "t");
83 this.options
.tlightness
= this.getLightnessArg(args
, "t");
85 if(args
.contains("uio"))
86 this.options
.uiOptionsArg
= args
.get("uio");
88 var url
= args
.get("url");
89 var chans
, nick
= args
.get("nick");
92 ichans
= this.parseIRCURL(url
);
93 if($defined(chans
) && chans
!= "")
94 canAutoConnect
= true;
96 chans
= args
.get("channels");
98 var canAutoConnect
= false;
101 var cdata
= chans
.split(" ");
103 chans
= cdata
[0].split(",");
106 for(var i
=0;i
<chans
.length
;i
++) {
107 chans2
[i
] = chans
[i
];
109 var prefix
= chans
[i
].charAt(0);
110 if(prefix
!= '#' && prefix
!= '&')
111 chans2
[i
] = "#" + chans2
[i
]
113 cdata
[0] = chans2
.join(",");
114 ichans
= cdata
.join(" ");
115 canAutoConnect
= true;
120 inick
= this.randSub(nick
);
122 if(args
.contains("randomnick") && args
.get("randomnick") == 1)
123 inick
= this.options
.initialNickname
;
125 /* we only consider autoconnecting if the nick hasn't been supplied, or it has and it's not "" */
126 if(canAutoConnect
&& (!$defined(inick
) || ($defined(inick
) && (inick
!= "")))) {
127 var p
= args
.get("prompt");
128 var pdefault
= false;
130 if(!$defined(p
) || p
== "") {
133 } else if(p
== "0") {
139 /* autoconnect if we have channels and nick but only if prompt != 1 */
140 if($defined(inick
) && !p
) {
142 } else if(!pdefault
&& !p
) { /* OR if prompt=0, but not prompt=(nothing) */
148 var ui_
= new ui($(element
), new qwebirc
.ui
.Theme(this.options
.theme
), this.options
);
150 var usingAutoNick
= !$defined(nick
);
151 if(usingAutoNick
&& autoConnect
)
152 inick
= this.options
.initialNickname
;
154 var details
= ui_
.loginBox(callback
, inick
, ichans
, autoConnect
, usingAutoNick
);
157 getHueArg: function(args
, t
) {
158 var hue
= args
.get(t
+ "hue");
162 if(hue
> 360 || hue
< 0)
166 getSaturationArg: function(args
, t
) {
167 var saturation
= args
.get(t
+ "saturation");
168 if(!$defined(saturation
))
170 saturation
= parseInt(saturation
);
171 if(saturation
> 100 || saturation
< -100)
175 getLightnessArg: function(args
, t
) {
176 var lightness
= args
.get(t
+ "lightness");
177 if(!$defined(lightness
))
179 lightness
= parseInt(lightness
);
180 if(lightness
> 100 || lightness
< -100)
184 randSub: function(nick
) {
185 var getDigit = function() { return Math
.floor(Math
.random() * 10); }
187 return nick
.split("").map(function(v
) {
196 parseIRCURL: function(url
) {
197 if(url
.indexOf(":") == 0)
199 var schemeComponents
= url
.splitMax(":", 2);
200 if(schemeComponents
[0].toLowerCase() != "irc" && schemeComponents
[0].toLowerCase() != "ircs") {
201 alert("Bad IRC URL scheme.");
205 if(url
.indexOf("/") == 0) {
210 var pathComponents
= url
.splitMax("/", 4);
211 if(pathComponents
.length
< 4 || pathComponents
[3] == "") {
217 if(pathComponents
[3].indexOf("?") > -1) {
218 queryArgs
= qwebirc
.util
.parseURI(pathComponents
[3]);
219 args
= pathComponents
[3].splitMax("?", 2)[0];
221 args
= pathComponents
[3];
223 var parts
= args
.split(",");
225 var channel
= parts
[0];
226 if(channel
.charAt(0) != "#")
227 channel
= "#" + channel
;
229 var not_supported
= [], needkey
= false, key
;
230 for(var i
=1;i
<parts
.length
;i
++) {
231 var value
= parts
[i
];
232 if(value
== "needkey") {
235 not_supported
.push(value
);
239 if($defined(queryArgs
)) {
240 queryArgs
.each(function(key_
, value
) {
245 not_supported
.push(key_
);
252 key
= prompt("Please enter the password for channel " + channel
+ ":");
254 channel
= channel
+ " " + key
;
257 if(not_supported
.length
> 0)
258 alert("The following IRC URL components were not accepted: " + not_supported
.join(", ") + ".");