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
/
fil2175B45BE46BA1400A4AE0901E1F58A4
< prev
next >
Wrap
Text File
|
2010-07-12
|
12KB
|
393 lines
if (typeof(Cc) === "undefined")
var Cc = Components.classes;
if (typeof(Ci) === "undefined")
var Ci = Components.interfaces;
var YaFTab = {
nsIYa: Components.classes["@yandex.ru/yasearch;1"]
.getService(Components.interfaces.nsIYaSearch)
.wrappedJSObject,
get nsIYaFTab() {
delete this.nsIYaFTab;
return this.nsIYaFTab = this.nsIYa.yaFTab;
},
get settings() {
delete this.settings;
return this.settings = this.nsIYa.yaFTab.settings;
},
get topChromeWin() {
return window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow)
},
openYandexPage: function(aEvent) {
if (aEvent) {
aEvent.stopPropagation();
aEvent.preventDefault();
}
let url = this.nsIYa.getLocaleDependedUrl("YandexWwwHost");
this.loadURI(url, aEvent || "tab", {clid:7});
return false;
},
formHistSvc: Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2),
doSearch: function(aText) {
let searchbox = document.getElementById("ftab-search-box");
let text = aText || searchbox.value || "";
if (!text.replace(/\s/g, ""))
return false;
if (this.nsIYa.prefs.searchHistoryEnabled)
this.formHistSvc.addEntry("yasearch-history", text);
let urlData = this.nsIYa.getSearchEngineUrl("www", text, null, {clid:8})
if (urlData && urlData.url)
this.loadURI(urlData.url, "tab");
},
loadURI: function(aURL, aEvent, aStatData, aPostData, aRespectLoadTabPref) {
this.topChromeWin.Ya.loadURI(aURL, aEvent, aStatData, aPostData, aRespectLoadTabPref);
},
clickThumb: function(aPageIndex, aEvent) {
if (aPageIndex >= 1 && aPageIndex <= this.settings.thumbsNmb) {
let thumb = this.thumbElements.filter(function(element) {
return aPageIndex == element.getAttribute("yaThumbIndex");
})[0];
if (thumb)
return thumb.click(aEvent);
}
return false;
},
MIN_WIDTH: 550,
onWindowResize: function() {
let width = (document.height - 115) / this.settings.screenFactor;
width = Math.min(width, window.innerWidth * 0.9);
width = parseInt(Math.max(width, this.MIN_WIDTH), 10);
[ document.getElementById("ftab-search-box"),
this.editor.getElementByAnonid("page-url") ]
.forEach(function(textbox) {
if (textbox && textbox.popupset) {
Array.slice(textbox.popupset.childNodes)
.map(function(el) {
if (el.localName=="panel" && el.hasAttribute("width"))
el.removeAttribute("width");
});
}
});
document.getElementById("table-container").style.width = width + "px";
},
onLoad: function() {
let browser = this.topChromeWin.gBrowser.getBrowserForDocument(document);
if (browser)
browser.mIconURL = document.getElementById("favicon").href;
let pagesData = this.nsIYaFTab.createTabClient(this);
let container = document.getElementById("thumbs-container");
while (container.firstChild)
container.removeChild(container.firstChild);
container.appendChild(pagesData);
this.onWindowResize();
document.getElementById("container-stack").hidden = false;
window.addEventListener("resize", this, false);
window.addEventListener("keypress", this, false);
window.addEventListener("click", this, false);
this.DragAndDrop.init();
},
onUnload: function() {
window.removeEventListener("resize", this, false);
window.removeEventListener("keypress", this, false);
window.removeEventListener("click", this, false);
this.DragAndDrop.destroy();
this.nsIYaFTab.destroyTabClient(this);
},
handleEvent: function(aEvent) {
if (!aEvent.isTrusted)
return;
switch (aEvent.type) {
case "click":
if (aEvent.button == 1) {
let node = aEvent.target;
if (node == document.getElementById("search-container-link")) {
return this.openYandexPage(aEvent);
}
let level = 0;
while (level++ < 10 && node && !("click" in node)) {
node = node.parentNode;
}
if (node && "click" in node)
node.click(aEvent);
}
break;
case "keypress":
if (aEvent.altKey && aEvent.keyCode && !(aEvent.ctrlKey || aEvent.metaKey)) {
let page = aEvent.keyCode - (aEvent.keyCode > 96 ? 96 : 48);
if (this.clickThumb(page)) {
aEvent.preventDefault();
aEvent.stopPropagation();
}
}
break;
case "resize":
setTimeout(function(me) {me.onWindowResize();}, 50, this);
break;
default:
break;
}
},
get thumbElements() {
let res = Array.slice(document.getElementById("thumbs-container")
.getElementsByClassName("thumb-holder"));
return res;
},
getPageProps: function(aData) {
let index = (aData instanceof HTMLElement) ? aData.getAttribute("yaThumbIndex") : aData;
return this.nsIYaFTab.getPageProps(index);
},
observe: function(aTopic, aData) {
switch (aTopic) {
case "UPDATE_PROPS":
if (aData && (aData.url || aData.pageIndex)) {
let url = aData.url;
let pageIndex = aData.pageIndex;
this.thumbElements.filter(function(element) {
return (pageIndex && pageIndex == element.getAttribute("yaThumbIndex")) ||
(url && url == element.getAttribute("href"));
})
.forEach(function(element) {
element.updateProps(this.getPageProps(element));
}, this);
if (url === this.editor.thumbHolder.getAttribute("href")) {
this.hanleNewURL(url, false);
}
}
break;
default:
break;
}
},
DragAndDrop: {
_isInited: false,
init: function() {
if (this._isInited)
return;
window.addEventListener("draggesture", this, false);
window.addEventListener(Ci.nsIDOMDataTransfer ? "drop" : "dragdrop", this, false);
window.addEventListener("dragover", this, false);
this._isInited = true;
},
destroy: function() {
if (!this._isInited)
return;
window.removeEventListener("draggesture", this, false);
window.removeEventListener(Ci.nsIDOMDataTransfer ? "drop" : "dragdrop", this, false);
window.removeEventListener("dragover", this, false);
this._isInited = false;
},
handleEvent: function(aEvent) {
if (!aEvent.isTrusted)
return;
switch (aEvent.type) {
case "draggesture":
let target = this._getThumbHolderFromEvent(aEvent);
let fakeDragEvent = target === aEvent.target ? aEvent : {
screenX: aEvent.screenX,
screenY: aEvent.screenY,
target: target,
originalTarget: target,
stopPropagation: function() {},
dataTransfer: aEvent.dataTransfer
}
nsDragAndDrop.startDrag(fakeDragEvent, this);
aEvent.stopPropagation();
break;
case "dragdrop":
case "drop":
nsDragAndDrop.drop(aEvent, this);
break;
case "dragover":
nsDragAndDrop.dragOver(aEvent, this);
break;
default:
break;
}
},
_getThumbHolderFromEvent: function(aEvent) {
let target = aEvent.target;
while (target && !(target.localName == "a" && target.getAttribute("class") == "thumb-holder"))
target = target.parentNode;
return target && target.localName == "a" ? target : null;
},
_getPageAttributeFromEvent: function(aAttrName, aEvent) {
let thumbHolder = this._getThumbHolderFromEvent(aEvent);
return thumbHolder ? thumbHolder.getAttribute(aAttrName) : null;
},
getSupportedFlavours: function() {
let flavourSet = new FlavourSet();
flavourSet.appendFlavour("yaftab/page-index");
return flavourSet;
},
onDragStart: function(aEvent, aXferData, aDragAction) {
let index = this._getPageAttributeFromEvent("yaThumbIndex", aEvent);
if (!index)
return;
aXferData.data = new TransferData();
aXferData.data.addDataForFlavour("yaftab/page-index", index);
let href = this._getPageAttributeFromEvent("href", aEvent);
if (href) {
aXferData.data.addDataForFlavour("text/unicode", href);
aXferData.data.addDataForFlavour("text/x-moz-url", href);
}
},
onDragOver: function(aEvent, aFlavour, aSession) {},
onDrop: function(aEvent, aXferData, aSession) {
if (aXferData.flavour.contentType !== "yaftab/page-index")
return;
let xferData = aXferData.data.split("\n");
let fromIndex = parseInt(xferData[0],10);
if (!fromIndex)
return;
let toIndex = this._getPageAttributeFromEvent("yaThumbIndex", aEvent);
if (!toIndex)
return false;
aEvent.preventDefault();
YaFTab.nsIYaFTab.swapPages(fromIndex, toIndex);
}
},
getSitesFromHistory: function(aOnComplete) {
return this.nsIYaFTab.getSitesFromHistory(20, aOnComplete);
},
get editor() {
delete this.editor;
return this.editor = document.getElementById("editor");
},
showEditorForPage: function(aPageIndex) {
this.editor.open(aPageIndex, this.nsIYaFTab.getPageProps(aPageIndex));
},
onEditorCallback: function(aPageIndex, aPageData, aOpenTimestamp) {
if (aPageData) {
this.nsIYaFTab.setPageProps(aPageIndex, aPageData, {checkedTimeMin: aOpenTimestamp});
}
},
hanleNewURL: function(aURL, aRefreshData) {
let props = this.nsIYaFTab.getPropsForURL(aURL, aRefreshData);
let editor = this.editor;
editor.setText("title", props.title || "", true);
props.title = editor.getText("title");
editor.thumbHolder.updateProps(props);
},
getURLFromString: function(aString) {
return this.nsIYaFTab.getURLFromString(aString);
},
get stringBundleSet() {
delete this.stringBundleSet;
let sbs = Cc["@mozilla.org/intl/stringbundle;1"].createInstance(Ci.nsIStringBundleService);
return this.stringBundleSet = sbs.createBundle("chrome://yasearch/locale/ftab/ftab.properties");
},
removePage: function(aPageIndex) {
let props = this.nsIYaFTab.getPageProps(aPageIndex);
let pageTitle = props ? (props.title || props.url || "") : "";
let confirmTitle = this.stringBundleSet.GetStringFromName("dialogTitle");
let confirmMessage = this.stringBundleSet.GetStringFromName("thumbRemoveLabel");
if (pageTitle) {
if (pageTitle.length > 300)
pageTitle = pageTitle.substr(0, 300) + "...";
confirmMessage += " " + this.stringBundleSet.formatStringFromName("thumbRemoveLabelTitle", [pageTitle], 1);
}
confirmMessage += "?";
let rv = this.nsIYa.promptService.confirm(window, confirmTitle, confirmMessage);
if (rv)
this.nsIYaFTab.removePage(aPageIndex);
}
};
window.addEventListener("pageshow", function(aLoadEvent) {
aLoadEvent.currentTarget.addEventListener("pagehide", function(aUnloadEvent) {
YaFTab.onUnload();
}, false);
YaFTab.onLoad();
}, false);