home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Narzedzia
/
AIMP2
/
aimp_2.61.583.exe
/
$TEMP
/
YandexPackSetup.msi
/
filF0298B0202F77D777DC8C37B07F238F1
< prev
next >
Wrap
Text File
|
2010-07-12
|
48KB
|
1,436 lines
var Ya = {
observerService: Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService),
nsIYa: Cc["@yandex.ru/yasearch;1"].getService(Ci.nsIYaSearch).wrappedJSObject,
sContextMenu: null,
lastWord: null,
yaContextSearchId: "yasearchMenuIdPrefix-yandex-search-menu",
yaContextSearchServicesId: "yasearchMenuIdPrefix-yandex-menu",
onLoad: function() {
if (typeof(FeedHandler) === "object" && typeof(FeedHandler.updateFeeds) === "function") {
var origUpdateFeeds = FeedHandler.updateFeeds;
FeedHandler.updateFeeds = function() {
Ya.updateFeedsAttribute();
return origUpdateFeeds.apply(this, arguments);
}
}
if (typeof(BrowserToolboxCustomizeDone) === "function") {
var origBrowserToolboxCustomizeDone = BrowserToolboxCustomizeDone;
BrowserToolboxCustomizeDone = function() {
Ya.realizeLoginBehaviour();
return origBrowserToolboxCustomizeDone.apply(this, arguments);
}
}
this.stringBundleSet = document.getElementById("yasearch-string-bundle-global");
this.sContextMenu = document.getElementById("contentAreaContextMenu");
if (this.nsIYa.getBoolPref("yasearch.default.search")) {
let menuElement = document.getElementById("context-searchselect");
if (menuElement)
menuElement.setAttribute("style", "display:none !important");
}
this.realizeLoginBehaviour();
this.observerService.addObserver(this, "Ya-Refresh-Services", false);
this.observerService.addObserver(this, "Ya-Refresh-Login-Status", false);
this.observerService.addObserver(this, "Ya-Refresh-Data", false);
this.observerService.addObserver(this, "Ya-Refresh-Busy-State", false);
this.redrawContextMenu();
this.sContextMenu.addEventListener("popupshowing", function(e) { Ya.showContextMenu(e) }, false);
this.sContextMenu.addEventListener("popuphidden", function(e) { Ya.hideContextMenu(e) }, false);
setTimeout(function(){
Ya._mailIntegration.defaultOnClick =
document.getElementById("content").onclick ||
function() {
return window.contentAreaClick(event, false);
};
Ya._mailIntegration.defaultWinObject = window.MailIntegration;
Ya.mailIntegration = Ya.nsIYa.getBoolPref("yasearch.general.ui.mail.integration");
}, 10);
this.observerService.notifyObservers(null, "Ya-Browser-OpenClose", "open");
let partnerPaletteNode =
Array.slice.call(document.getElementById("navigator-toolbox").palette.childNodes)
.filter(function(aNode){return aNode.id == "yasearch-partner"})[0];
if (partnerPaletteNode) {
var partnerExists = false;
if (this.nsIYa.yaPartner) {
let toolbaritemContent = this.nsIYa.yaPartner.toolbaritemContent(document);
if (toolbaritemContent) {
partnerExists = true;
["title", "label", "image"].forEach(function(aAttrName) {
if (toolbaritemContent.hasAttribute(aAttrName))
partnerPaletteNode.setAttribute(aAttrName, toolbaritemContent.getAttribute(aAttrName));
});
}
}
if (!partnerExists)
partnerPaletteNode.parentNode.removeChild(partnerPaletteNode);
}
},
unLoad: function() {
this.observerService.removeObserver(this, "Ya-Refresh-Services");
this.observerService.removeObserver(this, "Ya-Refresh-Login-Status");
this.observerService.removeObserver(this, "Ya-Refresh-Data");
this.observerService.removeObserver(this, "Ya-Refresh-Busy-State");
this.observerService.notifyObservers(null, "Ya-Browser-OpenClose", "close");
},
redrawSearchBoxPopup: function() {
let searchTB = document.getElementById("yasearch-textbox");
if (searchTB)
searchTB.rebuildPopupServices();
},
focusSearch: function() {
let searchTB = document.getElementById("yasearchbox");
if (searchTB) {
searchTB.focus();
searchTB.select();
}
},
get buttonsObject() {
let buttons = {
get navigElements() {
return !!(this.bloggers || this.cy || this.spam);
},
get isAnyVisibleAuthElement() {
}
};
["cy", "spam", "bloggers", "lenta", "mail", "money", "fotki", "yaru", "translate", "moikrug"]
.forEach(function(aButtonName) {
this[aButtonName] = !!document.getElementById("yasearch-" + aButtonName);
}, buttons);
return buttons;
},
buildFeedsMenu: function() {
var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
let addFeedsMenu = document.createElementNS(XULNS, "menulist");
addFeedsMenu.appendChild(document.createElementNS(XULNS, "menupopup"));
let feeds = ("feeds" in gBrowser.mCurrentBrowser) ? gBrowser.mCurrentBrowser.feeds : null;
if (!feeds || feeds.length == 0)
return false;
for each (var feed in feeds) {
let newFeed = document.createElementNS(XULNS, "menuitem");
let baseTitle = feed.title || feed.href;
newFeed.setAttribute("label", baseTitle);
newFeed.setAttribute("tooltiptext", feed.href);
addFeedsMenu.firstChild.appendChild(newFeed);
}
window.openDialog(YaUtils.CHROME_CONTENT + "feeds/add-dialog.xul", "",
"centerscreen,chrome,dialog,resizable,dependent",
addFeedsMenu, gBrowser.mCurrentBrowser.contentTitle);
return true;
},
updateFeedsAttribute: function() {
let lentaTBItem = document.getElementById("yasearch-lenta");
if (lentaTBItem) {
setTimeout(function(me) {
let feeds = ("feeds" in gBrowser.mCurrentBrowser) ? gBrowser.mCurrentBrowser.feeds : null;
lentaTBItem.setAttribute("hasFeeds", !(!feeds || feeds.length == 0));
if (lentaTBItem.firstChild.open)
me.onLentaPopupshowing();
}, 0, this);
}
},
onLentaPopupshowing: function() {
let lentaTBItem = document.getElementById("yasearch-lenta");
let lentaMenuPopup = document.getElementById("yasearch-lenta-menupopup");
if (lentaTBItem && lentaMenuPopup)
lentaMenuPopup.lastChild.setAttribute("disabled", !(lentaTBItem.getAttribute("hasFeeds") == "true"));
},
addBookmark: function(aFolderId, aExistId) {
window.openDialog(YaUtils.CHROME_CONTENT + "bookmarks/add-dialog.xul", "",
"centerscreen,chrome,dialog,resizable,dependent",
gBrowser.mCurrentBrowser, aFolderId, aExistId);
},
loadCY: function(aEvent, aType) {
let location = gBrowser.selectedBrowser.webNavigation.currentURI;
try {
if (location.scheme && (location.scheme == "http" || location.scheme == "https") && location.host.length >= 3) {
switch (aType) {
case "similar":
this.loadURI("http://yandex.ru/yandsearch?ds=" + encodeURIComponent(location.spec), aEvent);
break;
case "all":
this.loadURI("http://yandex.ru/yandsearch?serverurl=" + encodeURIComponent(location.host), aEvent);
break;
default:
this.loadURI("http://www.yandex.ru/cy?host=" + encodeURIComponent(location.host) + "&base=0",
aEvent, {action:3200});
break;
}
}
} catch(e) {}
},
setCY: function(aCYData) {
let spamButton = document.getElementById("yasearch-spam-button");
if (spamButton) {
if (aCYData && aCYData.spam) {
spamButton.disabled = false;
let onCommandTxt = "Ya.confirmCYSpamPromt('" + aCYData.spam + "', event.target)";
spamButton.setAttribute("oncommand", "if (event.target == this) " + onCommandTxt);
document.getElementById("yasearch-spam-button-confirm-item").setAttribute("oncommand", onCommandTxt);
} else {
spamButton.disabled = true;
}
}
let cyButton = document.getElementById("yasearch-cy-button");
if (cyButton)
cyButton.setCYData(aCYData);
},
confirmCYSpamPromt: function(aUrl, aElement) {
let rv = this.nsIYa.promptService.confirm(window,
this.stringBundleSet.getString("ConfirmCYSpamTitle"),
this.stringBundleSet.getString("ConfirmCYSpamMessage"));
if (rv)
this.nsIYa.confirmCYSpam(aUrl, aElement);
},
get personalToolbarItems() {
return YaUtils.evaluateXPath(document, "//xul:toolbaritem[starts-with(@class,'yasearch-login')]");
},
_changeToolbaritemAuthState: function(aToolbarItem, aIsHasAuth) {
let reg = aIsHasAuth ? /(\s|^)yasearch\-login\-not(\s|$)/ : /(\s|^)yasearch\-login(\s|$)/;
let repl = "$1yasearch-login" + (aIsHasAuth ? "" : "-not") + "$2";
aToolbarItem.className = aToolbarItem.className.replace(reg, repl);
Array.slice(aToolbarItem.childNodes)
.filter(function(ch) ch.hasAttribute("yaAuthDisabled"))
.concat(aToolbarItem)
.forEach(function(ch) {
ch.setAttribute("yaAuthDisabled", !aIsHasAuth);
});
},
realizeLoginBehaviour: function() {
let isLogin = this.nsIYa.isLogin;
this.personalToolbarItems.forEach(function(item) {
if (!/\-(mail|login)\-/.test(item.id))
this._changeToolbaritemAuthState(item, isLogin);
}, this);
this.updateServicesWork();
},
refreshLoginButton: function() {
let loginButton = document.getElementById("yasearch-login-button");
if (!loginButton)
return;
let fullLogin = "";
let login = this.nsIYa.yaAuth.session.login;
if (!login) {
let swapData = this.nsIYa.yaAuth.swapUsersData;
if (swapData) {
login = swapData.username;
} else {
let mfdAuthData = this.MFD.getTopAuth();
if (mfdAuthData) {
login = mfdAuthData.username;
fullLogin = mfdAuthData.boxname;
}
}
}
let tooltiptext = login ? this.stringBundleSet.getString("user") + ": " + (fullLogin || login) :
loginButton.getAttribute("_deftooltiptext");
loginButton.setAttribute("yaLabel", login || "0");
loginButton.setAttribute("tooltiptext", tooltiptext);
this._changeToolbaritemAuthState(document.getElementById("yasearch-login"), !!login);
},
onLoginButtonPopupShowing: function() {
let loginButton = document.getElementById("yasearch-login-button");
if (!loginButton || loginButton.getAttribute("yaLabel") == "0")
return false;
let menuseparators = loginButton.getElementsByTagName("menuseparator");
let menuseparator = menuseparators.item(menuseparators.length - 1);
let menupopup = menuseparator.parentNode;
while (menupopup.firstChild != menuseparator)
menupopup.removeChild(menupopup.firstChild);
let loginsInfo = this.nsIYa.yaAuth.getAllLoginsInfo();
menuseparator.hidden = !loginsInfo.length;
if (loginsInfo.length) {
loginsInfo.sort(function(a,b) {
return (a.type > b.type) ? -1 : (a.type < b.type) ? 1 :
((a.username > b.username) ? 1 : (a.username < b.username) ? -1 : 0);
});
let frag = document.createDocumentFragment();
let loginType = loginsInfo[0].type;
let XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
let doc = document;
for each (let [index, loginInfo] in Iterator(loginsInfo)) {
if (loginType != loginInfo.type) {
loginType = loginInfo.type;
frag.appendChild(doc.createElementNS(XULNS, "menuseparator"));
}
let menuitem = doc.createElementNS(XULNS, "menuitem");
menuitem.setAttribute("oncommand", "Ya.doLoginButtonCommand(event, 'swap')");
menuitem.setAttribute("label", loginInfo.username);
menuitem.setAttribute("disabled", loginInfo.hasAuth);
frag.appendChild(menuitem);
}
menupopup.insertBefore(frag, menuseparator);
}
return true;
},
doLoginButtonCommand: function(aEvent, aCommandType) {
let target = aEvent.target;
if (target && target.localName == "menuitem") {
switch (aCommandType) {
case "swap":
this.nsIYa.yaAuth.initLoginSwapProcess(target.getAttribute("label"));
break;
case "logout":
this.nsIYa.yaAuth.dropAllAuth();
break;
case "change":
this.openWelcomeWindow(null, null, {view:'auth'});
break;
default:
return;
}
aEvent.stopPropagation();
}
},
checkOnCommandEvent: function(aEvent) {
let target = aEvent.target;
let currentTarget = aEvent.currentTarget;
if (!(target == currentTarget || target.localName == "toolbarbutton"))
return false;
if (currentTarget.localName !== "toolbaritem" && currentTarget.localName !== "toolbarbutton")
return false;
if (target.disabled && !this.nsIYa.isLogin) {
let parentNode = target.parentNode;
while (parentNode && parentNode.localName != "toolbaritem")
parentNode = parentNode.parentNode;
if (parentNode && /yasearch\-login/.test(parentNode.getAttribute("class"))) {
let [,serviceType] = parentNode.getAttribute("id").split("-");
this.openWelcomeWindow(serviceType, target.getAttribute("id"));
return false;
}
}
return true;
},
updateServicesWork: function() {
this.refreshLoginButton();
this.redrawServicesButton();
this.refreshMailData();
this.refreshCounterData("fotki");
this.refreshCounterData("yaru");
this.refreshCounterData("moikrug");
this.refreshLentaData();
this.refreshMoneyData();
},
redrawServices: function() {
this.redrawServicesButton();
this.redrawContextMenu();
this.redrawSearchBoxPopup();
},
redrawServicesButton: function() {
let sButton = document.getElementById("yasearch-search");
if (!sButton)
return;
if (sButton.firstChild)
sButton.removeChild(sButton.firstChild);
this.nsIYa.DOMUtils.appendNode(this.nsIYa.getServicesDOMNode(), sButton);
},
showQuickTranslateItems: function(aLabel) {
if (!this.nsIYa.getBoolPref("yasearch.general.ui.quick.search"))
aLabel = false;
for each (var qtItemId in ["lingvo"]) {
var mItem = document.getElementById("yasearchQTranslateItem-" + qtItemId);
if (mItem) {
mItem.hidden = aLabel ? false : true;
if (aLabel)
mItem.setAttribute("label", this.stringBundleSet.getFormattedString("search_" + qtItemId, [aLabel]));
}
}
},
redrawContextMenu: function() {
let oldMenu = document.getElementById(this.yaContextSearchServicesId);
if (oldMenu) {
let newMenu = this.nsIYa.getDOMDocContent("menu-popup");
this.nsIYa.DOMUtils.replaceNode(newMenu, oldMenu);
}
},
getBrowserSelection: function() {
let focusedWindow = document.commandDispatcher.focusedWindow;
let selection = focusedWindow.getSelection().toString();
return this._cropSelectionText(selection);
},
_cropSelectionText: function(aString) {
const CHAR_LEN = 100;
if (aString) {
if (aString.length > CHAR_LEN) {
var pattern = new RegExp("^(?:\\s*.){0," + CHAR_LEN + "}");
pattern.test(aString);
aString = RegExp.lastMatch;
}
aString = aString.replace(/^\s+/, "").replace(/\s+$/, "").replace(/\s+/g, " ");
if (aString.length > CHAR_LEN)
aString = aString.substr(0, CHAR_LEN);
}
return aString;
},
showContextMenu: function(evt) {
if (evt.target.id != this.sContextMenu.id)
return;
let yaContextMenu = document.getElementById(this.yaContextSearchId);
let yaContextServicesMenu = document.getElementById(this.yaContextSearchServicesId);
let selectedText = "";
let target = gContextMenu.target;
if (gContextMenu.isContentSelected) {
selectedText = this.getBrowserSelection();
} else if (gContextMenu.onTextInput && !target.readOnly && target.type != "password") {
if (target.value) {
selectedText = target.value.toString().slice(target.selectionStart, target.selectionEnd);
selectedText = this._cropSelectionText(selectedText);
}
}
this.lastWord = selectedText;
if (selectedText) {
if (selectedText.length > 15)
selectedText = selectedText.substr(0, 15) + "...";
yaContextMenu.setAttribute("label", this.stringBundleSet.getFormattedString("search_yandex", [selectedText]));
yaContextServicesMenu.setAttribute("label", this.stringBundleSet.getFormattedString("search_services", [selectedText]));
}
this.showQuickTranslateItems(selectedText || false);
let hidden = !selectedText;
yaContextMenu.hidden = hidden;
yaContextServicesMenu.hidden = hidden;
let sendToItemsType = "page";
if (!!this.pageDataSender.getImageDataForContextMenu()) {
sendToItemsType = "image";
} else if (gContextMenu.isTextSelected) {
sendToItemsType = "selected";
}
let hiddenSendService = /^(chrome|file|about):$/.test(target.ownerDocument.location.protocol);
["Mail", "Yaru"].forEach(function(quickSendService) {
let item = document.getElementById("yasearchQSendTo" + quickSendService);
if (item) {
item.setAttribute("yaPageDataSendType", sendToItemsType);
item.setAttribute("label", item.getAttribute("yaLabelSend_" + sendToItemsType));
item.setAttribute("hidden", hiddenSendService || !document.getElementById("yasearch-" + quickSendService.toLowerCase()));
}
});
},
hideContextMenu: function(aEvent) {
if (aEvent.target.id != this.sContextMenu.id)
return;
this.lastWord = null;
},
contentAreaClick: function(event, fieldNormalClicks) {
if (event.isTrusted && event.button == 0 &&
!event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
var linkNode,
target = event.target;
if (target instanceof HTMLAnchorElement ||
target instanceof HTMLAreaElement ||
target instanceof HTMLLinkElement) {
if (target.hasAttribute("href"))
linkNode = target;
} else {
linkNode = event.originalTarget;
while (linkNode && !(linkNode instanceof HTMLAnchorElement))
linkNode = linkNode.parentNode;
if (linkNode && !linkNode.hasAttribute("href"))
linkNode = null;
}
if (linkNode && linkNode.href) {
var hrefStr = linkNode.href;
if (hrefStr.indexOf("mailto:") > -1 && hrefStr.indexOf("mailto:") < 7 &&
this.composeEmail(hrefStr))
return false;
}
}
return window.contentAreaClick(event, fieldNormalClicks);
},
pageDataSender: {
_storedDataToSend: null,
sendToService: function(aDestination, aEvent, aStatData) {
const LINE_BREAK = aDestination === "yaru" ? "<br/><br/>" : "\n\n";
this._storedDataToSend = null;
let sendType = "page";
if (aEvent && aEvent.target && aEvent.target.hasAttribute("yaPageDataSendType"))
sendType = aEvent.target.getAttribute("yaPageDataSendType");
let dataToSend = {
body: "",
subject: "",
title: "",
URL: ""
};
switch (sendType) {
case "page":
case "page-link":
dataToSend.subject = window.content.document.title;
if (sendType == "page") {
let metaNodes = window.content.document.getElementsByTagName("meta");
for (let i = 0, len = metaNodes.length; i < len; i++) {
let metaName = (metaNodes[i].name || "").toLowerCase();
if (metaName == "description" && metaNodes[i].content) {
dataToSend.body = metaNodes[i].content + LINE_BREAK;
break;
}
}
}
dataToSend.body += window.content.location.href;
break;
case "selected":
dataToSend.body = this.getSelectedText(aEvent);
break;
case "image":
let imgData = this.getImageDataForContextMenu();
if (imgData) {
dataToSend.body = '<img src="' + imgData.imageURL +
'" alt="' + (imgData.imageName || imgData.imageURL) +
'" title="' + imgData.imageName + '" />';
dataToSend.message_type = "html";
}
break;
default:
break;
}
if (!(dataToSend.body || dataToSend.subject))
return false;
if (!(sendType == "page" || sendType == "page-link")) {
let wp = gBrowser.currentURI;
if (wp && wp.spec && typeof wp.spec != "undefined" && !/^about/.test(wp.spec))
dataToSend.body = "Источник: " + wp.spec + LINE_BREAK + dataToSend.body;
} else if (/^about/.test(dataToSend.body)) {
dataToSend.body = null;
}
if (aDestination == "yaru") {
if (sendType == "page") {
dataToSend.URL = window.content.location.href;
delete dataToSend.body;
}
dataToSend.title = dataToSend.subject;
delete dataToSend.subject;
}
let sendObject = {
sendType: sendType,
destination: aDestination,
dataToSend: dataToSend,
statData: aStatData,
sessionRestarted: false,
url: null
};
if (aDestination == "mail" && !Ya.nsIYa.username) {
let topMFDAuth = Ya.MFD.getTopAuth();
if (topMFDAuth) {
sendObject.url = Ya.MFD.getComposeURLForDomain(topMFDAuth.domain);
if (sendObject.statData)
sendObject.statData.action = 1055;
}
}
if (/^mfd:/.test(aDestination)) {
let mfdURL = Ya.MFD.getComposeURLForDomain(aDestination.replace(/^mfd:/, ""));
if (!mfdURL)
return false;
aDestination = "mail";
sendObject.destination = aDestination;
sendObject.url = mfdURL;
if (sendObject.statData)
sendObject.statData.action = 1055;
}
if (Ya.nsIYa.username || sendObject.url) {
this._sendToServiceHepler(sendObject);
} else {
sendObject.sessionRestarted = true;
this._storedDataToSend = sendObject;
let welcomeWindow = Ya.openWelcomeWindow(aDestination);
if (welcomeWindow) {
function addUnloadListener(aTarget) {
aTarget.addEventListener("unload", function(aUnloadEvent) {
aUnloadEvent.currentTarget.removeEventListener("unload", arguments.callee, false);
if (Ya && Ya.pageDataSender)
Ya.pageDataSender.checkNeedSendData();
}, false);
}
if (welcomeWindow.document instanceof Ci.nsIDOMXULDocument) {
addUnloadListener(welcomeWindow);
} else {
welcomeWindow.addEventListener("load", function(aLoadEvent) {
aLoadEvent.currentTarget.removeEventListener("load", arguments.callee, false);
addUnloadListener(aLoadEvent.currentTarget);
}, false);
}
}
}
},
checkNeedSendData: function() {
if (this._storedDataToSend) {
this._sendToServiceHepler(this._storedDataToSend);
this._storedDataToSend = null;
}
},
_sendToServiceHepler: function(aSendObject) {
if (typeof aSendObject !== "object" || !aSendObject.dataToSend)
return false;
let url = aSendObject.url;
let login = Ya.nsIYa.username;
if (!(login || url))
return false;
if (!url) {
switch (aSendObject.destination) {
case "mail":
url = "http://" + Ya.nsIYa.getLocaleDependedUrl("MailHost") + "/compose?mailto=";
break;
case "yaru":
url = "http://" + login + ".ya.ru/posts_add_";
url += (aSendObject.sendType == "page" ? "link" : "text") + ".xml";
break;
default:
break;
}
if (!url)
return false;
aSendObject.url = url;
}
if (!url)
return false;
if (aSendObject.destination == "yaru") {
if (aSendObject.sessionRestarted)
aSendObject.url = "http://my.ya.ru/request_to_session.xml";
aSendObject.dataToSend.YARU_retpath = url;
Ya.nsIYa.xmlHttpRequest(
"http://pass.yandex.ru/?retpath=" + encodeURIComponent("http://" + login + ".ya.ru/"),
{ callbackFunc: function() { if (Ya && Ya.pageDataSender) Ya.pageDataSender._sendData(aSendObject); } }
);
return true;
}
return this._sendData(aSendObject);
},
getSelectedText: function(aEvent) {
var focusedWindow = document.commandDispatcher.focusedWindow;
if (focusedWindow == window)
focusedWindow = content;
if (!focusedWindow)
return false;
var selection = focusedWindow.getSelection();
if (selection.isCollapsed || !selection.rangeCount)
return false;
var range = selection.getRangeAt(0);
var container = range && range.commonAncestorContainer ? range.commonAncestorContainer : null;
var imgCollection = (container && container.getElementsByTagNameNS) ?
Array.slice(container.getElementsByTagNameNS(container.namespaceURI, "img")) :
[];
const TMP_ALT_ATTR_NAME = "__yasearchTmpAlt";
let i = 0;
if (imgCollection.length) {
while (imgCollection[i]) {
let img = imgCollection[i];
img.setAttribute(TMP_ALT_ATTR_NAME, img.getAttribute("alt"));
img.setAttribute("alt", "[ изображение: " + img.src + " ]");
i++;
}
}
let selectedText = selection.toString();
if (imgCollection.length) {
i = 0;
while (imgCollection[i]) {
let img = imgCollection[i];
img.setAttribute("alt", img.getAttribute(TMP_ALT_ATTR_NAME));
img.removeAttribute(TMP_ALT_ATTR_NAME);
i++;
}
}
return selectedText ? selectedText : false;
},
getImageDataForContextMenu: function() {
return this.getImageDataForNode(document.popupNode);
},
getImageDataForNode: function(aNode) {
if (aNode && aNode.nodeType == 1 && (aNode instanceof Ci.nsIImageLoadingContent) && aNode.currentURI) {
var imageURI = aNode.currentURI;
if (/file|https?/.test(imageURI.scheme)) {
var altText = (aNode.hasAttribute && aNode.hasAttribute("alt")) ? aNode.getAttribute("alt") : "";
var titleText = (aNode.hasAttribute && aNode.hasAttribute("title")) ? aNode.getAttribute("title") : "";
if (altText == imageURI.spec) altText = "";
if (titleText == imageURI.spec) titleText = "";
var imageName = (titleText.length > altText.length) ? titleText : altText;
if (imageName.length > 1000)
imageName = imageName.substr(0, 1000);
return {imageURL: imageURI.spec, imageName: imageName};
}
return null;
}
return false;
},
_sendData: function(aSendObject) {
if (!aSendObject)
return false;
var url = aSendObject.url;
var dataToSend = [];
for (var [paramName, paramValue] in Iterator(aSendObject.dataToSend)) {
if (paramName && paramValue)
dataToSend.push(paramName + "=" + encodeURIComponent(paramValue.substr(0, 1000000)));
}
var postData = null;
if (dataToSend.length) {
dataToSend = dataToSend.join("&");
if (dataToSend.length > 8192 && /^https?:\/\/mail\.yandex\./.test(url)) {
url = url.replace("/compose?", "/classic/compose?");
}
var stringStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
stringStream.setData(dataToSend, dataToSend.length);
postData = Cc["@mozilla.org/network/mime-input-stream;1"].createInstance(Ci.nsIMIMEInputStream);
postData.addHeader("Content-Type", "application/x-www-form-urlencoded");
postData.addContentLength = true;
postData.setData(stringStream);
}
Ya.loadURI(url, "tab", aSendObject.statData, postData);
}
},
_mailIntegration: {
enabled: false,
get mailUrl() {
let url;
let topMFDAuth = Ya.nsIYa.isLogin ? false : Ya.MFD.getTopAuth();
if (topMFDAuth)
url = "mail.yandex.ru/for/" + topMFDAuth.domain;
else
url = Ya.nsIYa.getLocaleDependedUrl("MailHost");
return "http://" + url + "/compose?mailto=";
},
defaultOnClick: function(aEvent) {
return window.contentAreaClick(aEvent, false);
},
yaOnClick: function(aEvent) {
return Ya.contentAreaClick(aEvent, false);
},
defaultWinObject: window.MailIntegration,
_sendText: function(aBody, aSubject) {
var dataToSend = [];
if (aBody)
dataToSend.push("body=" + encodeURIComponent(aBody.substr(0, 1000000)));
if (aSubject)
dataToSend.push("subject=" + encodeURIComponent(aSubject.substr(0, 100000)));
var postData = null;
if (dataToSend.length) {
dataToSend = dataToSend.join("&");
var stringStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
stringStream.setData(dataToSend, dataToSend.length);
postData = Cc["@mozilla.org/network/mime-input-stream;1"].createInstance(Ci.nsIMIMEInputStream);
postData.addHeader("Content-Type", "application/x-www-form-urlencoded");
postData.addContentLength = true;
postData.setData(stringStream);
}
Ya.loadURI(this.mailUrl, "tab", null, postData);
},
yaWinObject: {
sendLinkForWindow: function(aWindow) {
this.sendMessage(aWindow.location.href,
aWindow.document.title);
},
sendMessage: function(aBody, aSubject) {
Ya._mailIntegration._sendText(aBody, aSubject);
},
_launchExternalUrl: function(aURL) {
Ya._mailIntegration.defaultWinObject._launchExternalUrl(aURL);
}
}
},
composeEmail: function(aMailAddress) {
if (this.nsIYa.getBoolPref("yasearch.general.ui.mail.integration.helper.show")) {
this.nsIYa.setBoolPref("yasearch.general.ui.mail.integration.helper.show", false);
setTimeout(function(me) {
me.nsIYa.promptService.alert(window,
me.stringBundleSet.getString("MailIntegrationHelperTitle"),
me.stringBundleSet.getString("MailIntegrationHelperMessage")
)
}, 100, this);
}
let mailUrl = this._mailIntegration.mailUrl + encodeURIComponent(aMailAddress.replace(/^mailto\:/, ""));
this.loadURI(mailUrl, "tab", {action: /\/for\//.test(mailUrl) ? 1022 : 1021});
return true;
},
get mailIntegration() {
return this._mailIntegration.enabled;
},
set mailIntegration(val) {
let type = val ? "ya" : "default";
this._mailIntegration.enabled = !!val;
document.getElementById("content").onclick = this._mailIntegration[type + "OnClick"];
window.MailIntegration = this._mailIntegration[type + "WinObject"];
},
search: function(engineId, evt) {
if (!this.lastWord || this.lastWord == "")
return false;
var searchUrl = this.nsIYa.getSearchEngineUrl(engineId, this.lastWord, null, {clid:10});
if (!searchUrl)
return false;
if (this.nsIYa.prefs.searchHistoryEnabled) {
Cc["@mozilla.org/satchel/form-history;1"]
.getService(Ci.nsIFormHistory2)
.addEntry("yasearch-history", this.lastWord);
}
this.loadURI(searchUrl.url, "tab", searchUrl.statData, null, true);
return true;
},
loadService: function(aId, aURL, aEvent, aStatData) {
this.loadURI(aURL, aEvent, aStatData);
this.nsIYa.setServiceTimestamp(aId);
},
loadConditionalURI: function(aType, aEvent, aStatData) {
var url;
switch (aType) {
case "feeds":
case "lenta":
url = this.nsIYa.getLocaleDependedUrl("MailHost") + "/lenta";
break;
case "mail":
let topMFDAuth = this.nsIYa.isLogin ? false : this.MFD.getTopAuth();
if (topMFDAuth) {
url = "mail.yandex.ru/for/" + topMFDAuth.domain;
if (aStatData && aStatData.action)
aStatData.action = parseInt(aStatData.action, 10) + 5;
} else {
url = this.nsIYa.getLocaleDependedUrl("MailHost");
}
url += "/messages" + (this.nsIYa.getBoolPref("yasearch.mail.uri.open.new") ? "?extra_cond=only_new" : "");
break;
case "fotki":
var login = this.nsIYa.username;
url = "fotki.yandex.ru" + (login ? ("/users/" + encodeURIComponent(login) + "/favorites") : "");
break;
case "yaru":
var login = this.nsIYa.username;
url = login ? (encodeURIComponent(login) + ".ya.ru/replies_history_unread.xml") : "wow.ya.ru";
break;
default:
if (aType && /^\/for\//.test(aType) && this.MFD) {
if (aStatData && aStatData.action)
aStatData.action = parseInt(aStatData.action, 10) + 5;
return this.MFD.loadURI(aType, "messages", aEvent, aStatData);
}
return false;
}
return this.loadURI(url, aEvent, aStatData);
},
checkForClick: function(aEvent) {
var node = aEvent.target;
if (node.getAttribute("disabled") == "true" || !node.hasAttribute("oncommand"))
return;
var fn = new Function("event", node.getAttribute("oncommand"));
fn.call(node, aEvent);
this.closeMenus(node);
},
closeMenus: function(aNode) {
if (aNode && "tagName" in aNode) {
if (aNode.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
&& (aNode.tagName == "menupopup" || aNode.tagName == "popup"))
if (aNode.hidePopup)
aNode.hidePopup();
this.closeMenus(aNode.parentNode);
}
},
getTypeByEvent: function(evt) {
if (evt) {
if (evt == "tab" || evt == "window" || evt == "new-tab") return evt;
if (evt.shiftKey) return "window";
if (evt.ctrlKey || evt.metaKey || this.nsIYa.prefs.commandOpenTab) return "tab";
if (evt.type == "click" && evt.button == 1) return "tab";
}
return "none";
},
canLoadUrlInCurrentTab: function(aTab, aUrl) {
if (aTab.hasAttribute("busy"))
return false;
var linkedBrowser = aTab && aTab.linkedBrowser ? aTab.linkedBrowser : null;
try {
if (!linkedBrowser || linkedBrowser.currentURI.host == "yasearch")
return true;
} catch(e) {}
try {
var sh = linkedBrowser.sessionHistory;
if (!sh || sh.index < 0 || (sh.count < 2 && (!linkedBrowser.currentURI || linkedBrowser.currentURI.spec == "about:blank")))
return true;
} catch(e) {}
function getHostFromURL(url) {
const IO_SERVICE = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
try {
return IO_SERVICE.newURI(url, null, null).host;
} catch(e) {}
return null;
}
var currentHost = getHostFromURL(linkedBrowser.currentURI.spec);
var host2Load = getHostFromURL(aUrl);
if (!(currentHost && (currentHost === host2Load)))
return false;
function modifTextareasInWindow(aWin) {
var doc = aWin.document;
if (doc && ("body" in doc)) {
var i=0, textareas = doc.getElementsByTagName("textarea");
while (textareas[i]) {
var textarea = textareas[i++];
if (textarea instanceof Ci.nsIDOMHTMLTextAreaElement && textarea.defaultValue != textarea.value)
return true;
}
}
return false;
}
return modifTextareasInWindow(linkedBrowser.contentWindow) ? false : true;
},
loadURI: function(url, evt, aStatData, postData, aRespectLoadTabPref) {
this.nsIYa.checkNeedSendGuid();
if (/^mailto\:/.test(url))
return this.mailIntegration ? this.composeEmail(url) : false;
var type = this.getTypeByEvent(evt);
if (!/^[A-z]+\:\/\//.test(url))
url = "http://" + url;
if (aStatData)
url = this.nsIYa.appendStatData2Url(url, aStatData);
var currentTab;
switch (type) {
case "window":
openNewWindowWith(url);
break;
case "new-tab":
case "tab":
currentTab = gBrowser.mCurrentTab;
if (!(type == "new-tab" || evt.ctrlKey || evt.metaKey || (evt.type == "click" && evt.button == 1)) &&
this.canLoadUrlInCurrentTab(currentTab, url))
{
currentTab.linkedBrowser.loadURIWithFlags(url, Ci.nsIWebNavigation.LOAD_FLAGS_NONE, null, null, postData);
} else {
currentTab = gBrowser.loadOneTab(url, null, null, postData, (aRespectLoadTabPref ? null : false));
}
break;
default:
currentTab = gBrowser.mCurrentTab;
loadURI(url, null, postData);
}
if (aStatData && aStatData.action && currentTab && currentTab.linkedBrowser.yaSearchTHandler)
currentTab.linkedBrowser.yaSearchTHandler.actionValue = aStatData.action;
return true;
},
fixupWebURI: function(aString) {
const nsIURIFixup = Ci.nsIURIFixup;
let fixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(nsIURIFixup);
let uri = null;
try {
uri = fixup.createFixupURI(aString, nsIURIFixup.FIXUP_FLAG_NONE);
uri = uri && uri.spec && /^(ftp|https?)/.test(uri.scheme) ? uri : null;
} catch(e) {}
return uri;
},
loadURIsInTabs: function(aURIsArray) {
for each (let uriString in aURIsArray) {
let uri = this.fixupWebURI(uriString);
if (uri)
gBrowser.addTab(uri.spec);
}
},
refreshMailData: function() {
let mb = document.getElementById("yasearch-mail-menupopup");
if (!mb)
return;
while (mb.firstChild)
mb.removeChild(mb.firstChild);
let data = this.nsIYa.mailData;
if (data.nodes)
while (data.nodes.hasChildNodes())
this.nsIYa.DOMUtils.appendNode(data.nodes.firstChild, mb);
mb.parentNode.setAttribute("yaLabel", data.count > 0 ? data.count : 0);
mb.parentNode.setAttribute("yaMailType", data.type);
this._changeToolbaritemAuthState(mb.parentNode, !!(this.nsIYa.isLogin || this.nsIYa.yaMFD.isLogin));
},
clickMailButton: function(aEvent) {
if (aEvent.target.getAttribute("yaMailType") == "mfd")
this.MFD.checkMailButtonClickWarning();
Ya.loadConditionalURI("mail", aEvent, {action:1000});
},
clickMail: function(aEvent, aMailType) {
let url = aEvent.target.id;
let action = "mfd" == aMailType ? 1035 : 1030;
this.nsIYa.decMailCounter(url);
this.loadURI(url, aEvent, {action:action});
return false;
},
MFD: {
_checkDomainString: function(aDomain) {
let domain = aDomain;
if (domain.indexOf("/for/") != 0)
domain = "/for/" + domain;
return domain;
},
loadURI: function(aDomain, aLinkType, aEvent, aStatData) {
let url = "mail.yandex.ru" + this._checkDomainString(aDomain) + "/" + aLinkType;
if (aLinkType == "messages" && Ya.nsIYa.getBoolPref("yasearch.mail.uri.open.new"))
url += "?extra_cond=only_new";
return Ya.loadURI(url, aEvent, aStatData);
},
dropAuthForLogin: function(aLogin, aForgetLogin) {
Ya.nsIYa.yaMFD.dropAuthForLogin(aLogin, aForgetLogin);
},
getComposeURLForDomain: function(aDomain) {
return aDomain ? "http://mail.yandex.ru" + this._checkDomainString(aDomain) + "/compose?mailto=" : null;
},
getTopAuth: function() {
return Ya.nsIYa.yaMFD.getTopAuth();
},
checkMailButtonClickWarning: function() {
if (Ya.nsIYa.getBoolPref("yasearch.general.ui.mail.mfd.warning.show")) {
Ya.nsIYa.setBoolPref("yasearch.general.ui.mail.mfd.warning.show", false);
setTimeout(function() {
Ya.nsIYa.promptService.alert(window,
Ya.stringBundleSet.getString("MailButtonClickMFDWarningTitle"),
Ya.stringBundleSet.getString("MailButtonClickMFDWarningMessage")
)
}, 100);
}
}
},
refreshCounterData: function(aType) {
let menupopup = document.getElementById("yasearch-" + aType + "-menupopup");
if (menupopup) {
let tbb = this.nsIYa.Counters.getXULNode(aType);
menupopup.parentNode.setAttribute("yaLabel", tbb.getAttribute("yaLabel"));
while (menupopup.firstChild)
menupopup.removeChild(menupopup.firstChild);
let data = tbb.firstChild;
while (data.hasChildNodes())
this.nsIYa.DOMUtils.appendNode(data.firstChild, menupopup);
}
},
refreshLentaData: function() {
let fb = document.getElementById("yasearch-lenta-button");
if (fb) {
let data = this.nsIYa.Counters.getCount("lenta");
fb.setAttribute("yaLabel", data > 0 ? data : 0);
}
},
refreshMoneyData: function() {
let mb = document.getElementById("yasearch-money-button");
if (mb) {
let data = this.nsIYa.Counters.getCount("money");
mb.setAttribute("yaLabel", data > 0 ? data : 0);
}
},
observe: function(aSubject, aTopic, aState) {
switch (aTopic) {
case "Ya-Refresh-Services":
this.redrawServicesButton();
break;
case "Ya-Refresh-Login-Status":
this.realizeLoginBehaviour();
break;
case "Ya-Refresh-Data":
switch (aState) {
case "mfd-list":
case "mailList":
this.refreshMailData();
break;
case "allServices":
case "mailAndFeeds":
this.refreshLentaData();
this.refreshMoneyData();
this.refreshCounterData("fotki");
this.refreshCounterData("yaru");
this.refreshCounterData("moikrug");
break;
case "fotki":
case "yaru":
case "moikrug":
this.refreshCounterData(aState);
break;
case "lenta":
this.refreshLentaData();
break;
case "money":
this.refreshMoneyData();
break;
case "mail-integration":
this.mailIntegration = this.nsIYa.getBoolPref("yasearch.general.ui.mail.integration");
break;
case "services":
this.redrawServices();
break;
case "login":
this.refreshLoginButton();
break;
default:
break;
}
break;
case "Ya-Refresh-Busy-State":
let data = aState.split(":");
let state = !!(data[0] === "true");
let types = [data[1]];
for each (let type in types) {
window.setTimeout(function(aType) {
let btn = YaUtils.evaluateXPath(document, '//xul:toolbaritem[starts-with(@id,"' + aType + '")]')[0];
if (btn)
btn.setAttribute("busy", state);
}, state ? 0 : 700, type);
}
break;
}
},
openWelcomeWindow: function(aServiceType, aCallbackElementId, aExtraProps) {
const winType = "Yasearch:WelcomeDialog";
let welcomeWindow = this.nsIYa.getWindow(winType);
if (welcomeWindow) {
welcomeWindow.focus();
} else {
let flags = "chrome,alwaysRaised,dependent=yes";
if (!this.nsIYa.AppInfo.browser.isGreaterThenFx35 || this.nsIYa.AppInfo.OS.isMacOS)
flags += ",titlebar=no";
welcomeWindow = window.openDialog(YaUtils.CHROME_CONTENT + "dialogs/welcome.xul",
winType, flags, aServiceType, aCallbackElementId, aExtraProps);
}
return welcomeWindow;
},
openPrefWindow: function() {
const APP_NAME = "yasearch";
const winType = APP_NAME + ":Preferences";
let prefWindow = this.nsIYa.getWindow(winType);
if (prefWindow) {
prefWindow.focus();
} else {
let instantApply = this.nsIYa.getBoolPref("browser.preferences.instantApply");
let features = "chrome,titlebar,toolbar,centerscreen,resizable," + (instantApply ? "dialog=no" : "modal");
prefWindow = window.openDialog("chrome://" + APP_NAME + "/content/custombar/preferences/preferences.xul", winType, features);
}
return prefWindow;
},
openAboutWindow: function() {
const winType = "Yasearch:AboutDialog";
let aboutWindow = this.nsIYa.getWindow(winType);
if (aboutWindow)
aboutWindow.focus();
else
aboutWindow = window.openDialog(YaUtils.CHROME_CONTENT + "about/about.xul", winType,
"chrome,resizable=no,dependent=yes,centerscreen");
return aboutWindow;
},
log: function(msg) { this.nsIYa.log("Ya: " + msg); },
dump: function(aObj) { this.nsIYa.dump(aObj); }
};
window.addEventListener("load", function(aLoadEvent) {
aLoadEvent.currentTarget.removeEventListener("load", arguments.callee, false);
aLoadEvent.currentTarget.addEventListener("unload", function(aUnloadEvent) {
aUnloadEvent.currentTarget.removeEventListener("unload", arguments.callee, false);
Ya.unLoad();
}, false);
Ya.onLoad();
}, false);