+ this.__cancelLogin();
+ this.fireEvent("close");
+ this.options.callback(data);
+ },
+ __cancelLogin: function(noUIModifications) {
+ if(this.__cancelLoginCallback)
+ this.__cancelLoginCallback(noUIModifications);
+ },
+ __loginConnect: function(e) {
+ new Event(e).stop();
+ if(this.validate() === false)
+ return;
+
+ this.__performLogin(function() {
+ var data = this.validate();
+ if(data === false) {
+ /* we're logged in -- show the normal join button */
+ this.util.exec("[name=connectbutton]", this.util.setVisible(true));
+ return;
+ }
+
+ this.fireEvent("close");
+ this.options.callback(data);
+ }.bind(this), "loginconnectbutton");
+ },
+ __login: function(e) {
+ new Event(e).stop();
+
+ this.__cancelLogin(true);
+
+ this.__performLogin(function() {
+ var focus = "connect";
+ if(!this.options.autoConnect) {
+ var nick = this.rootElement.getElement("input[name=nickname]").value, chan = this.rootElement.getElement("input[name=channels]").value;
+ if(!nick) {
+ focus = "nickname";
+ } else if(!chan) {
+ focus = "channels";
+ }
+ }
+ this.util.exec("[name=" + focus + "]", this.util.focus);
+ }.bind(this), "login");
+ },
+ __performLogin: function(callback, calleename) {
+ Cookie.write("jslogin", "1");
+
+ var handle = window.open("/auth", this.__windowName, "status=0,toolbar=0,location=1,menubar=0,directories=0,resizable=0,scrollbars=1,height=280,width=550");
+
+ if(handle === null || handle === undefined) {
+ Cookie.dispose("jslogin");
+// Cookie.write("redirect", document.location);
+// window.location = "auth?";
+ return;
+ }
+
+ var closeDetector = function() {
+ if(handle.closed)
+ this.__cancelLoginCallback();
+ }.bind(this);
+ var closeCallback = closeDetector.periodical(100);
+
+ this.__cancelLoginCallback = function(noUIModifications) {
+ $clear(closeCallback);
+
+ Cookie.dispose("jslogin");
+
+ try {
+ handle.close();
+ } catch(e) {
+ }
+
+ if(!noUIModifications) {
+ this.util.exec("[name=loggingin]", this.util.setVisible(false));
+ this.util.exec("[name=" + calleename + "]", this.util.setVisible(true));
+ }
+ this.__cancelLoginCallback = null;
+ }.bind(this);
+
+ this.util.exec("[name=loggingin]", this.util.setVisible(true));
+ this.util.exec("[name=" + calleename + "]", this.util.setVisible(false));
+
+ __qwebircAuthCallback = function(username, expiry, serverNow) {
+ this.__cancelLoginCallback(true);
+
+ var now = new Date().getTime();
+ var offset = (serverNow * 1000) - now;
+ var ourExpiry = expiry * 1000 - offset;
+ Cookie.write("ticketexpiry", ourExpiry)
+
+ this.util.exec("[name=loggingin]", this.util.setVisible(false));
+ this.util.exec("[name=loginstatus]", this.util.setVisible(true));
+ this.util.exec("[name=authname]", this.util.setText(username));
+ callback();
+ }.bind(this);
+
+ },
+ __validateConfirmData: function() {
+ return {nickname: this.options.initialNickname, autojoin: this.options.initialChannels};
+ },
+ __validateLoginData: function() {
+ var nick = this.rootElement.getElement("input[name=nickname]"), chan = this.rootElement.getElement("input[name=channels]");
+
+ var nickname = nick.value;
+ var chans = chan.value;
+ if(chans == "#") /* sorry channel "#" :P */
+ chans = "";
+
+ if(!nickname) {
+ alert("You must supply a nickname.");
+ nick.focus();
+ return false;
+ }
+
+ var stripped = qwebirc.global.nicknameValidator.validate(nickname);
+ if(stripped != nickname) {
+ nick.value = stripped;
+ alert("Your nickname was invalid and has been corrected; please check your altered nickname and try again.");
+ nick.focus();
+ return false;