home *** CD-ROM | disk | FTP | other *** search
- var YaWelcome = {
- onpenerYa: window.opener.Ya,
-
- nsIYa: Cc["@yandex.ru/yasearch;1"].getService(Ci.nsIYaSearch).wrappedJSObject,
- yaAuth: Cc["@yandex.ru/yasearch;1"].getService(Ci.nsIYaSearch).wrappedJSObject.yaAuth,
-
- get observerService() {
- return Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
- },
-
- get dialogContentHeight() {
- let dialogContent = document.getElementById("dialogcontent");
-
- let contentHeight = 0,
- contentStyle = window.getComputedStyle(dialogContent, null);
-
- ["border-top-width", "border-bottom-width", "margin-top", "margin-bottom"]
- .forEach(function(aPropName) {
- contentHeight += parseInt(contentStyle.getPropertyValue(aPropName), 10);
- });
-
- contentHeight += dialogContent.selectedPanel.currentHeight;
-
- return contentHeight;
- },
-
- sizeToContent: function(aCenterWindow) {
- if (window.outerHeight < 100 && !aCenterWindow)
- return;
-
- let centerWindow = !!(aCenterWindow || window.outerHeight < 100);
-
- setTimeout(function() {
- if (!centerWindow) {
- window.sizeToContent();
- return;
- }
-
- if (window.outerHeight < 100)
- window.outerHeight = 100;
-
- YaWelcome.toggleCollapsedView(YaWelcome.getAboutServiceCollapsedState());
-
- window.sizeToContent();
-
- window.centerWindowOnScreen();
-
- if (window.screenX == 50000 && window.screenY == 50000) {
- let appInfo = YaWelcome.nsIYa.AppInfo;
- if (appInfo.OS.isMacOS && appInfo.browser.isGreaterThenFx35) {
- try {
- let primaryScreen = Cc["@mozilla.org/gfx/screenmanager;1"]
- .getService(Ci.nsIScreenManager)
- .primaryScreen;
-
- let left = {}, top = {}, width = {}, height = {};
- primaryScreen.GetAvailRect(left, top, width, height);
-
- window.moveTo((left.value + width.value - window.outerWidth)/2,
- (top.value + height.value - window.outerHeight)/2);
- } catch(e) {}
- }
- }
-
- new YaDragWindow([document.getElementById("tabbox-welcome"),
- document.getElementById("tabbox-services")]);
-
- }, centerWindow ? 300 : 100);
- },
-
- get LOGIN_STATES() {
- return this.yaAuth.LOGIN_STATES;
- },
-
- _loginProcessUsername: null,
-
- get loginProcessUsername(val) {
- return this._loginProcessUsername;
- },
-
- set loginProcessUsername(val) {
- this._loginProcessUsername = this.yaAuth.normalizeUser(val).name;
- },
-
- get loginState() {
- let user = this.yaAuth.Users.getUser(this.loginProcessUsername);
- if (!user)
- return this.LOGIN_STATES.NO_AUTH;
-
- return user.auth.loginState;
- },
-
- get authType() {
- let user = this.yaAuth.Users.getUser(this.loginProcessUsername);
- if (!user)
- return null;
-
- return user.type;
- },
-
- cancelDialog: function() {
- return document.documentElement.cancelDialog();
- },
-
- aboutService: "bar",
- callbackElementId: "",
- extraProps: {},
-
- get dialogContent() {
- return document.getElementsByTagNameNS("http://bar.yandex.ru/firefox", "dialogcontent").item(0);
- },
-
- getAboutServiceCollapsedState: function() {
- if (!this.aboutService)
- return false;
-
- const prefName = "yasearch.general.ui.mybar.collapsed.services";
- var prefValue = this.nsIYa.getCharPref(prefName) || "";
-
- return !!(prefValue.indexOf("|" + this.aboutService + "|") > -1);
- },
-
- setAboutServiceCollapsedState: function(aState) {
- if (!this.aboutService)
- return;
-
- const prefName = "yasearch.general.ui.mybar.collapsed.services";
- var prefValue = this.nsIYa.getCharPref(prefName) || "";
-
- var serviceFlag = "|" + this.aboutService + "|";
-
- prefValue = prefValue.replace(serviceFlag, "");
-
- if (aState)
- prefValue += serviceFlag;
-
- this.nsIYa.setCharPref(prefName, prefValue);
- },
-
- get usernameText() {
- return (document.getElementById("yasearch-username").value || "").replace(/^\s\s*/, "").replace(/\s\s*$/, "");
- },
-
- get passwordText() {
- return (document.getElementById("yasearch-password").value || "").replace(/^\s\s*/, "").replace(/\s\s*$/, "");
- },
-
- onDialogLoad: function() {
- window.outerWidth = 3;
- window.outerHeight = 3;
-
- window.moveTo(50000,50000);
-
- let AppInfo = this.nsIYa.AppInfo;
- if (AppInfo.OS.isWindows && AppInfo.browser.isGreaterThenFx30) {
- let shadowAttribute = document.createAttribute("yashadow");
- shadowAttribute.value = "window";
- document.documentElement.attributes.setNamedItem(shadowAttribute);
- } else if (AppInfo.OS.isLinux) {
- document.documentElement.attributes.removeNamedItem("yatransparent");
- }
-
- new YaUtils.KeyCorrector(document.getElementById("yasearch-username"));
- new YaUtils.KeyCorrector(document.getElementById("yasearch-password"));
-
- if ("arguments" in window && window.arguments.length) {
- this.aboutService = window.arguments[0] || "bar";
- this.callbackElementId = window.arguments[1] || "";
- this.extraProps = window.arguments[2] || { view: "auth" };
- }
-
- if (this.aboutService == "bookmarks")
- this.aboutService = "zakladki";
-
- if (this.aboutService == "mfd")
- this.aboutService = "pdd";
-
- document.getElementById("dialogcontent").setAttribute("yaServiceName", this.aboutService);
-
- let serviceXSLTParams = { serviceType: this.aboutService };
- let serviceData = this.nsIYa.Counters.getServiceLocalizedXML(this.aboutService);
- if (serviceData) {
- let serviceDataURL = serviceData.url;
- if (serviceDataURL)
- serviceXSLTParams.serviceURL = serviceDataURL.toString();
-
- if ("@action" in serviceDataURL) {
- var serviceDataAction = parseInt(serviceDataURL.@action, 10);
- if (serviceDataAction)
- serviceXSLTParams.serviceURLAction = serviceDataAction + 1;
- }
- }
-
- let filePath = "services/mybar/services.about.";
- let aboutService = this.nsIYa.getDOMDocContent2(filePath + "xsl", filePath + "xml", serviceXSLTParams);
-
- if (aboutService) {
- document.getElementById("tabbox-welcome").setAttribute("title", aboutService.getAttribute("serviceTitle"));
- document.getElementById("about-service-holder").appendChild(aboutService);
- }
-
- document.getElementById("yasearch-username").popup.addEventListener("mouseup", this, true);
- document.getElementById("yasearch-username").popup.addEventListener("mousemove", this, true);
-
- if (this.extraProps.view == "auto") {
- let username = this.yaAuth.username;
- if (!username) {
- let mfdAuthData = this.nsIYa.yaMFD.getTopAuth();
- if (mfdAuthData)
- username = mfdAuthData.boxname;
- }
-
- this.loginProcessUsername = username || null;
-
- if (this.authType == "mfd")
- document.getElementById("dialogcontent").setAttribute("yaServiceName", "mfd");
- }
-
- this.handleLoginStateChanged();
-
- this.sizeToContent(true);
-
- this.observerService.addObserver(this, "Ya-Login-State-Changed", false);
- this.observerService.addObserver(this, "Ya-Refresh-Data", false);
- },
-
- onDialogUnload: function() {
- this.observerService.removeObserver(this, "Ya-Refresh-Data");
- this.observerService.removeObserver(this, "Ya-Login-State-Changed");
-
- document.getElementById("yasearch-username").popup.removeEventListener("mouseup", this, true);
- document.getElementById("yasearch-username").popup.removeEventListener("mousemove", this, true);
- },
-
- onDialogAccept: function() {
- if (!this.usernameText ||
- !document.getElementById("yasearch-password").value)
- return false;
-
- this.loginProcessUsername = this.usernameText;
-
- var cookiesHostName = "yandex.ru";
- var cookiesAllowed = this.yaAuth.Cookies.isCookiesAllowedForHost(cookiesHostName);
-
- if (!cookiesAllowed) {
- var cookieBehaviorValue = cookiesAllowed === null ? -1 : this.nsIYa.getIntPref("network.cookie.cookieBehavior");
-
- var dialogTextAppend = "";
-
- switch (cookieBehaviorValue) {
- case 1:
- dialogTextAppend = " " + this.getLocalizedString("Cookies3PartyDisabledText");
- break;
-
- case 2:
- break;
-
- default:
- cookieBehaviorValue = -1;
- dialogTextAppend = " " + this.getLocalizedString("Cookies3PartyDisabledYandexText");
- break;
- }
-
- var dialogText = this.getLocalizedFormattedString("CookiesDisabledText", [dialogTextAppend]);
-
- var prompter = this.nsIYa.promptService;
- var dummy = { value: false };
- if (prompter.confirmEx(window,
- null,
- dialogText,
- prompter.STD_YES_NO_BUTTONS + prompter.BUTTON_POS_0_DEFAULT,
- null, null, null, null, dummy) == 1) {
- return false;
- }
-
- if (cookieBehaviorValue != -1)
- this.nsIYa.setIntPref("network.cookie.cookieBehavior", 0);
-
- if (!this.yaAuth.Cookies.isCookiesAllowedForHost(cookiesHostName))
- this.yaAuth.Cookies.allowCookiesForHost(cookiesHostName);
- }
-
- if (!this.yaAuth.initLoginProcess(this.usernameText,
- this.passwordText,
- document.getElementById("yasearch-store-password").checked,
- true)) {
- this.cancelDialog();
- }
-
- return false;
- },
-
- toggleCollapsedView: function(aCollapsed) {
- var tabpanel = document.getElementById("login-tabpanel");
- var collapsed = typeof aCollapsed == "boolean" ? aCollapsed : !(tabpanel.getAttribute("collapsed") == "true");
-
- tabpanel.setAttribute("collapsed", collapsed);
-
- this.sizeToContent();
-
- this.setAboutServiceCollapsedState(collapsed);
- },
-
- handleWindowClick: function(aEvent) {
- var target = aEvent.originalTarget,
- targetHref;
-
- while (target &&
- "getAttribute" in target &&
- !(targetHref = target.getAttribute("href") || target.getAttribute("yahref"))) {
- target = target.parentNode;
- }
-
- if (targetHref) {
- targetHref = targetHref.replace(/\{user\}/g, this.yaAuth.username);
-
- var action = target.hasAttribute("yaLinkAction") ? target.getAttribute("yaLinkAction") : null;
-
- if (/\/mail\.yandex\.(ru|ua|kz|by)\/messages$/.test(targetHref) &&
- this.nsIYa.getBoolPref("yasearch.mail.uri.open.new")) {
- targetHref += "?extra_cond=only_new";
- }
-
- this.nsIYa.loadURI(targetHref, "tab", (action ? {action:action} : null));
-
- this.cancelDialog();
-
- return false;
- }
-
- return true;
- },
-
- checkAcceptButton: function() {
- let disabled = this.loginState >= this.LOGIN_STATES.REQUEST ||
- this.usernameText.length < 2 ||
- this.passwordText.length < 2;
-
- let acceptButton = document.documentElement.getButton("accept");
- if (acceptButton.disabled !== disabled)
- acceptButton.disabled = disabled;
-
- document.getElementById("login-button").disabled = disabled;
- },
-
- handleLoginEntered: function() {
- let pass = this.yaAuth.PasswordManager.getStoredPassword(this.usernameText);
- document.getElementById("yasearch-password").value = pass;
- document.getElementById("yasearch-store-password").checked = !!pass;
-
- this.checkAcceptButton();
- },
-
- getLocalizedString: function(aName) {
- return document.getElementById("yasearch-string-bundle-welcome").getString(aName);
- },
-
- getLocalizedFormattedString: function(aName, aStrArray) {
- return document.getElementById("yasearch-string-bundle-welcome").getFormattedString(aName, aStrArray, aStrArray.length);
- },
-
- _getHoverCellHelper: function(aEvent) {
- let row = {},
- col = {},
- obj = {};
-
- let docBoxObject = document.documentElement.boxObject;
- let x = aEvent.screenX - docBoxObject.screenX;
- let y = aEvent.screenY - docBoxObject.screenY;
-
- aEvent.originalTarget.parentNode.treeBoxObject.getCellAt(x, y, row, col, obj);
-
- return (row.value >= 0) ? { row: row.value, column: col.value.id } : null;
- },
-
- handleEvent: function(aEvent) {
- if (!aEvent.isTrusted)
- return;
-
- switch (aEvent.type) {
- case "mouseup":
- var rc = this._getHoverCellHelper(aEvent);
- if (rc) {
- if (rc.column && rc.column == "treecolAutoCompleteComment") {
- aEvent.stopPropagation();
-
- let login2remove = document.getElementById("yasearch-username").controller.getValueAt(rc.row);
- let rv = this.nsIYa.promptService.confirm(window,
- this.getLocalizedString("LogginRemoveUserTitle"),
- this.getLocalizedFormattedString("LogginRemoveUserMessage", [login2remove]));
-
- if (rv) {
- let password2remove = this.yaAuth.PasswordManager.getStoredPassword(login2remove);
- this.yaAuth.PasswordManager.removeUserData(login2remove);
-
- if (this.usernameText == login2remove) {
- document.getElementById("yasearch-username").value = "";
-
- if (this.passwordText == password2remove)
- document.getElementById("yasearch-password").value = "";
-
- document.getElementById("yasearch-store-password").checked = false;
- }
-
- this.refreshHasSavedLoginsMode();
- this.checkAcceptButton();
- }
- }
- }
- break;
-
- case "mousemove":
- var rc = null;
- try {
- rc = this._getHoverCellHelper(aEvent);
- } catch(e) {}
-
- if (!rc)
- return;
-
- let onCommentColumn = (rc.column && rc.column == "treecolAutoCompleteComment") ? true : false;
- if (this.yaAuth.PasswordManager.onHoverTreeUglyHack != onCommentColumn) {
- this.yaAuth.PasswordManager.onHoverTreeUglyHack = onCommentColumn;
- document.getElementById("yasearch-username").popup.invalidate();
- }
-
- break;
- }
- },
-
- observe: function(aSubject, aTopic, aState) {
- if (aTopic == "Ya-Login-State-Changed") {
- if (aState == this.loginProcessUsername)
- this.handleLoginStateChanged(true);
-
- return;
- }
-
- if (aTopic != "Ya-Refresh-Data")
- return;
-
- switch (aState) {
- case "allServices":
- var xulList;
-
- if (this.authType == "mfd") {
- xulList = this.nsIYa.Counters.getUserServicesXULForMFDUser(this.loginProcessUsername);
- } else {
- xulList = this.nsIYa.Counters.getUserServicesXUL();
- document.getElementById("tabbox-services").busy = false;
- }
-
- if (xulList)
- this.nsIYa.DOMUtils.replaceChildNodes(xulList, document.getElementById("user-info-services-list"));
-
- this.sizeToContent();
-
- break;
-
- case "yaru-user-data":
- if (this.authType == "mfd") {
- document.getElementById("user-info-name").value = this.loginProcessUsername.split("@")[0];
- } else {
- var yaruData = this.nsIYa.Counters.getYaruUserData();
-
- var avatar = document.getElementById("user-info-avatar");
- avatar.holder.setAttribute("yahref", "http://{user}.ya.ru/");
- avatar.holder.setAttribute("yaLinkAction", "3470");
- avatar.avatarSrc = yaruData ? yaruData.avatar.toString() + "middle" : "";
-
- document.getElementById("user-info-name").value = (yaruData ? yaruData.title.toString() : "") || this.yaAuth.username;
- document.getElementById("user-info-status").value = yaruData ? yaruData.mood.toString() : "";
- }
-
- break;
- }
- },
-
- handleLoginStateChanged: function(aFromObserver) {
- let connectionStatus = 0;
- let lastStateIsRequest = document.getElementById("yasearch-connection-status").selectedIndex == 1;
-
- if (this.loginState == this.LOGIN_STATES.AUTH) {
- if (lastStateIsRequest) {
- if (this.callbackElementId && (this.callbackElementId == "yasearch-mail-button" || this.authType != "mfd")) {
- let browser = this.nsIYa.getWindow("navigator:browser");
- if (browser && browser.Ya) {
- let elementToCall = browser.document.getElementById(this.callbackElementId);
- if (elementToCall && "doCommand" in elementToCall) {
- let clbckFn = elementToCall.id === "yasearch-bookmarks-button" ?
- function() { browser.Ya.loadURI("zakladki.yandex.ru"); } :
- function() { elementToCall.doCommand(); };
-
- new this.nsIYa.utils.G_Timer(clbckFn, 1000);
- }
- }
- }
-
- this.cancelDialog();
- return;
- }
-
- this.showUserPage();
-
- } else {
- switch (this.loginState) {
- case this.LOGIN_STATES.NO_AUTH:
- if (this._exitAfterLogout) {
- document.documentElement.cancelDialog();
- return;
- }
-
- break;
-
- case this.LOGIN_STATES.REQUEST:
- connectionStatus = 1;
- break;
-
- case this.LOGIN_STATES.NET_ERROR:
- connectionStatus = lastStateIsRequest ? 3 : 0;
- break;
-
- case this.LOGIN_STATES.CAPTCHA_ERROR:
- if (lastStateIsRequest) {
- let prompter = this.nsIYa.promptService;
-
- let flags = prompter.BUTTON_POS_0 * prompter.BUTTON_TITLE_IS_STRING +
- prompter.BUTTON_POS_1 * prompter.BUTTON_TITLE_IS_STRING +
- prompter.BUTTON_POS_0_DEFAULT;
-
- let rv = prompter.confirmEx(window,
- this.getLocalizedString("CaptchaDialogTitle"),
- this.getLocalizedString("CaptchaDialogMsg"),
- flags,
- this.getLocalizedString("CaptchaDialogButtonOK"),
- this.getLocalizedString("CaptchaDialogButtonCancel"),
- null, null, {});
-
- if (rv !== 1) {
- this.nsIYa.loadURI("https://passport.yandex.ru", "tab");
- this.cancelDialog();
- return;
- }
- }
-
- default:
- if (lastStateIsRequest)
- connectionStatus = 2;
- break;
- }
-
- if (lastStateIsRequest && this.yaAuth.loginFail)
- connectionStatus = 4;
-
- this.showAuthPage();
- }
-
- this.setConnectionStatus(connectionStatus);
-
- let controlsDisabled = (this.loginState >= this.LOGIN_STATES.REQUEST);
- ["yasearch-username", "yasearch-password", "yasearch-store-password"]
- .forEach(function(aControlId) {
- document.getElementById(aControlId).disabled = controlsDisabled;
- });
-
- if (!controlsDisabled) {
- let passTextbox = document.getElementById("yasearch-password");
- if (document.commandDispatcher.focusedElement == passTextbox.inputField) {
- passTextbox.blur();
- passTextbox.focus();
- }
- }
- },
-
- setConnectionStatus: function(aStatusIndex) {
- document.getElementById("yasearch-connection-status").selectedIndex = aStatusIndex;
- this.sizeToContent();
- },
-
- refreshHasSavedLoginsMode: function() {
- document.getElementById("yasearch-username")
- .setAttribute("yaHasSavedLogins", this.yaAuth.PasswordManager.hasSavedLogins);
- },
-
- switchUser: function() {
- this.extraProps.view == "auth";
-
- this.loginProcessUsername = null;
-
- document.getElementById("yasearch-username").value = "";
- document.getElementById("yasearch-password").value = "";
-
- document.getElementById("yasearch-connection-status").selectedIndex = 0;
-
- this.handleLoginStateChanged();
-
- this.sizeToContent();
- },
-
- showAuthPage: function() {
- this.dialogContent.selectedIndex = 0;
-
- this.refreshHasSavedLoginsMode();
-
- if (this.usernameText == "") {
- let username = this.nsIYa.getCharPref("yasearch.users.default");
- if (username) {
- let password = this.yaAuth.PasswordManager.getStoredPassword(username);
- if (password) {
- document.getElementById("yasearch-username").value = username;
- document.getElementById("yasearch-password").value = password;
- }
-
- document.getElementById("yasearch-store-password").checked = !!password;
- }
- }
-
- this.checkAcceptButton();
- },
-
- showUserPage: function() {
- document.getElementById("user-info-avatar").removeAttribute("yahref");
-
- this.observe(null, "Ya-Refresh-Data", "allServices");
- this.observe(null, "Ya-Refresh-Data", "yaru-user-data");
-
- this.dialogContent.selectedIndex = 1;
-
- if (this.authType != "mfd") {
- document.getElementById("tabbox-services").busy = true;
- this.nsIYa.refreshHTTPData("allServices");
- this.nsIYa.Counters.refreshYaRuUserData();
- }
- },
-
- _exitAfterLogout: false,
-
- logout: function(aExitAfterLogout) {
- const NOPROMPT_PREF_NAME = "yasearch.general.ui.mybar.logout.noprompt";
-
- let forgetMe = { value: false };
- let noprompt = this.nsIYa.getBoolPref(NOPROMPT_PREF_NAME);
-
- if (!noprompt) {
- let savedPass = !!(this.yaAuth.PasswordManager.getStoredPassword(this.loginProcessUsername));
-
- let prompts = this.nsIYa.promptService;
- let buttonFlags = prompts.BUTTON_POS_0 * prompts.BUTTON_TITLE_IS_STRING +
- prompts.BUTTON_POS_1 * prompts.BUTTON_TITLE_IS_STRING +
- prompts.BUTTON_POS_2 * prompts.BUTTON_TITLE_IS_STRING +
- prompts.BUTTON_POS_0_DEFAULT;
-
- let answerBtnIndex = prompts.confirmEx(null,
- this.getLocalizedString("logOutTitle"),
- this.getLocalizedString("logOutConfirm"),
- buttonFlags,
- this.getLocalizedString("logOutYesPrompt"),
- this.getLocalizedString("logOutNoPrompt"),
- this.getLocalizedString("logOutNoAlwaysPrompt"),
- savedPass ? this.getLocalizedString("logOutForgetPass") : null,
- forgetMe);
-
- switch (answerBtnIndex) {
- case 0:
- break;
-
- case 1:
- return;
-
- case 2:
- this.nsIYa.setBoolPref(NOPROMPT_PREF_NAME, true);
- break;
- }
- }
-
- this._exitAfterLogout = aExitAfterLogout;
-
- this.yaAuth.dropAuth(this.loginProcessUsername, true, forgetMe.value);
-
- if (aExitAfterLogout)
- this.cancelDialog();
- },
-
- onNewLoginClick: function(aEvent) {
- let url = "http://passport.yandex.ru/passport?mode=register";
-
- let clid4 = this.nsIYa.vendorData.clid4 || "";
-
- url += "&clid=" + clid4 +
- "&retpath=http%3A%2F%2Fclck.yandex.ru%2Fredir%2Fdtype%3Dstred%2Fpid%3D12%2Fcid%3D1737%2Fpath%3D" +
- clid4 + "%2F*";
-
- let serviceURL = "http://i.yandex.ru"
- let serviceData = this.nsIYa.Counters.getServiceLocalizedXML(this.aboutService);
-
- if (serviceData) {
- let afterRegURL = serviceData.afterregistration.toString() || serviceData.url.toString();
- if (afterRegURL)
- serviceURL = afterRegURL;
- }
-
- url += encodeURIComponent(serviceURL);
-
- this.onpenerYa.loadURI(url, aEvent, {action:3100});
- this.cancelDialog();
- }
- }
-