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",
26 initialize: function(element
, ui
, options
) {
27 qwebirc
.global
= {dynamicBaseURL: options
.dynamicBaseURL
, staticBaseURL: options
.staticBaseURL
}; /* HACK */
29 this.setOptions(options
);
31 window
.addEvent("domready", function() {
32 var callback = function(options
) {
33 var IRC
= new qwebirc
.irc
.IRCClient(options
, ui_
);
35 window
.onbeforeunload
= qwebirc_ui_onbeforeunload
;
36 window
.addEvent("unload", function() {
37 IRC
.quit("Page closed");
42 var ichans
= this.options
.initialChannels
;
43 var autoConnect
= false;
45 if(this.options
.searchURL
) {
46 var args
= qwebirc
.util
.parseURI(String(document
.location
));
47 this.options
.hue
= this.getHueArg(args
);
49 if($defined(args
["uio"]))
50 this.options
.uiOptionsArg
= args
["uio"];
52 var url
= args
["url"];
53 var chans
, nick
= args
["nick"];
56 ichans
= this.parseIRCURL(url
);
57 if($defined(chans
) && chans
!= "")
58 canAutoConnect
= true;
60 chans
= args
["channels"];
62 var canAutoConnect
= false;
65 var cdata
= chans
.split(" ");
67 chans
= cdata
[0].split(",");
70 for(var i
=0;i
<chans
.length
;i
++) {
73 if(chans
[i
].charAt(0) != '#')
74 chans2
[i
] = "#" + chans2
[i
]
76 cdata
[0] = chans2
.join(",");
77 ichans
= cdata
.join(" ");
78 canAutoConnect
= true;
83 inick
= this.randSub(nick
);
85 if(args
["randomnick"] && args
["randomnick"] == 1)
86 inick
= this.options
.initialNickname
;
88 /* we only consider autoconnecting if the nick hasn't been supplied, or it has and it's not "" */
89 if(canAutoConnect
&& (!$defined(inick
) || ($defined(inick
) && (inick
!= "")))) {
90 var p
= args
["prompt"];
93 if(!$defined(p
) || p
== "") {
102 /* autoconnect if we have channels and nick but only if prompt != 1 */
103 if($defined(inick
) && !p
) {
105 } else if(!pdefault
&& !p
) { /* OR if prompt=0, but not prompt=(nothing) */
111 var ui_
= new ui($(element
), new qwebirc
.ui
.Theme(this.options
.theme
), this.options
);
113 var usingAutoNick
= !$defined(nick
);
114 if(usingAutoNick
&& autoConnect
)
115 inick
= this.options
.initialNickname
;
117 var details
= ui_
.loginBox(callback
, inick
, ichans
, autoConnect
, usingAutoNick
);
120 getHueArg: function(args
) {
121 var hue
= args
["hue"];
125 if(hue
> 360 || hue
< 0)
129 randSub: function(nick
) {
130 var getDigit = function() { return Math
.floor(Math
.random() * 10); }
132 return nick
.split("").map(function(v
) {
141 parseIRCURL: function(url
) {
142 if(url
.indexOf(":") == 0)
144 var schemeComponents
= url
.splitMax(":", 2);
145 if(schemeComponents
[0].toLowerCase() != "irc" && schemeComponents
[0].toLowerCase() != "ircs") {
146 alert("Bad IRC URL scheme.");
150 if(url
.indexOf("/") == 0) {
155 var pathComponents
= url
.splitMax("/", 4);
156 if(pathComponents
.length
< 4 || pathComponents
[3] == "") {
162 if(pathComponents
[3].indexOf("?") > -1) {
163 queryArgs
= qwebirc
.util
.parseURI(pathComponents
[3]);
164 args
= pathComponents
[3].splitMax("?", 2)[0];
166 args
= pathComponents
[3];
168 var parts
= args
.split(",");
170 var channel
= parts
[0];
171 if(channel
.charAt(0) != "#")
172 channel
= "#" + channel
;
174 var not_supported
= [], needkey
= false, key
;
175 for(var i
=1;i
<parts
.length
;i
++) {
176 var value
= parts
[i
];
177 if(value
== "needkey") {
180 not_supported
.push(value
);
184 if($defined(queryArgs
)) {
185 for(var key_
in queryArgs
) {
186 var value
= queryArgs
[key_
];
192 not_supported
.push(key_
);
199 key
= prompt("Please enter the password for channel " + channel
+ ":");
201 channel
= channel
+ " " + key
;
204 if(not_supported
.length
> 0)
205 alert("The following IRC URL components were not accepted: " + not_supported
.join(", ") + ".");