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",
35 accountWhoisCommand: null
37 initialize: function(element
, ui
, options
) {
38 this.setOptions(options
);
39 var extractHost = function() {
40 var uri
= document
.location
.href
;
42 /* IE6 doesn't have document.origin ... */
43 var start
= uri
.indexOf('?');
45 uri
= uri
.substring(0, start
);
46 var start
= uri
.indexOf('#');
48 uri
= uri
.substring(0, start
);
50 if(QWEBIRC_DEBUG
&& uri
.endsWith(".html")) {
51 var last
= uri
.lastIndexOf("/");
52 uri
= uri
.substring(0, last
+ 1);
54 if(uri
.substr(uri
.length
- 1) != "/")
60 options
.baseURL
= extractHost();
64 dynamicBaseURL: options
.dynamicBaseURL
,
65 staticBaseURL: options
.staticBaseURL
,
66 baseURL: options
.baseURL
,
67 nicknameValidator: $defined(options
.nickValidation
) ? new qwebirc
.irc
.NicknameValidator(options
.nickValidation
) : new qwebirc
.irc
.DummyNicknameValidator()
70 window
.addEvent("domready", function() {
71 var callback = function(options
) {
72 options
.cloak
= ui_
.options
.cloak
;
73 var IRC
= new qwebirc
.irc
.IRCClient(options
, ui_
);
75 window
.onbeforeunload
= qwebirc_ui_onbeforeunload
;
76 window
.addEvent("unload", function() {
77 IRC
.quit("Page closed");
82 var ichans
= this.options
.initialChannels
;
83 var autoConnect
= false;
85 if(this.options
.searchURL
) {
86 var args
= qwebirc
.util
.parseURI(String(document
.location
));
87 this.options
.hue
= this.getHueArg(args
, "");
88 this.options
.saturation
= this.getSaturationArg(args
, "");
89 this.options
.lightness
= this.getLightnessArg(args
, "");
91 this.options
.thue
= this.getHueArg(args
, "t");
92 this.options
.tsaturation
= this.getSaturationArg(args
, "t");
93 this.options
.tlightness
= this.getLightnessArg(args
, "t");
95 if(args
.contains("uio"))
96 this.options
.uiOptionsArg
= args
.get("uio");
98 var url
= args
.get("url");
99 var chans
, nick
= args
.get("nick");
102 ichans
= this.parseIRCURL(url
);
103 if($defined(chans
) && chans
!= "")
104 canAutoConnect
= true;
106 chans
= args
.get("channels");
108 var canAutoConnect
= false;
111 var cdata
= chans
.split(" ");
113 chans
= cdata
[0].split(",");
116 for(var i
=0;i
<chans
.length
;i
++) {
117 chans2
[i
] = chans
[i
];
119 var prefix
= chans
[i
].charAt(0);
120 if(prefix
!= '#' && prefix
!= '&')
121 chans2
[i
] = "#" + chans2
[i
]
123 cdata
[0] = chans2
.join(",");
124 ichans
= cdata
.join(" ");
125 canAutoConnect
= true;
130 inick
= this.randSub(nick
);
132 if(args
.contains("randomnick") && args
.get("randomnick") == 1)
133 inick
= this.options
.initialNickname
;
135 if(args
.contains("cloak") && args
.get("cloak") == 1)
136 this.options
.cloak
= true;
138 /* we only consider autoconnecting if the nick hasn't been supplied, or it has and it's not "" */
139 if(canAutoConnect
&& (!$defined(inick
) || ($defined(inick
) && (inick
!= "")))) {
140 var p
= args
.get("prompt");
141 var pdefault
= false;
143 if(!$defined(p
) || p
== "") {
146 } else if(p
== "0") {
152 /* autoconnect if we have channels and nick but only if prompt != 1 */
153 if($defined(inick
) && !p
) {
155 } else if(!pdefault
&& !p
) { /* OR if prompt=0, but not prompt=(nothing) */
161 var ui_
= new ui($(element
), new qwebirc
.ui
.Theme(this.options
.theme
), this.options
);
163 var usingAutoNick
= !$defined(nick
);
164 if(usingAutoNick
&& autoConnect
)
165 inick
= this.options
.initialNickname
;
167 var details
= ui_
.loginBox(callback
, inick
, ichans
, autoConnect
, usingAutoNick
);
170 getHueArg: function(args
, t
) {
171 var hue
= args
.get(t
+ "hue");
175 if(hue
> 360 || hue
< 0)
179 getSaturationArg: function(args
, t
) {
180 var saturation
= args
.get(t
+ "saturation");
181 if(!$defined(saturation
))
183 saturation
= parseInt(saturation
);
184 if(saturation
> 100 || saturation
< -100)
188 getLightnessArg: function(args
, t
) {
189 var lightness
= args
.get(t
+ "lightness");
190 if(!$defined(lightness
))
192 lightness
= parseInt(lightness
);
193 if(lightness
> 100 || lightness
< -100)
197 randSub: function(nick
) {
198 var getDigit = function() { return Math
.floor(Math
.random() * 10); }
200 return nick
.split("").map(function(v
) {
209 parseIRCURL: function(url
) {
210 if(url
.indexOf(":") == 0)
212 var schemeComponents
= url
.splitMax(":", 2);
213 if(schemeComponents
[0].toLowerCase() != "irc" && schemeComponents
[0].toLowerCase() != "ircs") {
214 alert("Bad IRC URL scheme.");
218 if(url
.indexOf("/") == 0) {
223 var pathComponents
= url
.splitMax("/", 4);
224 if(pathComponents
.length
< 4 || pathComponents
[3] == "") {
230 if(pathComponents
[3].indexOf("?") > -1) {
231 queryArgs
= qwebirc
.util
.parseURI(pathComponents
[3]);
232 args
= pathComponents
[3].splitMax("?", 2)[0];
234 args
= pathComponents
[3];
236 var parts
= args
.split(",");
238 var channel
= parts
[0];
239 if(channel
.charAt(0) != "#")
240 channel
= "#" + channel
;
242 var not_supported
= [], needkey
= false, key
;
243 for(var i
=1;i
<parts
.length
;i
++) {
244 var value
= parts
[i
];
245 if(value
== "needkey") {
248 not_supported
.push(value
);
252 if($defined(queryArgs
)) {
253 queryArgs
.each(function(key_
, value
) {
258 not_supported
.push(key_
);
265 key
= prompt("Please enter the password for channel " + channel
+ ":");
267 channel
= channel
+ " " + key
;
270 if(not_supported
.length
> 0)
271 alert("The following IRC URL components were not accepted: " + not_supported
.join(", ") + ".");