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
/
fil8804DAAB017ADF30C02527628F44E55F
< prev
next >
Wrap
Text File
|
2010-07-12
|
22KB
|
765 lines
var gYaBookmarks = {
_init: function() {
OBSERVER_SERVICE.addObserver(this, "quit-application-granted", false);
OBSERVER_SERVICE.addObserver(this, "Ya-Refresh-Login-Status", false);
},
_uninit: function() {
OBSERVER_SERVICE.removeObserver(this, "Ya-Refresh-Login-Status");
OBSERVER_SERVICE.removeObserver(this, "quit-application-granted");
},
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case "Ya-Refresh-Login-Status":
this.refreshBookmarksDOMMenu();
break;
case "quit-application-granted":
this._uninit();
break;
}
},
refreshBookmarksDOMMenu: function() {
this.bookmarksCache.clear();
gYaSearchService.bookmarksDOMMenu = false;
OBSERVER_SERVICE.notifyObservers(null, "Ya-Refresh-Data", "bookmarks");
},
__isRegRequired: false,
get isRegRequired() {
return !!this.__isRegRequired;
},
set isRegRequired(val) {
if (this.__isRegRequired !== null)
this.__isRegRequired = val;
return this.__isRegRequired;
},
getServerResponse: function(aResponseString) {
var result = {
xml: gYaSearchService.safeE4Xml(gYaSearchService.safeUnicode(aResponseString), null, ["page", "yaru"]),
error: 0
};
if (!result.xml || result.xml.xscript_invoke_failed.length()) {
result.error = "service";
} else if (result.xml.err.length()) {
var err = result.xml.err[0];
if ("spam" === err.@code.toString()) {
result.error = "spam";
} else {
switch (err.toString()) {
case "Exception: input":
result.error = "input";
break;
case "Exception: auth_required":
result.error = "auth_required";
break;
case "Exception: reg_required":
result.error = "reg_required";
this.isRegRequired = true;
break;
case "Exception: wow":
if (!result.xml.has_not_journal.length())
result.error = "wow_error";
break;
case "Exception: service":
default:
result.error = "service";
break;
}
}
}
return result;
},
get bookmarksXML() {
return gYaSearchService.bookmarksRawXml.bookmarks;
},
_getHostForBookmarkedCheck: function(aURI) {
var res = "";
try {
if ("scheme" in aURI && /ftp|https?/.test(aURI.scheme))
res = [aURI.scheme, "://", (aURI.scheme == "file" ? "/" : ""), aURI.hostPort].join("");
} catch(e) {}
return res;
},
_getUrlSpecForBookmarkedCheck: function(aURI) {
var res = "";
try {
if ("scheme" in aURI && /ftp|https?/.test(aURI.scheme))
res = [this._getHostForBookmarkedCheck(aURI), aURI.path].join("").replace(/(\/|#.+)+$/, "");
} catch(e) {}
return res;
},
bookmarksCache: {
_maxLength: 100,
_bookmarksData: [],
_notifyObservers: function(aBookmarkURL) {
OBSERVER_SERVICE.notifyObservers(null, "Ya-Refresh-Data", "bookmarks-url-status");
},
add: function(aBookmarkData, aNotifyObservers) {
var url = aBookmarkData.url;
var exists = this._bookmarksData.some(function(bmData) { return url === bmData.url; });
if (!exists) {
this._bookmarksData.splice(this._maxLength);
this._bookmarksData.unshift(aBookmarkData);
if (aNotifyObservers)
this._notifyObservers();
}
},
remove: function(aBookmarkURL, aNotifyObservers) {
this._bookmarksData = [bmData for each (bmData in this._bookmarksData) if (aBookmarkURL !== bmData.url)];
if (aNotifyObservers)
this._notifyObservers();
},
clear: function() {
this._bookmarksData = [];
this._notifyObservers();
},
getData: function(aBookmarkURL) {
var bmData = this._bookmarksData.filter(function(bmData) { return aBookmarkURL === bmData.url; });
return bmData.length ? bmData[0] : null;
}
},
isBookmarkedURIinCache: function(aURI) {
var url = this._getUrlSpecForBookmarkedCheck(aURI);
if (!url)
return false;
var res = this.bookmarksCache.getData(url);
return res ? res.bookmarked : null;
},
isBookmarkedURI: function(aURI) {
var res = false;
var id = null,
folderId = null;
var url = this._getUrlSpecForBookmarkedCheck(aURI);
if (url) {
if (this._addBookmarkQueue.hasBookmarkForURL(url)) {
res = "adding";
} else if (this.bookmarksXML) {
var regexpUrl = new RegExp(url.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1')
.replace(/(https?\\:\\\/\\\/)(www\\.)?/, '$1(www\\.)?'));
var bookmarkedLink = false;
for each (var link in this.bookmarksXML..link.(regexpUrl.test(@url))) {
var endOfUrl = link.@url.split(regexpUrl).pop();
if (endOfUrl && !(/^\/$/.test(endOfUrl) || /^\/?#/.test(endOfUrl)))
continue;
bookmarkedLink = link;
break;
}
if (bookmarkedLink) {
res = "url";
id = bookmarkedLink.@id.toString();
folderId = 0;
}
}
}
res = { url: url,
id: id,
folderId: folderId,
bookmarked: res }
this.bookmarksCache.add(res);
return res;
},
getBrowserPageData: function(aBrowser) {
var res = {url: "", name: "", descr: ""};
var url = this._getUrlSpecForBookmarkedCheck(aBrowser.currentURI);
if (!/^about:/.test(url)) {
res.url = url;
res.name = aBrowser.contentTitle;
var metaNodes = aBrowser.contentDocument.defaultView.document.getElementsByTagName("meta");
for (var i = 0, len = metaNodes.length; i < len; i++) {
var metaName = (metaNodes[i].name || "").toLowerCase();
if (metaName == "description" && metaNodes[i].content) {
res.descr = metaNodes[i].content;
break;
}
}
}
return res;
},
_addBookmarkQueue: {
_elements: [],
_elementsAfterError: [],
get size() {
return this._elements.length;
},
get isEmpty() {
return !this.size;
},
get isBusy() {
return this._isBusy;
},
hasBookmarkForURL: function(aURL) {
for each (var bookmarkData in this._elements.concat(this._elementsAfterError))
if (bookmarkData.url == aURL)
return true;
return false;
},
clear: function() {
this._elements = [];
this._elementsAfterError = [];
this._isBusy = false;
},
push: function(aBookmarkData) {
if (this.hasBookmarkForURL(aBookmarkData.url))
return false;
this._elements.push(aBookmarkData);
gYaBookmarks.bookmarksCache.remove(aBookmarkData.url, true);
this._checkNeedProccess();
return true;
},
shift: function() {
return this._elements.shift();
},
get topElement() {
return this._elements[0];
},
_checkNeedProccess: function() {
if (this.isBusy)
return false;
if (this.isEmpty) {
var elementsAfterError = this._elementsAfterError;
this.clear();
gYaBookmarks.bookmarksCache.clear(true);
if (elementsAfterError.length) {
if (elementsAfterError.length == 1) {
gYaBookmarks.showError(elementsAfterError[0].error, "add");
}
else {
var failedBookmarksTitles = "";
for each (bookmarkData in elementsAfterError) {
var str = bookmarkData.name.length? bookmarkData.name : bookmarkData.url;
if (str.length > 50)
str = str.substr(0, 50) + "...";
failedBookmarksTitles += (str + "\n");
}
var readableReason = gYaBookmarks.getString("Reason_" + elementsAfterError[elementsAfterError.length - 1].error);
gYaSearchService.promptService.alert(
null,
gYaBookmarks.getString("Error_bgfailed_Title"),
gYaBookmarks.getFormattedString("Error_bgfailed_Message", [failedBookmarksTitles, readableReason]));
}
}
return false;
}
this._isBusy = true;
this.topElement.callback = this._proccessCallback.bind(this);
gYaSearchService.bookmarksInsertNewItem(this.topElement);
return true;
},
_criticalErrors: ["auth_required", "reg_required", "spam"],
_errorIsCritical: function(err) {
return !(this._criticalErrors.indexOf(err) == -1);
},
_proccessCallback: function(aData) {
this._isBusy = false;
var currentElement = this.shift();
if ("string" == typeof aData) {
currentElement.callback = null;
currentElement.error = aData;
this._elementsAfterError.push(currentElement);
if (this._errorIsCritical(aData)) {
this._elementsAfterError = this._elementsAfterError.concat(this._elements);
this._elements = [];
}
}
this._checkNeedProccess();
}
},
getStringBundle: function() {
if (!this.stringBundle) {
var strBundleService = Cc["@mozilla.org/intl/stringbundle;1"].createInstance(Ci.nsIStringBundleService);
this.stringBundle = strBundleService.createBundle("chrome://yasearch/locale/bookmarks/bookmarks.properties");
}
return this.stringBundle;
},
getString: function(aName) {
return this.getStringBundle().GetStringFromName(aName);
},
getFormattedString: function(aName, aStrArray) {
return this.getStringBundle().formatStringFromName(aName, aStrArray, aStrArray.length);
},
showError: function(aErrorType, aBookmarkingMode) {
if (aErrorType === "reg_required")
return this.showRegRequiredDialog();
var t1 = [this.getString("Action_" + aBookmarkingMode + "_InTitle")];
var t2 = [this.getString("Action_" + aBookmarkingMode + "_InMessage")];
if (aErrorType === "input") {
t2.unshift(t1);
}
var errorType = "Error_" + aErrorType + "_";
gYaSearchService.promptService.alert(null,
this.getFormattedString(errorType + "Title", t1),
this.getFormattedString(errorType + "Message", t2)
);
},
showRegRequiredDialog: function() {
const winType = "Yasearch:BookmarksRegRequiredDialog";
var regRequiredWindow = gYaSearchService.getWindow(winType);
if (regRequiredWindow)
regRequiredWindow.focus();
else
gYaSearchService.windowWatcher.openWindow(
null,
CHROME_CONTENT + "bookmarks/regrequiredDialog.xul",
winType,
"chrome,resizable=no,dependent=yes,centerscreen",
null);
},
addBookmarkInBackground: function(aBrowser) {
var bookmarkData = gYaBookmarks.getBrowserPageData(aBrowser);
if (!bookmarkData.url || gYaBookmarks.isBookmarkedURI(bookmarkData.url).bookmarked)
return false;
bookmarkData.tags = "";
bookmarkData.folder = 0;
this._addBookmarkQueue.push(bookmarkData);
},
formatTagsString: function(aString, aReturnArray) {
var tagsHash = {}, tagsArray = aString.toString().split(",");
for (var i = tagsArray.length; i-- > 0;) {
var tag = tagsArray[i].replace(/[^\x20-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]/g, "")
.replace(/^\s+/, "")
.replace(/\s+$/, "")
.replace(/\s+/g, " ");
if (tag != "" && !tagsHash[tag])
tagsHash[tag] = true;
}
tagsArray = [];
for (var tag in tagsHash)
tagsArray.push(tag);
tagsArray.reverse();
return aReturnArray ? tagsArray : tagsArray.join(", ");
},
getTagsListArray: function(aLimitNmb) {
var tagsHash = {};
var linkXMLElements = this.bookmarksXML..link;
for (var i=0, len = linkXMLElements.length(); i < len; i++) {
var linkTags = linkXMLElements[i].@tags.toString();
if (linkTags) {
var tagsArray = this.formatTagsString(linkTags, true);
for each (var tag in tagsArray) {
tagsHash[tag] ?
(tagsHash[tag].count++) :
(tagsHash[tag] = {value: tag, count: 1});
}
}
}
var tagsArray = [];
for each (var tag in tagsHash)
tagsArray.push(tag);
tagsHash = null;
tagsArray = this.sortTagsArrayByCount(tagsArray);
if (aLimitNmb)
tagsArray = tagsArray.slice(0, aLimitNmb);
return tagsArray;
},
sortTagsArrayByCount: function(aTagsArray) {
aTagsArray.sort(function(a,b) {
return (a.count > b.count) ? -1 : (a.count < b.count) ? 1 :
((a.value > b.value) ? -1 : (a.value < b.value) ? 1 : 0);
});
return aTagsArray;
},
sortTagsArrayByName: function(aTagsArray) {
aTagsArray.sort(function(a,b) {
var aLower = a.toLowerCase(), bLower = b.toLowerCase();
return (aLower < bLower) ? -1 : (aLower > bLower) ? 1 :
((a < b) ? -1 : (a > b) ? 1 : 0);
});
return aTagsArray;
},
getDataForTagsContainer: function(aLimitNmb) {
var resArray = [], tagsArray = this.getTagsListArray(aLimitNmb);
for each (var tagObject in tagsArray)
resArray.push(tagObject.value);
return resArray;
},
showTags: function(aInput, aLimitNmb, aLimitNmbToShow) {
var tagsArray = this.formatTagsString(aInput.value, true);
var tagsData = this.getDataForTagsContainer(aLimitNmb);
var res = {};
for each (var tag in tagsData) {
res[tag] = {value: tag};
for each (var value in tagsArray) {
if (value == tag)
res[tag].disabled = true;
}
}
var resLimited;
if (aLimitNmbToShow && tagsData.length) {
resLimited = {};
tagsData = this.sortTagsArrayByName(tagsData.slice(0, aLimitNmbToShow));
for each (var tag in tagsData)
resLimited[tag] = {value: tag};
}
aInput.showTags(res, resLimited);
},
handleTextChange: function(aInput) {
var value = aInput.value;
if (value === aInput.lastTextValue) return;
var tagsArray = this.formatTagsString(value, true);
if (aInput.tagMaxLength) {
for each (var tag in tagsArray) {
if (tag.length > aInput.tagMaxLength) {
aInput.value = aInput.lastTextValue;
aInput.selectTextRange(aInput.lastCursorPosition, aInput.lastCursorPosition);
aInput.showMaxLengthTooltip();
return;
}
}
}
for each (var tagList in aInput.tagsList) {
var exist = false;
for (var i=0, len = tagsArray.length; i < len; i++) {
if (tagsArray[i] === tagList.value) {
if (tagList.element && tagList.element.getAttribute("disabled") != "true")
tagList.element.setAttribute("disabled", "true");
exist = tagsArray.splice(i,1);
break;
}
}
if (!exist && tagList.element && tagList.element.getAttribute("disabled") == "true")
tagList.element.setAttribute("disabled", "false");
}
aInput.lastTextValue = value;
aInput.lastCursorPosition = aInput.selectionStart;
},
handleTextInput: function(aInput) {
if (!aInput.tagsList)
return;
var value = aInput.value;
var selStart = aInput.selectionStart, selEnd = aInput.selectionEnd;
if (selEnd !== value.length)
return;
var textBefore = value.substr(0, selStart);
textBefore = textBefore.substr(textBefore.lastIndexOf(",") + 1).replace(/^( *)/, "");
if (textBefore == "")
return;
var re = new RegExp("^" + textBefore);
for each (var tag in aInput.tagsList) {
var tagValue = tag.value;
if (re.test(tagValue) && !(new RegExp("(^|,) *" + tagValue + " *($|,)","i").test(value))) {
var textComplete = tagValue.substr(textBefore.length);
var resultValue = value.substr(0, selEnd) + textComplete;
if (aInput.trySetNewValue(resultValue)) {
aInput.selectTextRange(selStart, resultValue.length);
aInput.lastTextComplete = textComplete;
return;
}
}
}
},
refreshYaRuUserData: function(aCallback) {
gYaSearchService.xmlHttpRequest("http://zakladki.yandex.ru/bar/getcommunities.xml?" + getNCRndStr(),
{ callbackFunc: this.refreshYaRuUserDataCallback.bind(this, aCallback) });
},
refreshYaRuUserDataCallback: function(aReq, aCallback) {
var res;
if (gYaSearchService.isReqError(aReq)) {
res = "lost_connection";
} else if (!gYaSearchService.isLogin) {
res = "auth_required";
} else {
var yaruResponse = this.getServerResponse(aReq.target.responseText);
if (yaruResponse.error) {
res = yaruResponse.error;
} else {
if (yaruResponse.xml && yaruResponse.xml.communities) {
var communities = yaruResponse.xml.communities.community;
var communitiesArray = [];
for (var i=0, len = communities.length(); i < len; i++) {
var label = communities[i].title.toString();
var value = communities[i].feed_id.toString();
if (label && value)
communitiesArray.push(communities[i]);
}
communitiesArray.sort(function(a,b) {
var labelA = a.title.toString(), labelB = b.title.toString();
var labelALower = labelA.toLowerCase(), labelBLower = labelB.toLowerCase();
return (labelALower < labelBLower) ? -1 : (labelALower > labelBLower) ? 1 :
((labelA < labelB) ? -1 : (labelA > labelB) ? 1 : 0);
});
var _communities = new XML('<communities/>');
for each (var community in communitiesArray)
_communities.community += community;
yaruResponse.xml.communities = _communities;
}
res = yaruResponse.xml;
}
}
if (aCallback)
aCallback(res);
},
refreshYaRuUserFriendsData: function(aCallback) {
gYaSearchService.xmlHttpRequest("http://zakladki.yandex.ru/bar/getfriendlast.xml?" + getNCRndStr(),
{ callbackFunc: this.refreshYaRuUserFriendsDataCallback.bind(this, aCallback) });
},
refreshYaRuUserFriendsDataCallback: function(aReq, aCallback) {
var res;
if (gYaSearchService.isReqError(aReq)) {
res = "lost_connection";
} else if (!gYaSearchService.isLogin) {
res = "auth_required";
} else {
var yaruResponse = this.getServerResponse(aReq.target.responseText);
if (yaruResponse.error) {
res = yaruResponse.error;
} else {
res = yaruResponse.xml;
}
}
if (typeof res !== "xml") {
var errorXml = <yaru/>;
errorXml.@yasearch_error = res;
res = errorXml;
}
res.@yasearch_login = gYaSearchService.username;
res = gYaSearchService.getDOMDocContent2("bookmarks/xsl-yaru-friends-links.xsl",
gYaSearchService.domParser.parseFromString(res.toSource(), "text/xml"));
if (aCallback)
aCallback(res);
},
yaruPrefs: {
MAX_ADD_HELP_SHOWED: 9,
prefBranchName: "yasearch.general.ui.bookmarks.prefs.",
onHelpShowed: function(aHidePermanently) {
this.set("yaruAddHelpShowed",
aHidePermanently || (gYaSearchService.getIntPref(this.prefBranchName + "yaruAddHelpShowed") + 1));
},
get: function(aPrefName) {
var fullPrefName = this.prefBranchName + aPrefName;
var res = null;
switch (aPrefName) {
case "yaruBlockExpanded":
case "yaruLiveWindowDisabled":
case "yaruExportChecked":
res = gYaSearchService.getBoolPref(fullPrefName);
break;
case "yaruPublicVal":
res = gYaSearchService.getIntPref(fullPrefName);
break;
case "yaruAddHelpShowed":
res = gYaSearchService.getIntPref(fullPrefName) >= this.MAX_ADD_HELP_SHOWED;
break;
default:
return null;
}
return res;
},
set: function(aPrefName, aPrefValue) {
var fullPrefName = this.prefBranchName + aPrefName;
var res = null;
switch (aPrefName) {
case "yaruBlockExpanded":
case "yaruLiveWindowDisabled":
case "yaruExportChecked":
res = gYaSearchService.setBoolPref(fullPrefName, aPrefValue);
break;
case "yaruPublicVal":
res = gYaSearchService.setIntPref(fullPrefName, aPrefValue);
break;
case "yaruAddHelpShowed":
if ("number" !== typeof aPrefValue)
aPrefValue = aPrefValue ? this.MAX_ADD_HELP_SHOWED : 0;
res = gYaSearchService.setIntPref(fullPrefName, Math.min(this.MAX_ADD_HELP_SHOWED, aPrefValue));
break;
default:
return null;
}
return res;
}
},
_lastUsedFolderPrefName: "yasearch.general.ui.bookmarks.lastfolder",
get lastUsedFolder() {
var [lastFolderId, lastFolderTimestamp] =
gYaSearchService.getCharPref(this._lastUsedFolderPrefName).split(";");
lastFolderId = gYaSearchService.parseIntFromStr(lastFolderId);
lastFolderTimestamp = gYaSearchService.parseIntFromStr(lastFolderTimestamp);
return (lastFolderId && (Date.now() - lastFolderTimestamp) < (DAY_SECS / 24)) ? // 1 hour
Math.max(0, lastFolderId) : 0;
},
set lastUsedFolder(val) {
gYaSearchService.setCharPref(this._lastUsedFolderPrefName,
[Math.max(0, gYaSearchService.parseIntFromStr(val)), Date.now()].join(";"));
return this.lastUsedFolder;
}
}
gYaBookmarks._init();