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
/
fil50CE460251CCEB561279D710FF0C811D
< prev
next >
Wrap
Text File
|
2010-07-12
|
13KB
|
380 lines
if (!YaUtils) {
if (typeof(Cc) === "undefined")
var Cc = Components.classes;
if (typeof(Ci) === "undefined")
var Ci = Components.interfaces;
var YaUtils = {
CHROME_CONTENT: "chrome://yasearch/content/",
get nsUtils() {
delete this.nsUtils;
return this.nsUtils = Cc["@yandex.ru/yasearch;1"].getService(Ci.nsIYaSearch)
.wrappedJSObject
.utils;
},
get nsDOMUtils() {
delete this.nsDOMUtils;
return this.nsDOMUtils = Cc["@yandex.ru/yasearch;1"].getService(Ci.nsIYaSearch)
.wrappedJSObject
.DOMUtils;
},
convertStringToUnicode: function(aString, aCharset) {
var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = aCharset || "windows-1251";
return converter.ConvertToUnicode(aString);
},
evaluateXPath: function(aNode, aExpr) {
return this.nsDOMUtils.evaluateXPath(aNode, aExpr);
},
RegExp: {
_escapeRe: /([.*+?^=!:${}()|[\]\/\\])/g,
escape: function(aString) {
return String(aString).replace(this._escapeRe, '\\$1');
},
createFromString: function(aString, aFlags) {
return new RegExp(this.escape(aString), aFlags);
}
},
searchWordsRe: {
_phrasesRe: {},
hostRe: new RegExp("(?:^|\.)(yandex|google|rambler|aport|mail|gogo|nigma|yahoo|msn|live|bing)\.(?:com|ru|ua|kz|by)$", "i"),
getPhraseRe: function(aHost) {
if (!this._phrasesRe[aHost]) {
var q = "q";
switch (aHost) {
case "yandex": q = "text"; break;
case "rambler": q = "(?:query|words)"; break;
case "aport": q = "r"; break;
case "yahoo": q = "p"; break;
}
this._phrasesRe[aHost] = new RegExp("[\?&](?:" + q + ")=([^#&\?]*)");
}
return this._phrasesRe[aHost];
}
},
getSearchTextFromLocation: function(aLocation, aWebProgress) {
var locationHost, res = false;
try {
locationHost = aLocation.host;
} catch(e) {}
if (locationHost && locationHost.match(this.searchWordsRe.hostRe) &&
aLocation.path.match(this.searchWordsRe.getPhraseRe(RegExp.$1))) {
var t = (RegExp.$1).replace(/\+/g, " ");
try {
res = decodeURIComponent(t);
if (/^\!?link=".*"$/.test(res))
res = false;
} catch(e) {
try {
t = unescape(t);
if (/[а-ё]/i.test(t)) {
res = t;
} else {
var charset = (aWebProgress && aWebProgress.document.characterSet.toLowerCase() == "koi8-r") ?
"koi8-r" : null;
t = this.convertStringToUnicode(t, charset);
res = /[а-ё]/i.test(t) ? t : false;
}
} catch(ex) {}
}
if (res && res[0] == "#" && /maps\.yandex/.test(locationHost))
res = false;
}
return res;
},
getSearchTextFromWebProgress: function(aWebProgress) {
var searchTextReferring = this.getSearchTextFromLocation(aWebProgress.referringURI, aWebProgress);
if (!searchTextReferring)
return false;
if (this.getSearchTextFromLocation(aWebProgress.currentURI, aWebProgress))
return false;
try {
var currentHost = aWebProgress.currentURI.host;
var referringHost = aWebProgress.referringURI.host;
var yandexHostRegExp = /(^|\.)yandex\.(ru|ua|kz|by|com)$/;
if (currentHost === referringHost ||
(yandexHostRegExp.test(currentHost) && yandexHostRegExp.test(referringHost)))
return false;
} catch(e) {}
return searchTextReferring;
},
get KeyCorrector() {
delete this.KeyCorrector;
var nsKeyCorrector = Cc["@yandex.ru/yasearch;1"].getService(Ci.nsIYaSearch)
.wrappedJSObject.KeyCorrector;
this.KeyCorrector = function(aTextbox) {
this.__textbox = aTextbox;
this.__allowedTooltipText = aTextbox.getAttribute("yaAllowedTooltiptext") || "";
this.__allowedTooltip = null;
this.__allowedTooltipTimer = null;
this.__lastKey = null;
this.init();
};
this.KeyCorrector.prototype = {
_regexpNames: ["Value", "ValueFinal", "Chars"],
_keyConvTable: nsKeyCorrector.keyConvTable,
_charConvTable: nsKeyCorrector.charConvTable,
_setListeners: function(aAdd) {
var fn = aAdd ? "addEventListener" : "removeEventListener";
var events = [ ["keypress", true], ["keydown", false] ];
if (this.__allowedCharsRE)
events.push(["input", false]);
if (this.__allowedTooltipText)
events.push(["blur", false]);
events.forEach(function(ev) {
this.__textbox[fn](ev[0], this, ev[1], true);
}, this);
this.__textbox.ownerDocument.defaultView[fn]("unload", this, false, true);
},
init: function() {
this._regexpNames.forEach(function(aReName) {
var attrName = "yaAllowed" + aReName;
var attrValue = this.__textbox.getAttribute(attrName);
this["__allowed" + aReName + "RE"] = attrValue ? new RegExp(attrValue) : null;
}, this);
this._setListeners(true);
var me = this;
this.__textbox.yaValueIsNotValid = function(aShowTooltip) {
if (me.__allowedValueFinalRE && !me.__allowedValueFinalRE.test(this.value)) {
if (aShowTooltip === true)
me.showAllowedTooltip();
return true;
}
return false;
}
},
destroy: function() {
this.__textbox.yaValueIsNotValid = null;
this._setListeners(false);
this._regexpNames.forEach(function(aReName) {
this["__allowed" + aReName + "RE"] = null;
}, this);
this.__allowedTooltipText = null;
if (this.__allowedTooltip) {
this.hideAllowedTooltip();
this.__allowedTooltip.parentNode.removeChild(this.__allowedTooltip);
this.__allowedTooltip = null;
}
},
get allowedTooltip() {
if (this.__allowedTooltip === null) {
this.__allowedTooltip = false;
if (this.__allowedTooltipText) {
var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var doc = this.__textbox.ownerDocument;
var tt = doc.createElementNS(XULNS, "tooltip");
tt.setAttribute("orient", "vertical");
var description = doc.createElementNS(XULNS, "description");
description.textContent = this.__allowedTooltipText;
tt.appendChild(description);
this.__allowedTooltip = tt;
this.__textbox.parentNode.appendChild(tt);
}
}
return this.__allowedTooltip;
},
set allowedTooltip() {
if (this.__allowedTooltip) {
this.hideAllowedTooltip();
this.__allowedTooltip.parentNode.removeChild(this.__allowedTooltip);
}
this.__allowedTooltip = null;
},
hideAllowedTooltip: function() {
var tt = this.allowedTooltip;
if (!tt || !("openPopup" in tt))
return;
if (this.__allowedTooltipTimer) {
this.__allowedTooltipTimer.cancel();
this.__allowedTooltipTimer = null;
}
if ("hidePopup" in tt)
tt.hidePopup();
},
showAllowedTooltip: function() {
var tt = this.allowedTooltip;
if (!tt || !("openPopup" in tt))
return;
this.hideAllowedTooltip();
tt.openPopup(this.__textbox, "overlap", 0, 7, false, null);
this.__allowedTooltipTimer = new YaUtils.nsUtils.G_Timer(
function() {
if (tt)
tt.hidePopup();
}, 10000
);
},
_fireInsertCommand: function(aData) {
try {
var command = "cmd_insertText";
var controller = document.commandDispatcher.getControllerForCommand(command);
if (controller && controller.isCommandEnabled(command)) {
controller = controller.QueryInterface(Ci.nsICommandController);
var params = Cc["@mozilla.org/embedcomp/command-params;1"].createInstance(Ci.nsICommandParams);
params.setStringValue("state_data", aData);
controller.doCommandWithParams(command, params);
return true;
}
} catch(e) {}
return false;
},
handleEvent: function(aEvent) {
if (aEvent.isTrusted === true && !(aEvent.ctrlKey || aEvent.altKey || aEvent.metaKey)) {
switch (aEvent.type) {
case "input":
var _re = this.__allowedCharsRE;
if (_re) {
this.hideAllowedTooltip();
var tbvalueCurrent = this.__textbox.value;
if (tbvalueCurrent) {
function convert(match) {
return _re.test(match) ? match : "";
}
var tbvalueFiltered = tbvalueCurrent.replace(/./g, convert);
if (tbvalueFiltered !== tbvalueCurrent) {
this.__textbox.value = tbvalueFiltered;
this.showAllowedTooltip();
}
}
}
break;
case "keydown":
this.__lastKey = aEvent.keyCode;
break;
case "keypress":
var res = false;
var cancelEvent = false;
if (aEvent.charCode) {
var shiftKey = aEvent.shiftKey;
var strFromCode = String.fromCharCode(aEvent.charCode);
if (this._keyConvTable) {
if ((shiftKey && strFromCode.toUpperCase() != strFromCode) ||
(!shiftKey && strFromCode.toLowerCase() != strFromCode))
{
shiftKey = !shiftKey;
}
var chCode = shiftKey ?
this._keyConvTable.withShift[this.__lastKey] :
this._keyConvTable.withoutShift[this.__lastKey];
res = (chCode && chCode != aEvent.charCode) ? String.fromCharCode(chCode) : false;
} else {
res = (shiftKey ? this._charConvTable.withShift[strFromCode.toLowerCase()]||false : false) ||
this._charConvTable.withoutShift[strFromCode]||false;
}
if (this.__allowedCharsRE) {
var str = res || strFromCode;
if (str && !this.__allowedCharsRE.test(str)) {
res = false;
cancelEvent = true;
this.showAllowedTooltip();
}
}
}
if (res && this._fireInsertCommand(res))
cancelEvent = true;
if (cancelEvent) {
aEvent.preventDefault();
aEvent.stopPropagation();
}
break;
case "blur":
this.hideAllowedTooltip();
break;
case "unload":
this.destroy();
break;
default:
break;
}
}
}
};
return this.KeyCorrector;
}
};
Components.utils.import("resource://yasearch/JSON.jsm", YaUtils);
}