home *** CD-ROM | disk | FTP | other *** search
- var YaCity = {
- nsIYa: Components.classes["@yandex.ru/yasearch;1"]
- .getService(Components.interfaces.nsIYaSearch)
- .wrappedJSObject,
-
- nsIYaAutoComplete: Components.classes["@mozilla.org/autocomplete/search;1?name=YasearchCity"]
- .getService(Components.interfaces.nsIYaCityAComplete)
- .wrappedJSObject,
-
- get yaCityComponent() {
- return this.nsIYa.yaCity;
- },
-
- _autoCity: {id: 0, label: ""},
-
- _res: 0,
-
- accepted: false,
-
- init: function() {
- this.stringBundleSet = document.getElementById("yasearch-string-bundle-city");
-
- this.toolbarButtonId = window.arguments[0];
-
- this.removeButtonOnCancel = !!window.arguments[1];
-
- this.textLabel = document.getElementById("yasearch-city-city");
-
- setTimeout(function(me) {
- me.nsIYaAutoComplete.prepeareForNewSearch();
- me.refreshCitiesList(me.yaCityComponent.citiesData);
- }, 0, this);
- },
-
- handleCityChange: function(event) {
- let city = event.target;
-
- if (city.hasAttribute("gid") && city.nodeName == "label")
- this.setCity(city.getAttribute("gid"), city.value);
- },
-
- onSearchComplete: function() {
- this._res = this.nsIYaAutoComplete.lastResult.id;
- },
-
- onTextChanged: function(aType) {
- let lastResult = this.nsIYaAutoComplete.lastResult;
- this._res = this.textLabel.value == lastResult.city ? lastResult.id : "0";
- return true;
- },
-
- setCity: function(aId, aLabel) {
- this._res = aId;
- this.textLabel.value = aLabel;
-
- this.nsIYaAutoComplete.lastResult = {id: aId, city: aLabel};
- },
-
- setAutoCity: function(aCity) {
- if (YaCity.textLabel.value != "")
- return;
-
- var cityObj = aCity || this._autoCity;
- this.setCity(cityObj.id, cityObj.label);
- },
-
- refreshCitiesList: function(aData) {
- if (typeof YaCity != "undefined") {
- if (!aData)
- return false;
-
- YaCity.textLabel.disabled = false;
-
- var buttonProps = YaCity.yaCityComponent.getCityProps(YaCity.toolbarButtonId);
-
- if (buttonProps.cityId) {
- var cityElement = aData..region.(@id == buttonProps.cityId)[0];
- if (cityElement) {
- YaCity.setAutoCity({id: buttonProps.cityId, label: cityElement.@name.toString()});
- return true;
- }
- }
- }
-
- return true;
- },
-
- get _subPrefs() {
- return (window.opener && "YaSubPrefs" in window.opener) ? window.opener.YaSubPrefs : null;
- },
-
- onDialogAccept: function() {
- if (!this._res) {
- this.nsIYa.promptService.alert(window,
- YaCity.stringBundleSet.getString("ErrorNoCityTitle"),
- YaCity.stringBundleSet.getString("ErrorNoCity"));
- return false;
- }
-
- this.accepted = true;
-
- let cityId = this._res,
- label = this.textLabel.value;
-
- if (cityId == "0")
- cityId = label = "";
-
- this.yaCityComponent.updateButtonProps(this.toolbarButtonId,
- {
- cityId: cityId,
- label: label,
- weatherEnabledValue: "",
- trafficEnabledValue: ""
- }
- );
-
- let prefs = this._subPrefs;
- if (prefs && ("changeLabelFromCityWindow" in prefs))
- prefs.changeLabelFromCityWindow(this.toolbarButtonId, label);
-
- this.yaCityComponent.updateCityInfo(this.toolbarButtonId, true);
-
- return true;
- },
-
- onDialogUnload: function() {
- if (this.removeButtonOnCancel && !this.accepted && this.toolbarButtonId)
- this.yaCityComponent.removeToolbaritem(this.toolbarButtonId);
-
- let prefs = this._subPrefs;
- if (prefs && ("resizeWindow" in prefs))
- prefs.resizeWindow();
- }
- };