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
/
fil43115CFC30D3CF3E477A10C17FEB7D1B
< prev
next >
Wrap
Text File
|
2010-07-12
|
13KB
|
400 lines
(function () {
var YaBloggers = {
nsIYa: Cc["@yandex.ru/yasearch;1"].getService(Ci.nsIYaSearch).wrappedJSObject,
SHOW_VALUE_PREF_NAME: "yasearch.general.ui.show.bloggers.value",
onWindowLoad: function() {
let URLInfo = this.nsIYa.yaURLInfo;
["UNKNOWN", "TIMED_REQUEST", "REQUEST", "ERROR", "RESPONSE"]
.forEach(function(aStateName) {
let stateName = "BLOGGERS_STATE_" + aStateName;
this[stateName] = URLInfo[stateName];
}, this);
this.showHideCounterLabel();
Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranchInternal)
.addObserver(this.SHOW_VALUE_PREF_NAME, this, false);
Ya.Bloggers = this;
this._Bloggers = this.nsIYa.Bloggers;
let prefs = this.nsIYa.getCharPref("yasearch.bloggers.ui.prefs");
if (prefs) {
prefs = prefs.split(",");
let x = parseInt(prefs[0], 10);
if (isNaN(x)) x = 0;
let y = parseInt(prefs[1], 10);
if (isNaN(y)) y = 0;
this.savedPosition = {x:x, y:y};
}
let container = getBrowser().mTabContainer;
container.addEventListener("select", this, true);
container.addEventListener("TabClose", this, false);
this.refreshData();
this.checkWindowVisible();
let bloggersMenuPopup = this.bloggersMenuPopup;
if (bloggersMenuPopup)
bloggersMenuPopup.addEventListener("popupshowing", this, true);
},
onWindowUnload: function() {
let bloggersMenuPopup = this.bloggersMenuPopup;
if (bloggersMenuPopup)
bloggersMenuPopup.removeEventListener("popupshowing", this, true);
Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranchInternal)
.removeObserver(this.SHOW_VALUE_PREF_NAME, this);
if (this.savedPosition)
this.nsIYa.setCharPref("yasearch.bloggers.ui.prefs", this.savedPosition.x + "," + this.savedPosition.y);
let container = getBrowser().mTabContainer;
container.removeEventListener("select", this, true);
container.removeEventListener("TabClose", this, false);
if (this.win && "close" in this.win)
this.win.close();
this.win = null;
this._Bloggers = null;
Ya.Bloggers = null;
},
get bloggersButton() {
return document.getElementById("yasearch-bloggers-button");
},
get bloggersMenuPopup() {
return document.getElementById("yasearch-bloggers-menupopup");
},
showHideCounterLabel: function() {
let bloggersButton = this.bloggersButton;
if (bloggersButton) {
let show = this.nsIYa.getBoolPref(this.SHOW_VALUE_PREF_NAME);
bloggersButton.setAttribute("yaLabelHidden", !show);
}
},
observe: function(aSubject, aTopic, aData) {
if (aTopic === "nsPref:changed") {
if (aData == this.SHOW_VALUE_PREF_NAME)
this.showHideCounterLabel();
}
},
openLink: function(aEvent) {
let urlData = this.nsIYa.yaURLInfo.getURL(gBrowser.currentURI);
if (urlData) {
let url = urlData.prePath + urlData.nonQueryPath;
url = "http://blogs.yandex.ru/search.xml?text=" + encodeURIComponent('!link="' + url + '"');
Ya.loadURI(url, "new-tab", {action:3300});
}
},
findParentByLocalName: function(aNode, aLocalName) {
let parent = aNode;
let names = [].concat(aLocalName);
while (parent) {
for (let i = 0; i < names.length; ++i) {
if (parent.localName == names[i])
return parent;
}
parent = parent.parentNode;
}
return null;
},
get winForMouseEvents() {
return ("close" in this.win) ? this.win : window;
},
handleEvent: function(aEvent) {
switch (aEvent.type) {
case "select":
this.showHide(document.getElementById("yasearch-bloggers") ?
this._Bloggers.isWindowVisible(gBrowser.selectedTab) :
false);
break;
case "TabClose":
this._Bloggers.clearTabData(aEvent.target.linkedPanel);
break;
case "mousemove":
let eventPoints = {x: aEvent.screenX, y: aEvent.screenY};
let ts = Date.now();
if (ts - this.lastTS < 7)
return;
this.lastTS = ts;
let diff = {
x: this.lastXY.x - eventPoints.x,
y: this.lastXY.y - eventPoints.y
};
if (diff.x == 0 && diff.y == 0)
return;
this.handleMouseMove(diff);
this.lastXY = eventPoints;
break;
case "mousedown":
var originalTarget = aEvent.originalTarget;
if (aEvent.button == 0 &&
this.findParentByLocalName(originalTarget, "yawintitle") &&
originalTarget.localName != "toolbarbutton") {
this.lastXY = {x: aEvent.screenX, y: aEvent.screenY};
this.lastTS = Date.now();
var w = this.winForMouseEvents;
w.addEventListener("mouseup", this, false);
w.addEventListener("mousemove", this, false);
}
break;
case "mouseup":
var w = this.winForMouseEvents;
w.removeEventListener("mouseup", this, false);
w.removeEventListener("mousemove", this, false);
this.checkWindowVisible();
break;
case "click":
var url = this.getUrlValue(aEvent.target);
if (url)
Ya.loadURI(url, "tab");
break;
case "resize":
this.checkWindowVisible();
break;
case "popupshowing":
let disabled = false;
let bloggersButton = this.bloggersButton;
if (bloggersButton && parseInt(bloggersButton.getAttribute("yaLabel"), 10) == 0) {
let currentURI = gBrowser.currentURI;
disabled = !(currentURI && /https?/.test(currentURI.scheme));
}
let menuitems = aEvent.target.getElementsByTagName("menuitem");
for (let i = 0, len = menuitems.length; i < len; i++)
menuitems[i].disabled = disabled;
break;
default:
break;
}
},
getUrlValue: function(aNode) {
let node = aNode;
while (node && "hasAttribute" in node) {
if (node.hasAttribute("url"))
return node.getAttribute("url");
node = node.parentNode;
}
return null;
},
hboxPopupShowing: function(aTooltip) {
let url = this.getUrlValue((("close" in this.win) ? this.win.document : document).tooltipNode);
return url ? aTooltip.firstChild.setAttribute("value", url) : false;
},
checkWindowState: function() {
if (this.win && !document.getElementById("yasearch-bloggers"))
this.hide();
},
changeMode: function(aMode) {
let mode = this._Bloggers.switchWindowMode(aMode) ? "top" : "bottom";
this.getWindowElement("yasearch-blogger-window-title").setAttribute("mode", mode);
if (mode == "bottom" && !this._Bloggers.isWindowVisible(gBrowser.selectedTab))
this.showHide(false);
},
hide: function(aButton) {
this._Bloggers.hideTopModeWindow();
this.changeMode(false);
this.showHide(false);
},
refreshData: function(aSkipCache, aTimeout, aManual) {
if (document.getElementById("yasearch-bloggers"))
this._Bloggers.getBloggersData(gBrowser.selectedTab, aSkipCache, aTimeout, aManual);
},
setData: function(aData, aCheckWindowState) {
let selIndex = 3,
bbutton = this.bloggersButton;
let count = aData ? aData.value : 0;
if (bbutton) {
let yaIconAttr = 0;
if (count) {
yaIconAttr = 1;
[0,100,1000,10000]
.every(function(aValue) {
return count > aValue ? !!yaIconAttr++ : false;
});
}
bbutton.setAttribute("yaLabel", count || 0);
bbutton.setAttribute("yaIcon", yaIconAttr);
let container = this.getWindowElement("yasearch-blogger-content-2");
let scroll = this.getWindowElement("yasearch-blogger-content-scroll");
if (scroll) {
if (scroll.scrollBoxObject && scroll.hasAttribute("location")) {
try {
let yPos = {};
scroll.scrollBoxObject.getPosition({}, yPos);
this._Bloggers.persistScrollPosition(scroll.getAttribute("location"), yPos.value);
} catch(e) {}
}
container.removeChild(container.firstChild);
}
if (aData) {
if ((aData.buttonState & this.BLOGGERS_STATE_UNKNOWN) || aData.value === 0) {
selIndex = 3;
} else if (aData.buttonState & this.BLOGGERS_STATE_REQUEST) {
selIndex = 0;
} else if ((aData.windowState & this.BLOGGERS_STATE_TIMED_REQUEST) || (aData.windowState & this.BLOGGERS_STATE_REQUEST)) {
selIndex = 1;
} else if ((aData.windowState & this.BLOGGERS_STATE_RESPONSE) && aData.content) {
selIndex = 2;
let s = this.nsIYa.DOMUtils.replaceChildNodes(aData.content, container);
if (aData.scroll) {
setTimeout(function() {
s.firstChild.scrollByPixels(aData.scroll);
}, 0);
}
} else if ((aData.buttonState & this.BLOGGERS_STATE_ERROR) || (aData.windowState & this.BLOGGERS_STATE_ERROR)) {
selIndex = 4;
}
}
}
selIndex = "" + selIndex;
let content = this.getWindowElement("yasearch-blogger-content");
if (content && content.selectedIndex != selIndex)
content.setAttribute("selectedIndex", selIndex);
if (aData && aCheckWindowState &&
count && this.getWindowElement("yasearch-blogger-content") &&
(aData.buttonState & this.BLOGGERS_STATE_RESPONSE) &&
(aData.windowState & this.BLOGGERS_STATE_UNKNOWN))
{
this._Bloggers.getBloggersData(gBrowser.selectedTab);
}
},
onTooltipShowing: function(aEvent) {
if (document.tooltipNode.tagName != "toolbarbutton")
return false;
let bloggersButton = this.bloggersButton;
if (!bloggersButton)
return false;
let bloggersCount = parseInt(bloggersButton.getAttribute("yaLabel"),10);
document.getElementById("yasearch-bloggers-tooltip-deck").selectedIndex = bloggersCount > 0 ? 1 : 0;
document.getElementById("yasearch-bloggers-tooltip-count").setAttribute("value", bloggersCount);
return true;
},
savedPosition: null,
getWindowElement: function(aId) {
return this.win ? this.win.document.getElementById(aId) : null;
},
handleMouseMove: function(aDiff) {
this.win.BloggersWindow.handleMouseMove(aDiff);
},
checkWindowVisible: function() {
if (this.win)
this.win.BloggersWindow.checkWindowVisible();
},
showHide: function(aState) {
let visible = (typeof aState == "undefined") ? !this.win : aState;
if (typeof aState == "undefined" || !visible)
this._Bloggers.persistWindowVisible(gBrowser.selectedTab, visible);
if (visible) {
if (!this.win) {
let flags = "chrome,dependent=yes";
if (!this.nsIYa.AppInfo.OS.isWindows)
flags += ",popup=yes";
if (!this.nsIYa.AppInfo.browser.isGreaterThenFx35)
flags += ",titlebar=no";
this.win = this.nsIYa.windowWatcher.openWindow(window,
"chrome://yasearch/content/bloggers/bloggers.xul",
"_blank", flags, null);
}
} else if (this.win) {
if (typeof aState == "undefined") {//toolbarbutton.@oncommand
this.hide();
} else {
this.win.close();
this.win = null;
}
}
}
}
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);
YaBloggers.onWindowUnload();
}, false);
YaBloggers.onWindowLoad();
}, false);
})();