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: null,
15 initialChannels: null,
16 networkName: "ExampleNetwork",
19 appTitle: "ExampleNetwork Web IRC",
33 dynamicConfiguration: false,
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 dynamicConfiguration: options
.dynamicConfiguration
,
66 staticBaseURL: options
.staticBaseURL
,
67 baseURL: options
.baseURL
,
68 nicknameValidator: $defined(options
.nickValidation
) ? new qwebirc
.irc
.NicknameValidator(options
.nickValidation
) : new qwebirc
.irc
.DummyNicknameValidator(),
69 dynamicConfigurationLoaded: false
72 window
.addEvent("domready", function() {
73 var callback = function(options
) {
74 var IRC
= new qwebirc
.irc
.IRCClient(options
, ui_
);
76 window
.onbeforeunload
= qwebirc_ui_onbeforeunload
;
77 window
.addEvent("unload", function() {
78 IRC
.quit("Page closed");
83 var ichans
= this.options
.initialChannels
;
84 var autoConnect
= false;
86 if(this.options
.searchURL
) {
87 var args
= qwebirc
.util
.parseURI(String(document
.location
));
88 this.options
.hue
= this.getHueArg(args
, "");
89 this.options
.saturation
= this.getSaturationArg(args
, "");
90 this.options
.lightness
= this.getLightnessArg(args
, "");
92 this.options
.thue
= this.getHueArg(args
, "t");
93 this.options
.tsaturation
= this.getSaturationArg(args
, "t");
94 this.options
.tlightness
= this.getLightnessArg(args
, "t");
96 if(args
.contains("uio"))
97 this.options
.uiOptionsArg
= args
.get("uio");
99 var url
= args
.get("url");
100 var chans
, nick
= args
.get("nick");
103 ichans
= this.parseIRCURL(url
);
104 if($defined(chans
) && chans
!= "")
105 canAutoConnect
= true;
107 chans
= args
.get("channels");
109 var canAutoConnect
= false;
112 var cdata
= chans
.split(" ");
114 chans
= cdata
[0].split(",");
117 for(var i
=0;i
<chans
.length
;i
++) {
118 chans2
[i
] = chans
[i
];
120 var prefix
= chans
[i
].charAt(0);
121 if(prefix
!= '#' && prefix
!= '&')
122 chans2
[i
] = "#" + chans2
[i
]
124 cdata
[0] = chans2
.join(",");
125 ichans
= cdata
.join(" ");
126 canAutoConnect
= true;
131 inick
= this.randSub(nick
);
133 if(args
.contains("randomnick") && args
.get("randomnick") == 1)
134 inick
= this.options
.initialNickname
;
136 /* we only consider autoconnecting if the nick hasn't been supplied, or it has and it's not "" */
137 if(canAutoConnect
&& (!$defined(inick
) || ($defined(inick
) && (inick
!= "")))) {
138 var p
= args
.get("prompt");
139 var pdefault
= false;
141 if(!$defined(p
) || p
== "") {
144 } else if(p
== "0") {
150 /* autoconnect if we have channels and nick but only if prompt != 1 */
151 if($defined(inick
) && !p
) {
153 } else if(!pdefault
&& !p
) { /* OR if prompt=0, but not prompt=(nothing) */
159 var ui_
= new ui($(element
), new qwebirc
.ui
.Theme(this.options
.theme
), this.options
);
161 var usingAutoNick
= !$defined(nick
);
162 if(usingAutoNick
&& autoConnect
)
163 inick
= this.options
.initialNickname
;
165 var details
= ui_
.loginBox(callback
, inick
, ichans
, autoConnect
, usingAutoNick
);
168 getHueArg: function(args
, t
) {
169 var hue
= args
.get(t
+ "hue");
173 if(hue
> 360 || hue
< 0)
177 getSaturationArg: function(args
, t
) {
178 var saturation
= args
.get(t
+ "saturation");
179 if(!$defined(saturation
))
181 saturation
= parseInt(saturation
);
182 if(saturation
> 100 || saturation
< -100)
186 getLightnessArg: function(args
, t
) {
187 var lightness
= args
.get(t
+ "lightness");
188 if(!$defined(lightness
))
190 lightness
= parseInt(lightness
);
191 if(lightness
> 100 || lightness
< -100)
195 randSub: function(nick
) {
196 var getDigit = function() { return Math
.floor(Math
.random() * 10); }
198 return nick
.split("").map(function(v
) {
207 parseIRCURL: function(url
) {
208 if(url
.indexOf(":") == 0)
210 var schemeComponents
= url
.splitMax(":", 2);
211 if(schemeComponents
[0].toLowerCase() != "irc" && schemeComponents
[0].toLowerCase() != "ircs") {
212 alert("Bad IRC URL scheme.");
216 if(url
.indexOf("/") == 0) {
221 var pathComponents
= url
.splitMax("/", 4);
222 if(pathComponents
.length
< 4 || pathComponents
[3] == "") {
228 if(pathComponents
[3].indexOf("?") > -1) {
229 queryArgs
= qwebirc
.util
.parseURI(pathComponents
[3]);
230 args
= pathComponents
[3].splitMax("?", 2)[0];
232 args
= pathComponents
[3];
234 var parts
= args
.split(",");
236 var channel
= parts
[0];
237 if(channel
.charAt(0) != "#")
238 channel
= "#" + channel
;
240 var not_supported
= [], needkey
= false, key
;
241 for(var i
=1;i
<parts
.length
;i
++) {
242 var value
= parts
[i
];
243 if(value
== "needkey") {
246 not_supported
.push(value
);
250 if($defined(queryArgs
)) {
251 queryArgs
.each(function(key_
, value
) {
256 not_supported
.push(key_
);
263 key
= prompt("Please enter the password for channel " + channel
+ ":");
265 channel
= channel
+ " " + key
;
268 if(not_supported
.length
> 0)
269 alert("The following IRC URL components were not accepted: " + not_supported
.join(", ") + ".");
275 qwebirc
.ui
.requireDynamicConfiguration = function(callback
) {
276 if (!qwebirc
.global
.dynamicConfiguration
|| qwebirc
.global
.dynamicConfigurationLoaded
) {
281 var r
= new Request
.JSON({url: qwebirc
.global
.dynamicBaseURL
+ "configuration", onSuccess: function(data
) {
282 qwebirc
.global
.dynamicBaseURL
= data
["dynamicBaseURL"];