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",
25 initialize: function(element
, ui
, options
) {
26 qwebirc
.global
= {dynamicBaseURL: options
.dynamicBaseURL
, staticBaseURL: options
.staticBaseURL
}; /* HACK */
28 this.setOptions(options
);
30 window
.addEvent("domready", function() {
31 var callback = function(options
) {
32 var IRC
= new qwebirc
.irc
.IRCClient(options
, ui_
);
34 window
.onbeforeunload
= qwebirc_ui_onbeforeunload
;
35 window
.addEvent("unload", function() {
36 IRC
.quit("Page closed");
41 var ichans
= this.options
.initialChannels
;
42 var autoConnect
= false;
44 if(this.options
.searchURL
) {
45 var args
= qwebirc
.util
.parseURI(String(document
.location
));
46 this.options
.hue
= this.getHueArg(args
);
47 var url
= args
["url"];
48 var chans
, nick
= args
["nick"];
51 ichans
= this.parseIRCURL(url
);
52 if($defined(chans
) && chans
!= "")
53 canAutoConnect
= true;
55 chans
= args
["channels"];
57 var canAutoConnect
= false;
60 var cdata
= chans
.split(" ");
62 chans
= cdata
[0].split(",");
65 for(var i
=0;i
<chans
.length
;i
++) {
68 if(chans
[i
].charAt(0) != '#')
69 chans2
[i
] = "#" + chans2
[i
]
71 cdata
[0] = chans2
.join(",");
72 ichans
= cdata
.join(" ");
73 canAutoConnect
= true;
78 inick
= this.randSub(nick
);
80 if(args
["randomnick"] && args
["randomnick"] == 1)
81 inick
= this.options
.initialNickname
;
83 /* we only consider autoconnecting if the nick hasn't been supplied, or it has and it's not "" */
84 if(canAutoConnect
&& (!$defined(inick
) || ($defined(inick
) && (inick
!= "")))) {
85 var p
= args
["prompt"];
88 if(!$defined(p
) || p
== "") {
97 /* autoconnect if we have channels and nick but only if prompt != 1 */
98 if($defined(inick
) && !p
) {
100 } else if(!pdefault
&& !p
) { /* OR if prompt=0, but not prompt=(nothing) */
106 var ui_
= new ui($(element
), new qwebirc
.ui
.Theme(this.options
.theme
), this.options
);
108 var usingAutoNick
= !$defined(nick
);
109 if(usingAutoNick
&& autoConnect
)
110 inick
= this.options
.initialNickname
;
112 var details
= ui_
.loginBox(callback
, inick
, ichans
, autoConnect
, usingAutoNick
);
115 getHueArg: function(args
) {
116 var hue
= args
["hue"];
120 if(hue
> 360 || hue
< 0)
124 randSub: function(nick
) {
125 var getDigit = function() { return Math
.floor(Math
.random() * 10); }
127 return nick
.split("").map(function(v
) {
136 parseIRCURL: function(url
) {
137 if(url
.indexOf(":") == 0)
139 var schemeComponents
= url
.splitMax(":", 2);
140 if(schemeComponents
[0].toLowerCase() != "irc" && schemeComponents
[0].toLowerCase() != "ircs") {
141 alert("Bad IRC URL scheme.");
145 if(url
.indexOf("/") == 0) {
150 var pathComponents
= url
.splitMax("/", 4);
151 if(pathComponents
.length
< 4 || pathComponents
[3] == "") {
157 if(pathComponents
[3].indexOf("?") > -1) {
158 queryArgs
= qwebirc
.util
.parseURI(pathComponents
[3]);
159 args
= pathComponents
[3].splitMax("?", 2)[0];
161 args
= pathComponents
[3];
163 var parts
= args
.split(",");
165 var channel
= parts
[0];
166 if(channel
.charAt(0) != "#")
167 channel
= "#" + channel
;
169 var not_supported
= [], needkey
= false, key
;
170 for(var i
=1;i
<parts
.length
;i
++) {
171 var value
= parts
[i
];
172 if(value
== "needkey") {
175 not_supported
.push(value
);
179 if($defined(queryArgs
)) {
180 for(var key_
in queryArgs
) {
181 var value
= queryArgs
[key_
];
187 not_supported
.push(key_
);
194 key
= prompt("Please enter the password for channel " + channel
+ ":");
196 channel
= channel
+ " " + key
;
199 if(not_supported
.length
> 0)
200 alert("The following IRC URL components were not accepted: " + not_supported
.join(", ") + ".");