]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/qwebircinterface.js
1 qwebirc
.ui
.Interface
= new Class({
4 initialNickname: "qwebirc" + Math
.ceil(Math
.random() * 100000),
6 networkName: "ExampleNetwork",
9 appTitle: "ExampleNetwork Web IRC",
15 initialize: function(element
, ui
, options
) {
16 this.setOptions(options
);
18 window
.addEvent("domready", function() {
19 var callback = function(options
) {
20 var IRC
= new qwebirc
.irc
.IRCClient(options
, ui_
);
22 window
.addEvent("beforeunload", function() {
23 IRC
.quit("Page closed");
28 var ichans
= this.options
.initialChannels
;
29 var autoConnect
= false;
31 if(this.options
.searchURL
) {
32 var args
= qwebirc
.util
.parseURI(String(document
.location
));
33 this.options
.hue
= this.getHueArg(args
);
34 var url
= args
["url"];
35 var chans
, nick
= args
["nick"];
38 ichans
= this.parseIRCURL(url
);
39 if($defined(chans
) && chans
!= "")
40 canAutoConnect
= true;
42 chans
= args
["channels"];
44 var canAutoConnect
= false;
47 var cdata
= chans
.split(" ");
49 chans
= cdata
[0].split(",");
52 for(var i
=0;i
<chans
.length
;i
++) {
55 if(chans
[i
].charAt(0) != '#')
56 chans2
[i
] = "#" + chans2
[i
]
58 cdata
[0] = chans2
.join(",");
59 ichans
= cdata
.join(" ");
60 canAutoConnect
= true;
65 inick
= this.randSub(nick
);
67 if(args
["randomnick"] && args
["randomnick"] == 1)
68 inick
= this.options
.initialNickname
;
70 /* we only consider autoconnecting if the nick hasn't been supplied, or it has and it's not "" */
71 if(canAutoConnect
&& (!$defined(inick
) || ($defined(inick
) && (inick
!= "")))) {
72 var p
= args
["prompt"];
75 if(!$defined(p
) || p
== "") {
84 /* autoconnect if we have channels and nick but only if prompt != 1 */
85 if($defined(inick
) && !p
) {
87 } else if(!pdefault
&& !p
) { /* OR if prompt=0, but not prompt=(nothing) */
93 var ui_
= new ui($(element
), new qwebirc
.ui
.Theme(this.options
.theme
), this.options
);
95 var usingAutoNick
= !$defined(nick
);
96 if(usingAutoNick
&& autoConnect
)
97 inick
= this.options
.initialNickname
;
99 var details
= ui_
.loginBox(callback
, inick
, ichans
, autoConnect
, usingAutoNick
);
102 getHueArg: function(args
) {
103 var hue
= args
["hue"];
107 if(hue
> 360 || hue
< 0)
111 randSub: function(nick
) {
112 var getDigit = function() { return Math
.floor(Math
.random() * 10); }
114 return nick
.split("").map(function(v
) {
123 parseIRCURL: function(url
) {
124 if(url
.indexOf(":") == 0)
126 var schemeComponents
= url
.splitMax(":", 2);
127 if(schemeComponents
[0].toLowerCase() != "irc" && schemeComponents
[0].toLowerCase() != "ircs") {
128 alert("Bad IRC URL scheme.");
132 if(url
.indexOf("/") == 0) {
137 var pathComponents
= url
.splitMax("/", 4);
138 if(pathComponents
.length
< 4 || pathComponents
[3] == "") {
144 if(pathComponents
[3].indexOf("?") > -1) {
145 queryArgs
= qwebirc
.util
.parseURI(pathComponents
[3]);
146 args
= pathComponents
[3].splitMax("?", 2)[0];
148 args
= pathComponents
[3];
150 var parts
= args
.split(",");
152 var channel
= parts
[0];
153 if(channel
.charAt(0) != "#")
154 channel
= "#" + channel
;
156 var not_supported
= [], needkey
= false, key
;
157 for(var i
=1;i
<parts
.length
;i
++) {
158 var value
= parts
[i
];
159 if(value
== "needkey") {
162 not_supported
.push(value
);
166 if($defined(queryArgs
)) {
167 for(var key_
in queryArgs
) {
168 var value
= queryArgs
[key_
];
174 not_supported
.push(key_
);
181 key
= prompt("Please enter the password for channel " + channel
+ ":");
183 channel
= channel
+ " " + key
;
186 if(not_supported
.length
> 0)
187 alert("The following IRC URL components were not accepted: " + not_supported
.join(", ") + ".");