home *** CD-ROM | disk | FTP | other *** search
- function YaSubSize2Content() {
- try {
- window.sizeToContent();
- window.resizeTo(window.outerWidth, window.outerHeight + 1);//fx bug
- } catch(e) {}
- }
-
- var YaSubPrefs = {
- accepted: false,
-
- observerService: Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService),
-
- resizeWindow: function() {
- YaSubSize2Content();
- },
-
- savedShowCityLabel: true,
-
- get currentShowCityLabel() {
- return _YaPrefs.nsIYa.prefs.showCityLabel;
- },
-
- set currentShowCityLabel(val) {
- _YaPrefs.nsIYa.prefs.showCityLabel = val;
- return this.currentShowCityLabel;
- },
-
- autoLabelAppendix: _YaPrefs.stringBundle.getString("CityAuto"),
- unknownCityLabel: _YaPrefs.stringBundle.getString("CityUnknown"),
-
- autoCityElements: {},
-
- changeState: function(aState, aId) {
- var observer = _YaPrefs.nsIYa.yaCity._observers[aId];
- if (observer && observer.nodes)
- for each (var node in observer.nodes)
- node.setAttribute("yaCustomizedVisible", aState);
- },
-
- observe: function(aSubject, aTopic, aState) {
- var observer = _YaPrefs.nsIYa.yaCity._observers[aState];
- var props = _YaPrefs.nsIYa.yaCity.getCityProps(observer.nodes[0].id);
- var chk = document.getElementById("yasearch-city-" + props.buttonId + "-node");
-
- if (!chk)
- return;
-
- if (aTopic == "Ya-City-Data-Changed") {
- chk.setAttribute("label", this._getLabelFromCityProps(props));
- } else if (aTopic == "Ya-City-Item-OnRemove") {
- chk.parentNode.removeChild(chk);
- }
-
- YaSubSize2Content();
- },
-
- _getLabelFromCityProps: function(aProps) {
- let label = aProps.label;
- if (aProps.cityId == "")
- label += " " + this.autoLabelAppendix;
-
- if (label == "")
- label = this.unknownCityLabel;
-
- return label;
- },
-
- changeLabelFromCityWindow: function(aId, aLabel) {
- var chk = document.getElementById(aId + "-node");
- if (!chk)
- return;
-
- if (!aLabel) {
- let props = _YaPrefs.nsIYa.yaCity.getCityProps(aId);
- aLabel = this._getLabelFromCityProps(props);
- }
-
- chk.setAttribute("label", aLabel);
- YaSubSize2Content();
- },
-
- beforeAccept: function() {
- this.accepted = true;
- return true;
- },
-
- beforeUnload: function() {
- this.observerService.removeObserver(this, "Ya-City-Data-Changed");
- this.observerService.removeObserver(this, "Ya-City-Item-OnRemove");
-
- if (!this.accepted) {
- for each (var chk in document.getElementById("yasearch.exists.city.buttons").getElementsByTagName("checkbox")) {
- if (chk.hasAttribute) {
- var id = chk.id.replace(/^yasearch\-city\-/, "").replace(/\-node$/, "");
- if (!chk.hasAttribute("visibleOnEnter")) {
- for each (var node in _YaPrefs.nsIYa.yaCity._observers[id].nodes)
- node.parentNode.removeChild(node);
- } else {
- this.changeState(true, id);
- }
- }
- }
-
- if (this.currentShowCityLabel != this.savedShowCityLabel)
- this.currentShowCityLabel = this.savedShowCityLabel;
- } else {
- var checkedBoxes = document.getElementById("yasearch.exists.city.buttons").getElementsByAttribute("checked", "true");
- if (!checkedBoxes[0])
- _YaPrefs.changeElementState("yasearch-city", false);
- }
-
- _YaPrefs.nsIYa.yaCity.updateObservers();
- },
-
- init: function() {
- this.savedShowCityLabel = this.currentShowCityLabel;
-
- this.observerService.addObserver(this, "Ya-City-Data-Changed", false);
- this.observerService.addObserver(this, "Ya-City-Item-OnRemove", false);
-
- var listBox = document.getElementById("yasearch.exists.city.buttons");
- while (listBox.firstChild)
- listBox.removeChild(listBox.firstChild);
-
- var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
-
- for each (var observer in _YaPrefs.nsIYa.yaCity._observers) {
- var node = observer.nodes[0];
- if (node.getAttribute("yaCustomizedVisible") == "true") {
- var props = _YaPrefs.nsIYa.yaCity.getCityProps(node.id);
- var label = props.label;
-
- if (props.cityId == "")
- label += " " + this.autoLabelAppendix;
-
- if (props.labelAlias)
- label = "(" + props.labelAlias + ") " + label;
-
- if (label == "")
- label = this.unknownCityLabel;
-
- var chk = document.createElementNS(XULNS, "checkbox");
- chk.setAttribute("id", "yasearch-city-" + props.buttonId + "-node");
- chk.setAttribute("label", label);
- chk.setAttribute("checked", "true");
- chk.setAttribute("visibleOnEnter", "true");
- chk.setAttribute("oncommand", "YaSubPrefs.changeState(this.checked, '" + props.buttonId + "');");
- listBox.appendChild(chk);
- }
- }
- },
-
- addCityButton: function() {
- var defaultSet = _YaPrefs.gYaToolbar.getAttribute("defaultset");
-
- var pid = "yasearch-city";
- var item = _YaPrefs.customizedElements[pid];
-
- for each (var browser in _YaPrefs.browsers) {
- var yaBar = browser.document.getElementById("yasearch-bar");
-
- var el = item.prev,
- found = false;
-
- while (el && !found) {
- found = yaBar.getElementsByAttribute("_yaPID", el.pid)[0] || false;
- el = el.prev;
- }
-
- if (found && found.nextSibling) {
- var prevFromDefault = new RegExp("([^,]*)," + pid).exec(defaultSet)[1];
-
- if (prevFromDefault && (prevFromDefault == "spring" || prevFromDefault == "separator")) {
- prevFromDefault = "toolbar" + prevFromDefault;
- while (found.nextSibling && found.nextSibling.localName == prevFromDefault)
- found = found.nextSibling;
- }
- }
-
- var beforeElt = found ? (found.nextSibling ? found.nextSibling : false) :
- (yaBar.firstChild ? yaBar.firstChild : false);
-
- var [id, clone] = _YaPrefs.nsIYa.yaOverlay.insertToolbarItem("yasearch-city", beforeElt, browser);
- if (!clone)
- continue;
-
- clone.setAttribute("yaCustomizedVisible", true);
- clone.setAttribute("_yaPID", pid);
- item.toolbarItems.push(clone);
- }
-
- var chk = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "checkbox");
- chk.setAttribute("label", this.autoLabelAppendix);
- chk.setAttribute("checked", "true");
- chk.setAttribute("id", id + "-node");
- chk.setAttribute("oncommand", "YaSubPrefs.changeState(this.checked, '" + id.replace(/^yasearch\-city\-/, "") + "');");
-
- document.getElementById("yasearch.exists.city.buttons").appendChild(chk);
-
- window.openDialog(YaUtils.CHROME_CONTENT + "city/city-settings.xul", "",
- "centerscreen,chrome,dialog,resizable,dependent", id, true);
-
- setTimeout("YaSubSize2Content",100);
- }
- };