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",
34 initialize: function(element
, ui
, options
) {
35 this.setOptions(options
);
39 dynamicBaseURL: options
.dynamicBaseURL
,
40 staticBaseURL: options
.staticBaseURL
,
41 nicknameValidator: $defined(options
.nickValidation
) ? new qwebirc
.irc
.NicknameValidator(options
.nickValidation
) : new qwebirc
.irc
.DummyNicknameValidator()
44 window
.addEvent("domready", function() {
45 var callback = function(options
) {
46 var IRC
= new qwebirc
.irc
.IRCClient(options
, ui_
);
48 window
.onbeforeunload
= qwebirc_ui_onbeforeunload
;
49 window
.addEvent("unload", function() {
50 IRC
.quit("Page closed");
55 var ichans
= this.options
.initialChannels
;
56 var autoConnect
= false;
58 if(this.options
.searchURL
) {
59 var args
= qwebirc
.util
.parseURI(String(document
.location
));
60 this.options
.hue
= this.getHueArg(args
, "");
61 this.options
.saturation
= this.getSaturationArg(args
, "");
62 this.options
.lightness
= this.getLightnessArg(args
, "");
64 this.options
.thue
= this.getHueArg(args
, "t");
65 this.options
.tsaturation
= this.getSaturationArg(args
, "t");
66 this.options
.tlightness
= this.getLightnessArg(args
, "t");
68 if($defined(args
["uio"]))
69 this.options
.uiOptionsArg
= args
["uio"];
71 var url
= args
["url"];
72 var chans
, nick
= args
["nick"];
75 ichans
= this.parseIRCURL(url
);
76 if($defined(chans
) && chans
!= "")
77 canAutoConnect
= true;
79 chans
= args
["channels"];
81 var canAutoConnect
= false;
84 var cdata
= chans
.split(" ");
86 chans
= cdata
[0].split(",");
89 for(var i
=0;i
<chans
.length
;i
++) {
92 if(chans
[i
].charAt(0) != '#')
93 chans2
[i
] = "#" + chans2
[i
]
95 cdata
[0] = chans2
.join(",");
96 ichans
= cdata
.join(" ");
97 canAutoConnect
= true;
102 inick
= this.randSub(nick
);
104 if(args
["randomnick"] && args
["randomnick"] == 1)
105 inick
= this.options
.initialNickname
;
107 /* we only consider autoconnecting if the nick hasn't been supplied, or it has and it's not "" */
108 if(canAutoConnect
&& (!$defined(inick
) || ($defined(inick
) && (inick
!= "")))) {
109 var p
= args
["prompt"];
110 var pdefault
= false;
112 if(!$defined(p
) || p
== "") {
115 } else if(p
== "0") {
121 /* autoconnect if we have channels and nick but only if prompt != 1 */
122 if($defined(inick
) && !p
) {
124 } else if(!pdefault
&& !p
) { /* OR if prompt=0, but not prompt=(nothing) */
130 var ui_
= new ui($(element
), new qwebirc
.ui
.Theme(this.options
.theme
), this.options
);
132 var usingAutoNick
= !$defined(nick
);
133 if(usingAutoNick
&& autoConnect
)
134 inick
= this.options
.initialNickname
;
136 var details
= ui_
.loginBox(callback
, inick
, ichans
, autoConnect
, usingAutoNick
);
139 getHueArg: function(args
, t
) {
140 var hue
= args
[t
+ "hue"];
144 if(hue
> 360 || hue
< 0)
148 getSaturationArg: function(args
, t
) {
149 var saturation
= args
[t
+ "saturation"];
150 if(!$defined(saturation
))
152 saturation
= parseInt(saturation
);
153 if(saturation
> 100 || saturation
< -100)
157 getLightnessArg: function(args
, t
) {
158 var lightness
= args
[t
+ "lightness"];
159 if(!$defined(lightness
))
161 lightness
= parseInt(lightness
);
162 if(lightness
> 100 || lightness
< -100)
166 randSub: function(nick
) {
167 var getDigit = function() { return Math
.floor(Math
.random() * 10); }
169 return nick
.split("").map(function(v
) {
178 parseIRCURL: function(url
) {
179 if(url
.indexOf(":") == 0)
181 var schemeComponents
= url
.splitMax(":", 2);
182 if(schemeComponents
[0].toLowerCase() != "irc" && schemeComponents
[0].toLowerCase() != "ircs") {
183 alert("Bad IRC URL scheme.");
187 if(url
.indexOf("/") == 0) {
192 var pathComponents
= url
.splitMax("/", 4);
193 if(pathComponents
.length
< 4 || pathComponents
[3] == "") {
199 if(pathComponents
[3].indexOf("?") > -1) {
200 queryArgs
= qwebirc
.util
.parseURI(pathComponents
[3]);
201 args
= pathComponents
[3].splitMax("?", 2)[0];
203 args
= pathComponents
[3];
205 var parts
= args
.split(",");
207 var channel
= parts
[0];
208 if(channel
.charAt(0) != "#")
209 channel
= "#" + channel
;
211 var not_supported
= [], needkey
= false, key
;
212 for(var i
=1;i
<parts
.length
;i
++) {
213 var value
= parts
[i
];
214 if(value
== "needkey") {
217 not_supported
.push(value
);
221 if($defined(queryArgs
)) {
222 for(var key_
in queryArgs
) {
223 var value
= queryArgs
[key_
];
229 not_supported
.push(key_
);
236 key
= prompt("Please enter the password for channel " + channel
+ ":");
238 channel
= channel
+ " " + key
;
241 if(not_supported
.length
> 0)
242 alert("The following IRC URL components were not accepted: " + not_supported
.join(", ") + ".");