home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0"?>
- <!DOCTYPE bindings [
- <!ENTITY % preferencesDTD SYSTEM "chrome://yasearch/locale/preferences/preferences.dtd">
- %preferencesDTD;
- ]>
-
- <bindings xmlns="http://www.mozilla.org/xbl"
- xmlns:xbl="http://www.mozilla.org/xbl"
- xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- xmlns:html="http://www.w3.org/1999/xhtml">
-
- <binding id="global-setting-icon">
- <content xb-tooltip-prefix="&global.setting.tooltip.prefix;">
- <xul:hbox flex="1">
- <xul:spacer flex="1"/>
- <xul:image xbl:inherits="tooltiptext=xb-global-setting-warning"/>
- </xul:hbox>
- </content>
-
- <implementation>
- <constructor><![CDATA[
- let tooltiptext = this.getAttribute("xb-global-setting-warning");
- if (tooltiptext == "auto") {
- let widgetNames = this.getAttribute("xb-global-setting-names")
- .split(",")
- .map(function(str) "«" + str + "»")
- .join(", ");
-
- this.setAttribute("xb-global-setting-warning", this.getAttribute("xb-tooltip-prefix").replace("%S", widgetNames));
- }
- ]]></constructor>
- </implementation>
- </binding>
-
- <binding id="base">
- <implementation>
- <field name="mListItem">
- this.parentNode.parentNode.parentNode
- </field>
-
- <field name="mPreferencesController">
- this.mListItem.parentNode.PreferencesController
- </field>
-
- <field name="mSource"/>
- <field name="mSourceTemplate"/>
- <field name="mShortcuts"/>
- <field name="mShortcutsTemplate"/>
-
- <property name="hasSourceURL" readonly="true" onget="return this.hasAttribute('source');"/>
- <property name="hasSourceTemplateURL" readonly="true" onget="return this.hasAttribute('template');"/>
-
- <property name="hasShortcutsURL" readonly="true" onget="return this.hasAttribute('shortcuts-source');"/>
- <property name="hasShortcutsTemplateURL" readonly="true" onget="return this.hasAttribute('shortcuts-template');"/>
-
- <method name="_getXMLData">
- <parameter name="aType"/>
- <body><![CDATA[
- let url = this.getAttribute(aType);
-
- if (!url)
- return this._onXMLDataResponse(aType, null);
-
- let me = this;
-
- function callback(aRequest) {
- let xmlString = "";
- try {
- xmlString = aRequest.target.responseText || "";
- } catch (ex) {}
-
- if (me && "_onXMLDataResponse" in me)
- me._onXMLDataResponse(aType, xmlString);
- }
-
- let req = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
- .createInstance(Components.interfaces.nsIXMLHttpRequest);
- try {
- req.open("GET", url, true);
- } catch (ex) {
- return this._onXMLDataResponse(aType, null);
- }
-
- let target = req.QueryInterface(Components.interfaces.nsIDOMEventTarget);
- target.addEventListener("load", callback, false);
- target.addEventListener("error", callback, false);
-
- req.send(null);
- ]]></body>
- </method>
-
- <method name="_onXMLDataResponse">
- <parameter name="aType"/>
- <parameter name="aXMLString"/>
- <body><![CDATA[
- if (aType == "template") {
- if (aXMLString === "") {
- this._getXMLData("alt-template");
- } else {
- this.mSourceTemplate = aXMLString;
- this._getXMLData("source");
- }
-
- return;
- }
-
- if (aType == "alt-template") {
- if (aXMLString === "") {
- this._onXMLDataResponse("alt-source", null);
- }
-
- this.mSourceTemplate = aXMLString;
- this._getXMLData("alt-source");
-
- return;
- }
-
- if (aType == "shortcuts-template") {
- if (aXMLString === "") {
- this._getXMLData("shortcuts-alt-template");
- } else {
- this.mShortcutsTemplate = aXMLString;
- this._getXMLData("shortcuts-source");
- }
-
- return;
- }
-
- if (aType == "shortcuts-alt-template") {
- if (aXMLString === "") {
- this._onXMLDataResponse("shortcuts-alt-source", null);
- }
-
- this.mShortcutsTemplate = aXMLString;
- this._getXMLData("shortcuts-alt-source");
-
- return;
- }
-
- if (aType == "source" || aType == "alt-source") {
- this.mSource = this.mPreferencesController
- .transformSourceXMLData(this.mListItem.id, aType, aXMLString, this.mSourceTemplate);
-
- if (!this.mSource) {
- if (aType != "alt-source") {
- if (this.hasAttribute("alt-template")) {
- this.mSourceTemplate = null;
- this._getXMLData("alt-template");
- } else {
- this._getXMLData("alt-source");
- }
-
- return;
- }
- }
-
- this._constructSource();
-
- } else if (aType == "shortcuts-source" || aType == "shortcuts-alt-source") {
- this.mShortcuts = this.mPreferencesController
- .transformSourceXMLData(this.mListItem.id, aType, aXMLString, this.mShortcutsTemplate);
-
- if (!this.mShortcuts) {
- if (aType != "shortcuts-alt-source") {
- if (this.hasAttribute("shortcuts-alt-template")) {
- this.mShortcutsTemplate = null;
- this._getXMLData("shortcuts-alt-template");
- } else {
- this._getXMLData("shortcuts-alt-source");
- }
-
- return;
- }
- }
-
- this._constructShortcuts();
- }
- ]]></body>
- </method>
-
- <method name="_getSource">
- <body><![CDATA[
- if (this.hasSourceURL) {
- this._getXMLData(this.hasSourceTemplateURL ? "template" : "source");
- } else {
- this._constructSource();
- }
- ]]></body>
- </method>
-
- <method name="_getShortcuts">
- <body><![CDATA[
- if (this.hasShortcutsURL) {
- this._getXMLData(this.hasShortcutsTemplateURL ? "shortcuts-template" : "shortcuts-source");
- } else {
- this._constructShortcuts();
- }
- ]]></body>
- </method>
-
- <constructor><![CDATA[
- setTimeout(function(me) {
- if (me && "_init" in me)
- me._init();
- }, 0, this);
- ]]></constructor>
-
- <method name="_init">
- <body><![CDATA[
- switch (this.getAttribute("xb-preftype")) {
- case "combobox":
- case "radiogroup":
- this._getSource();
- this._getShortcuts();
- break;
-
- default:
- break;
- }
- ]]></body>
- </method>
-
- <method name="_handleChange">
- <parameter name="aEvent"/>
- <body><![CDATA[
- if (aEvent.target === this && this.getAttribute("disabled") !== "true") {
- let val = this.value;
- this.mPreferencesController.onPrefChange(this.mListItem, this.getAttribute("prefName"), val);
- }
- ]]></body>
- </method>
- </implementation>
-
- <handlers>
- <handler event="CheckboxStateChange">
- this._handleChange(event);
- </handler>
-
- <handler event="change">
- this._handleChange(event);
- </handler>
-
- <handler event="select">
- if (["menulist", "radiogroup"].indexOf(event.originalTarget.localName) != -1)
- this._handleChange(event);
- </handler>
- </handlers>
- </binding>
-
- <binding id="checkbox" extends="#base">
- <content flex="1">
- <xul:box xbl:inherits="orient">
- <xul:checkbox anonid="checkbox" xbl:inherits="label,checked=value,disabled"/>
- <xul:hbox class="global-setting-icon" xbl:inherits="xb-global-setting-warning,xb-global-setting-names"/>
- </xul:box>
- </content>
-
- <implementation>
- <field name="checkbox">
- document.getAnonymousElementByAttribute(this, "anonid", "checkbox")
- </field>
-
- <property name="value">
- <getter><![CDATA[
- return !!this.checkbox.checked;
- ]]></getter>
- </property>
-
- <constructor><![CDATA[
-
- ]]></constructor>
- </implementation>
- </binding>
-
- <binding id="textedit" extends="#base">
- <content>
- <xul:box align="center" xbl:inherits="orient">
- <xul:label xbl:inherits="value=label"/>
- <xul:textbox flex="1" anonid="textbox" xbl:inherits="value,disabled,align,dir,pack,orient"/>
- <xul:label xbl:inherits="value=label-after"/>
- <xul:hbox class="global-setting-icon" xbl:inherits="xb-global-setting-warning,xb-global-setting-names"/>
- </xul:box>
- </content>
-
- <implementation>
- <field name="textbox">
- document.getAnonymousElementByAttribute(this, "anonid", "textbox")
- </field>
-
- <property name="value">
- <getter><![CDATA[
- return this.textbox.value || this.getAttribute("empty-default");
- ]]></getter>
- </property>
-
- <constructor><![CDATA[
- let type = this.getAttribute("value-type");
- switch (type) {
- case "string":
- case "number":
- case "int":
- break;
-
- default:
- type = "string";
- break;
- }
-
- let textbox = this.textbox;
-
- let maxLength = (type == "string" && this.hasAttribute("max-length")) ?
- parseInt(this.getAttribute("max-length"), 10) : 0;
- if (maxLength > 0)
- textbox.setAttribute("maxlength", maxLength);
-
- if (type == "int" || type == "number") {
- textbox.removeAttribute("flex");
-
- textbox.setAttribute("type", "number");
-
- if (type == "number")
- textbox.setAttribute("decimalplaces", "Infinity");
-
- let size = 4;
- ["min", "max"].forEach(function(aAttrName) {
- if (this.hasAttribute(aAttrName)) {
- let val = this.getAttribute(aAttrName);
- size = Math.max(size, val.length);
-
- val = (type == "number") ? parseFloat(val, 10) : parseInt(val, 10);
- textbox.setAttribute(aAttrName, val);
- }
- }, this);
-
- if (type == "int") {
- let increment = this.hasAttribute("spin") ? parseInt(this.getAttribute("spin"), 10) : 1;
- if (!increment || increment < 1)
- textbox.setAttribute("hidespinbuttons", "true");
- else
- textbox.setAttribute("increment", increment);
- }
-
- textbox.setAttribute("size", Math.min(12, size));
- }
-
- if (!this.hasAttribute("value") && this.hasAttribute("empty-default")) {
- this.setAttribute("value", this.getAttribute("empty-default"));
- }
- ]]></constructor>
- </implementation>
-
- <handlers>
- <handler event="select" phase="capturing" preventdefault="true">
- <![CDATA[
- if (event.target == this.textbox.inputField)
- event.stopPropagation();
- ]]>
- </handler>
- </handlers>
- </binding>
-
- <binding id="combobox" extends="#base">
- <content disabled="true" busy="true">
- <xul:box align="center" xbl:inherits="orient">
- <xul:label xbl:inherits="value=label"/>
- <xul:menulist anonid="menulist" flex="1" xbl:inherits="value,editable,disabled,align,dir,pack,orient">
- <xul:menupopup anonid="menupopup">
- <xul:menuitem label=" ...&controls.combobox.creating.label;... "/>
- </xul:menupopup>
- </xul:menulist>
- <xul:label xbl:inherits="value=label-after"/>
- <xul:hbox class="global-setting-icon" xbl:inherits="xb-global-setting-warning,xb-global-setting-names"/>
- <html:div style="display:none">
- <children/>
- </html:div>
- </xul:box>
- </content>
-
- <implementation>
- <field name="menulist">
- document.getAnonymousElementByAttribute(this, "anonid", "menulist")
- </field>
-
- <field name="menupopup">
- document.getAnonymousElementByAttribute(this, "anonid", "menupopup")
- </field>
-
- <property name="value">
- <getter><![CDATA[
- return this.menulist.value;
- ]]></getter>
- </property>
-
- <constructor><![CDATA[
- let menuitemNodes = Array.slice(this.childNodes)
- .filter(function (aNode) aNode.localName === "menuitem");
-
- menuitemNodes.forEach(function(aNode) {
- if (!aNode.hasAttribute("label") && aNode.hasAttribute("value"))
- aNode.setAttribute("label", aNode.getAttribute("value"));
-
- this.appendChild(aNode);
- }, this.menupopup);
- ]]></constructor>
-
- <method name="_nodesAppender">
- <parameter name="aDestination"/>
- <parameter name="aSource"/>
- <body><![CDATA[
- let i = 0,
- node = aSource.firstChild,
- nodes = document.createDocumentFragment(),
- t = Date.now();
-
- while (node) {
- nodes.appendChild(node);
- node = (i++ < 500 || (Date.now() - t) < 5) ? aSource.firstChild : null;
- }
-
- if (!nodes.childNodes.length) {
- this._constructSourceDone();
- } else {
- aDestination.appendChild(nodes);
-
- window.setTimeout(function(me, dst, src) {
- if (me && "_nodesAppender" in me)
- me._nodesAppender(dst,src);
- }, 10, this, aDestination, aSource);
- }
- ]]></body>
- </method>
-
- <method name="_constructSource">
- <body><![CDATA[
- let menupopup = this.menupopup;
-
- if (this.mSource && this.mSource.childNodes.length) {
- while (menupopup.firstChild)
- menupopup.removeChild(menupopup.firstChild);
-
- Array.slice(this.mSource.childNodes).forEach(function(aNode) {
- if (!aNode.hasAttribute("label") && aNode.hasAttribute("value"))
- aNode.setAttribute("label", aNode.getAttribute("value"));
- });
-
- this._nodesAppender(menupopup, this.mSource);
-
- } else {
- this._constructSourceDone();
- }
- ]]></body>
- </method>
-
- <method name="_constructSourceDone">
- <body><![CDATA[
- if (this.menupopup.childNodes.length) {
- this.menulist.value = this.getAttribute("value");
- this.setAttribute("disabled", "false");
- }
-
- this.removeAttribute("busy");
- ]]></body>
- </method>
-
- <method name="_constructShortcuts">
- <body><![CDATA[
- ]]></body>
- </method>
- </implementation>
- </binding>
-
- <binding id="combobox-editable" extends="#base">
- <content disabled="true" busy="true">
- <xul:box align="center" xbl:inherits="orient">
- <xul:label xbl:inherits="value=label"/>
- <xul:textbox anonid="textbox"
- flex="100"
- type="autocomplete"
- timeout="100"
- enablehistory="true"
- autocompletesearch="yacustombar-autocomplete"
- autocompletesearchparam=""
- completeselectedindex="false"
- completedefaultindex="false"
- forcecomplete="false"
- showcommentcolumn="false"
- tabscrolling="true"
- newlines="replacewithspaces"
- xbl:inherits="value,disabled,align,dir,pack,orient"/>
- <xul:label xbl:inherits="value=label-after"/>
- <xul:hbox class="global-setting-icon" xbl:inherits="xb-global-setting-warning,xb-global-setting-names"/>
- <html:div style="display:none">
- <children/>
- </html:div>
- </xul:box>
- <xul:vbox onclick="onShortcutsClick(event)">
- <html:div anonid="shortcuts" style="-moz-column-count:2;"/>
- </xul:vbox>
- </content>
-
- <implementation implements="nsIObserver">
- <field name="textbox">
- document.getAnonymousElementByAttribute(this, "anonid", "textbox")
- </field>
-
- <field name="shortcuts">
- document.getAnonymousElementByAttribute(this, "anonid", "shortcuts")
- </field>
-
- <field name="mFreeInput">
- this.getAttribute("free-input") != "false"
- </field>
-
- <field name="autocompleteData">[]</field>
-
- <field name="mACompleteCustomController">null</field>
-
- <property name="value">
- <getter><![CDATA[
- let val = this.textbox.value;
- if (this.mFreeInput)
- return val;
-
- let result = this._getAutocompleteResult(val);
- let realValue = result ? result.realValue : "";
-
- return realValue;
- ]]></getter>
- </property>
-
- <property name="mAutoCompleteSearch" readonly="true">
- <getter><![CDATA[
- let autoCompleteSearchName = this.textbox.getAttribute("autocompletesearch");
- let autoCompleteSearch = Cc["@mozilla.org/autocomplete/search;1?name=" + autoCompleteSearchName]
- .getService(Ci.nsIAutoCompleteSearch);
-
- return autoCompleteSearch.wrappedJSObject;
- ]]></getter>
- </property>
-
- <method name="_getAutocompleteResult">
- <parameter name="aString"/>
- <body><![CDATA[
- if (this.mFreeInput) {
- return {
- value: aString,
- realValue: aString
- };
- }
-
- let result = this.mAutoCompleteSearch.lastResult.getResultForString(aString);
-
- if (!result) {
- let lowercaseSearchString = aString.toLowerCase();
-
- this.autocompleteData.some(function(aDataObj) {
- return (aDataObj.value.toLowerCase().indexOf(lowercaseSearchString) == 0)
- ? (result = aDataObj, true)
- : false;
- });
-
- if (!result)
- result = this.autocompleteData[0];
- }
-
- return result;
- ]]></body>
- </method>
-
- <method name="_getValueFromRealValue">
- <parameter name="aRealValue"/>
- <body><![CDATA[
- let data = null;
- this.autocompleteData.some(function(aDataObj) {
- return (aDataObj.realValue == aRealValue) ? (data = aDataObj, true) : false;
- });
-
- return data ? data.value : null;
- ]]></body>
- </method>
-
- <constructor>
- <![CDATA[
- let os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
- os.addObserver(this, "autocomplete-did-enter-text", false);
-
- let textbox = this.textbox;
- let forceComplete = !this.mFreeInput;
-
- ["completeselectedindex", "completedefaultindex", "forcecomplete"]
- .forEach(function(aAttr) textbox.setAttribute(aAttr, forceComplete));
- ]]>
- </constructor>
-
- <destructor>
- <![CDATA[
- let os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
- os.removeObserver(this, "autocomplete-did-enter-text", false);
-
- this.autocompleteData = null;
- this.mAutoCompleteSearch.lastResult.clear();
- ]]>
- </destructor>
-
- <method name="_constructSource">
- <body><![CDATA[
- let JSON = this.mPreferencesController.JSON;
-
- let autocompleteData = [];
-
- if (this.mSource) {
- Array.slice(this.mSource.childNodes).forEach(function(aNode) {
- let dataObj = {
- value: aNode.getAttribute("label"),
- realValue: aNode.getAttribute("value")
- };
-
- autocompleteData.push(dataObj);
- });
-
- this.autocompleteData = autocompleteData;
-
- this.textbox.setAttribute("autocompletesearchparam", JSON.stringify(autocompleteData));
- }
-
- let val = this.getAttribute("value");
- this.textbox.value = this.mFreeInput ? val : (this._getValueFromRealValue(val) || "");
-
- this.setAttribute("disabled", "false");
- this.textbox.disabled = false;
-
- this.removeAttribute("busy");
- ]]></body>
- </method>
-
- <method name="_constructShortcuts">
- <body><![CDATA[
- //if (!this.mShortcuts) {
- // ...
- //}
-
- if (this.mShortcuts) {
- const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
-
- let shortcuts = this.shortcuts;
-
- Array.slice(this.mShortcuts.childNodes).forEach(function(aNode) {
- let label = document.createElementNS(kXULNS, "label");
- label.setAttribute("style", "display: block;")
- label.setAttribute("crop", "end");
- label.setAttribute("value", aNode.getAttribute("label"));
- label.setAttribute("xb-value", aNode.hasAttribute("value") ? aNode.getAttribute("value")
- : aNode.getAttribute("label"));
-
- shortcuts.appendChild(label);
- });
- }
- ]]></body>
- </method>
-
- <method name="onShortcutsClick">
- <parameter name="aEvent"/>
- <body><![CDATA[
- let originalTarget = aEvent.originalTarget;
- if (originalTarget.localName == "label") {
- this.textbox.value = originalTarget.getAttribute("value");
- //this... = originalTarget.getAttribute("xb-value");
- }
- ]]></body>
- </method>
-
- <method name="observe">
- <parameter name="aSubject"/>
- <parameter name="aTopic"/>
- <parameter name="aData"/>
- <body><![CDATA[
- switch (aTopic) {
- case "autocomplete-did-enter-text":
- if (aSubject === this.textbox) {
- let result = this.mAutoCompleteSearch.lastResult.lastResult;
- if (result)
- this.textbox.value = result.value;
- }
- break;
-
- default:
- break;
- }
- ]]></body>
- </method>
- </implementation>
-
- <handlers>
- <handler event="focus">
- <![CDATA[
- if (this.getAttribute("editable") == "true" && event.originalTarget.localName == "input")
- this.mAutoCompleteSearch.lastResult.clear();
- ]]>
- </handler>
-
- <handler event="blur">
- <![CDATA[
- if (this.getAttribute("editable") == "true" && event.originalTarget.localName == "input") {
- let result = this._getAutocompleteResult(this.textbox.value);
- this.textbox.value = result ? result.value : "";
- this._handleChange(event);
- }
- ]]>
- </handler>
- </handlers>
- </binding>
-
- <binding id="radiogroup" extends="#base">
- <content disabled="true" busy="true">
- <xul:box xbl:inherits="orient">
- <xul:groupbox>
- <xul:caption xbl:inherits="label" flex="1" crop="end"/>
- <xul:hbox class="global-setting-icon" xbl:inherits="xb-global-setting-warning,xb-global-setting-names"/>
- <xul:radiogroup anonid="radiogroup" xbl:inherits="value,disabled,align,dir,pack,orient"/>
- </xul:groupbox>
- <html:div style="display:none">
- <children/>
- </html:div>
- </xul:box>
- </content>
-
- <implementation>
- <field name="radiogroup">
- document.getAnonymousElementByAttribute(this, "anonid", "radiogroup")
- </field>
-
- <property name="value">
- <getter><![CDATA[
- return this.radiogroup.value;
- ]]></getter>
- </property>
-
- <constructor><![CDATA[
- let radioNodes = Array.slice(this.childNodes)
- .filter(function (aNode) aNode.localName === "radio");
-
- radioNodes.forEach(function(aNode) {
- this.appendChild(aNode);
- }, this.radiogroup);
- ]]></constructor>
-
- <method name="_constructSource">
- <body><![CDATA[
- let radiogroup = this.radiogroup;
-
- if (this.mSource && this.mSource.childNodes.length) {
- while (radiogroup.firstChild)
- radiogroup.removeChild(radiogroup.firstChild);
-
- radiogroup.appendChild(this.mSource);
- }
-
- if (radiogroup.childNodes.length) {
- let value = radiogroup.value;
- if (value)
- radiogroup.value = value;
- else
- radiogroup.selectedIndex = 0;
-
- this.setAttribute("disabled", "false");
- radiogroup.disabled = false;
- }
-
- this.removeAttribute("busy");
- ]]></body>
- </method>
-
- <method name="_constructShortcuts">
- <body><![CDATA[
- ]]></body>
- </method>
- </implementation>
- </binding>
- </bindings>
-