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",
23 initialize: function(element
, ui
, options
) {
24 this.setOptions(options
);
26 window
.addEvent("domready", function() {
27 var callback = function(options
) {
28 var IRC
= new qwebirc
.irc
.IRCClient(options
, ui_
);
30 window
.onbeforeunload
= qwebirc_ui_onbeforeunload
;
31 window
.addEvent("unload", function() {
32 IRC
.quit("Page closed");
37 var ichans
= this.options
.initialChannels
;
38 var autoConnect
= false;
40 if(this.options
.searchURL
) {
41 var args
= qwebirc
.util
.parseURI(String(document
.location
));
42 this.options
.hue
= this.getHueArg(args
);
43 var url
= args
["url"];
44 var chans
, nick
= args
["nick"];
47 ichans
= this.parseIRCURL(url
);
48 if($defined(chans
) && chans
!= "")
49 canAutoConnect
= true;
51 chans
= args
["channels"];
53 var canAutoConnect
= false;
56 var cdata
= chans
.split(" ");
58 chans
= cdata
[0].split(",");
61 for(var i
=0;i
<chans
.length
;i
++) {
64 if(chans
[i
].charAt(0) != '#')
65 chans2
[i
] = "#" + chans2
[i
]
67 cdata
[0] = chans2
.join(",");
68 ichans
= cdata
.join(" ");
69 canAutoConnect
= true;
74 inick
= this.randSub(nick
);
76 if(args
["randomnick"] && args
["randomnick"] == 1)
77 inick
= this.options
.initialNickname
;
79 /* we only consider autoconnecting if the nick hasn't been supplied, or it has and it's not "" */
80 if(canAutoConnect
&& (!$defined(inick
) || ($defined(inick
) && (inick
!= "")))) {
81 var p
= args
["prompt"];
84 if(!$defined(p
) || p
== "") {
93 /* autoconnect if we have channels and nick but only if prompt != 1 */
94 if($defined(inick
) && !p
) {
96 } else if(!pdefault
&& !p
) { /* OR if prompt=0, but not prompt=(nothing) */
102 var ui_
= new ui($(element
), new qwebirc
.ui
.Theme(this.options
.theme
), this.options
);
104 var usingAutoNick
= !$defined(nick
);
105 if(usingAutoNick
&& autoConnect
)
106 inick
= this.options
.initialNickname
;
108 var details
= ui_
.loginBox(callback
, inick
, ichans
, autoConnect
, usingAutoNick
);
111 getHueArg: function(args
) {
112 var hue
= args
["hue"];
116 if(hue
> 360 || hue
< 0)
120 randSub: function(nick
) {
121 var getDigit = function() { return Math
.floor(Math
.random() * 10); }
123 return nick
.split("").map(function(v
) {
132 parseIRCURL: function(url
) {
133 if(url
.indexOf(":") == 0)
135 var schemeComponents
= url
.splitMax(":", 2);
136 if(schemeComponents
[0].toLowerCase() != "irc" && schemeComponents
[0].toLowerCase() != "ircs") {
137 alert("Bad IRC URL scheme.");
141 if(url
.indexOf("/") == 0) {
146 var pathComponents
= url
.splitMax("/", 4);
147 if(pathComponents
.length
< 4 || pathComponents
[3] == "") {
153 if(pathComponents
[3].indexOf("?") > -1) {
154 queryArgs
= qwebirc
.util
.parseURI(pathComponents
[3]);
155 args
= pathComponents
[3].splitMax("?", 2)[0];
157 args
= pathComponents
[3];
159 var parts
= args
.split(",");
161 var channel
= parts
[0];
162 if(channel
.charAt(0) != "#")
163 channel
= "#" + channel
;
165 var not_supported
= [], needkey
= false, key
;
166 for(var i
=1;i
<parts
.length
;i
++) {
167 var value
= parts
[i
];
168 if(value
== "needkey") {
171 not_supported
.push(value
);
175 if($defined(queryArgs
)) {
176 for(var key_
in queryArgs
) {
177 var value
= queryArgs
[key_
];
183 not_supported
.push(key_
);
190 key
= prompt("Please enter the password for channel " + channel
+ ":");
192 channel
= channel
+ " " + key
;
195 if(not_supported
.length
> 0)
196 alert("The following IRC URL components were not accepted: " + not_supported
.join(", ") + ".");