1 function qwebirc_ui_onbeforeunload(e
) { /* IE sucks */
2 var message
= "This action will close all active IRC connections.";
3 var e
= e
|| window
.event
;
5 e
.returnValue
= message
;
9 qwebirc
.ui
.Interface
= new Class({
10 Implements: [Options
],
12 initialNickname: "qwebirc" + Math
.ceil(Math
.random() * 100000),
14 networkName: "ExampleNetwork",
17 appTitle: "ExampleNetwork Web IRC",
28 initialize: function(element
, ui
, options
) {
29 qwebirc
.global
= {dynamicBaseURL: options
.dynamicBaseURL
, staticBaseURL: options
.staticBaseURL
}; /* HACK */
31 this.setOptions(options
);
33 window
.addEvent("domready", function() {
34 var callback = function(options
) {
35 var IRC
= new qwebirc
.irc
.IRCClient(options
, ui_
);
37 window
.onbeforeunload
= qwebirc_ui_onbeforeunload
;
38 window
.addEvent("unload", function() {
39 IRC
.quit("Page closed");
44 var ichans
= this.options
.initialChannels
;
45 var autoConnect
= false;
47 if(this.options
.searchURL
) {
48 var args
= qwebirc
.util
.parseURI(String(document
.location
));
49 this.options
.hue
= this.getHueArg(args
);
50 this.options
.saturation
= this.getSaturationArg(args
);
51 this.options
.lightness
= this.getLightnessArg(args
);
53 if($defined(args
["uio"]))
54 this.options
.uiOptionsArg
= args
["uio"];
56 var url
= args
["url"];
57 var chans
, nick
= args
["nick"];
60 ichans
= this.parseIRCURL(url
);
61 if($defined(chans
) && chans
!= "")
62 canAutoConnect
= true;
64 chans
= args
["channels"];
66 var canAutoConnect
= false;
69 var cdata
= chans
.split(" ");
71 chans
= cdata
[0].split(",");
74 for(var i
=0;i
<chans
.length
;i
++) {
77 if(chans
[i
].charAt(0) != '#')
78 chans2
[i
] = "#" + chans2
[i
]
80 cdata
[0] = chans2
.join(",");
81 ichans
= cdata
.join(" ");
82 canAutoConnect
= true;
87 inick
= this.randSub(nick
);
89 if(args
["randomnick"] && args
["randomnick"] == 1)
90 inick
= this.options
.initialNickname
;
92 /* we only consider autoconnecting if the nick hasn't been supplied, or it has and it's not "" */
93 if(canAutoConnect
&& (!$defined(inick
) || ($defined(inick
) && (inick
!= "")))) {
94 var p
= args
["prompt"];
97 if(!$defined(p
) || p
== "") {
100 } else if(p
== "0") {
106 /* autoconnect if we have channels and nick but only if prompt != 1 */
107 if($defined(inick
) && !p
) {
109 } else if(!pdefault
&& !p
) { /* OR if prompt=0, but not prompt=(nothing) */
115 var ui_
= new ui($(element
), new qwebirc
.ui
.Theme(this.options
.theme
), this.options
);
117 var usingAutoNick
= !$defined(nick
);
118 if(usingAutoNick
&& autoConnect
)
119 inick
= this.options
.initialNickname
;
121 var details
= ui_
.loginBox(callback
, inick
, ichans
, autoConnect
, usingAutoNick
);
124 getHueArg: function(args
) {
125 var hue
= args
["hue"];
129 if(hue
> 360 || hue
< 0)
133 getSaturationArg: function(args
) {
134 var saturation
= args
["saturation"];
135 if(!$defined(saturation
))
137 saturation
= parseInt(saturation
);
138 if(saturation
> 100 || saturation
< -100)
142 getLightnessArg: function(args
) {
143 var lightness
= args
["lightness"];
144 if(!$defined(lightness
))
146 lightness
= parseInt(lightness
);
147 if(lightness
> 100 || lightness
< -100)
151 randSub: function(nick
) {
152 var getDigit = function() { return Math
.floor(Math
.random() * 10); }
154 return nick
.split("").map(function(v
) {
163 parseIRCURL: function(url
) {
164 if(url
.indexOf(":") == 0)
166 var schemeComponents
= url
.splitMax(":", 2);
167 if(schemeComponents
[0].toLowerCase() != "irc" && schemeComponents
[0].toLowerCase() != "ircs") {
168 alert("Bad IRC URL scheme.");
172 if(url
.indexOf("/") == 0) {
177 var pathComponents
= url
.splitMax("/", 4);
178 if(pathComponents
.length
< 4 || pathComponents
[3] == "") {
184 if(pathComponents
[3].indexOf("?") > -1) {
185 queryArgs
= qwebirc
.util
.parseURI(pathComponents
[3]);
186 args
= pathComponents
[3].splitMax("?", 2)[0];
188 args
= pathComponents
[3];
190 var parts
= args
.split(",");
192 var channel
= parts
[0];
193 if(channel
.charAt(0) != "#")
194 channel
= "#" + channel
;
196 var not_supported
= [], needkey
= false, key
;
197 for(var i
=1;i
<parts
.length
;i
++) {
198 var value
= parts
[i
];
199 if(value
== "needkey") {
202 not_supported
.push(value
);
206 if($defined(queryArgs
)) {
207 for(var key_
in queryArgs
) {
208 var value
= queryArgs
[key_
];
214 not_supported
.push(key_
);
221 key
= prompt("Please enter the password for channel " + channel
+ ":");
223 channel
= channel
+ " " + key
;
226 if(not_supported
.length
> 0)
227 alert("The following IRC URL components were not accepted: " + not_supported
.join(", ") + ".");