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 / fil451188DCEBAEC54758D94E04D9589B74 < prev    next >
Extensible Markup Language  |  2010-07-12  |  34KB  |  918 lines

  1. <?xml version="1.0"?>
  2. <!DOCTYPE bindings [
  3. <!ENTITY % yasearchDTD SYSTEM "chrome://yasearch/locale/yasearch.dtd" >
  4. %yasearchDTD;
  5. ]>
  6. <bindings id="YaSearchBindings"
  7.           xmlns="http://www.mozilla.org/xbl"
  8.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  9.           xmlns:xbl="http://www.mozilla.org/xbl">
  10.   
  11.   <binding id="yasearch-bar"
  12.            extends="chrome://global/content/bindings/toolbar.xml#toolbar">
  13.     <implementation>
  14.       <constructor><![CDATA[
  15.         Components.classes["@yandex.ru/yasearch;1"]
  16.                   .getService(Components.interfaces.nsIYaSearch)
  17.                   .wrappedJSObject
  18.                   .checkToolbarSet(this.getAttribute("yaNmbSaved"), this);
  19.       ]]></constructor>
  20.     </implementation>
  21.   </binding>
  22.   
  23.   <binding id="calendar-day-image"
  24.            extends="chrome://global/content/bindings/general.xml#image">
  25.     <implementation>
  26.       <constructor><![CDATA[
  27.         var day = (new Date().getDate() - 1) * 16;
  28.         
  29.         this.setAttribute("style", (this.getAttribute("style") || "")
  30.           + "background: url('" + this.src + "') -" + day + "px 0 no-repeat;"
  31.           + "min-width:16px; min-height:16px;"
  32.         );
  33.         
  34.         this.src = "";
  35.       ]]></constructor>
  36.     </implementation>
  37.   </binding>
  38.   
  39.   <binding id="extend-toolbarbutton" display="xul:button"
  40.            extends="chrome://global/content/bindings/toolbarbutton.xml#toolbarbutton">
  41.     <resources>
  42.       <stylesheet src="chrome://yasearch/skin/toolbarbutton.css"/>
  43.     </resources>
  44.     
  45.     <content>
  46.       <children includes="observes|template|menupopup|tooltip"/>
  47.       <xul:stack class="icons-holder">
  48.         <xul:image class="toolbarbutton-icon" xbl:inherits="validate,src=image,toolbarmode,buttonstyle"/>
  49.         <xul:vbox anonid="state-icons-container" onclick="this.previousSibling.click()">
  50.           <xul:image anonid="pause-icon" xbl:inherits="paused=yaAuthDisabled"/>
  51.         </xul:vbox>
  52.       </xul:stack>
  53.       <xul:label class="toolbarbutton-text" crop="right" flex="1"
  54.                  xbl:inherits="value=label,accesskey,crop,toolbarmode,buttonstyle"/>
  55.       <xul:label class="yasearch-toolbarbutton-text" crop="right" flex="1"
  56.                  xbl:inherits="value=yaLabel,accesskey,crop,toolbarmode,buttonstyle"/>
  57.     </content>
  58.   </binding>
  59.   
  60.   <binding id="extend-toolbarbutton-base" display="xul:menu"
  61.            extends="chrome://global/content/bindings/button.xml#menu-button-base">
  62.     <resources>
  63.       <stylesheet src="chrome://global/skin/toolbarbutton.css"/>
  64.     </resources>
  65.     
  66.     <content>
  67.       <children includes="observes|template|menupopup|tooltip"/>
  68.       <xul:toolbarbutton class="box-inherit toolbarbutton-menubutton-button"
  69.                          anonid="button" flex="1" allowevents="true"
  70.                          xbl:inherits="yaLabel,yaAuthDisabled,disabled,crop,image,label,accesskey,command,
  71.                                        align,dir,pack,orient,toolbarmode,buttonstyle"/>
  72.       <xul:dropmarker type="menu-button" class="toolbarbutton-menubutton-dropmarker"
  73.                       xbl:inherits="align,dir,pack,orient,disabled,toolbarmode,buttonstyle,label"/>
  74.     </content>
  75.     
  76.     <implementation>
  77.       <property name="disabled">
  78.         <getter><![CDATA[
  79.           var attrName = this.hasAttribute("yaAuthDisabled") ? "yaAuthDisabled" : "disabled";
  80.           return this.getAttribute(attrName) == "true";
  81.         ]]></getter>
  82.         
  83.         <setter><![CDATA[
  84.           var attrName = this.hasAttribute("yaAuthDisabled") ? "yaAuthDisabled" : "disabled";
  85.           
  86.           if (!val && attrName == "disabled")
  87.             this.removeAttribute("disabled");
  88.           else
  89.             this.setAttribute(attrName, !!val);
  90.           
  91.           return this.disabled;
  92.         ]]></setter>
  93.       </property>
  94.       
  95.       <property name="_isItemNeedAuth" readonly="true">
  96.         <getter><![CDATA[
  97.           return this.hasAttribute("yaAuthDisabled");
  98.         ]]></getter>
  99.       </property>
  100.       
  101.       <property name="_isCounter" readonly="true">
  102.         <getter><![CDATA[
  103.           return /yasearch\-counter/.test(this.getAttribute("class"));
  104.         ]]></getter>
  105.       </property>
  106.       
  107.       <constructor>
  108.         <![CDATA[
  109.           if (this.parentNode.parentNode.localName == "toolbarpaletteitem" || !this._isItemNeedAuth)
  110.             return;
  111.           
  112.           var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  113.           
  114.           var tooltipId = "yasearch-toolbarbutton-counter-tooltip";
  115.           var tooltip = document.getElementById(tooltipId);
  116.           if (!tooltip) {
  117.             tooltip = document.createElementNS(XULNS, "tooltip");
  118.             tooltip.setAttribute("id", tooltipId);
  119.             tooltip.setAttribute("noautohide", "true");
  120.             tooltip.setAttribute("style", "-moz-binding: url('chrome://yasearch/content/yasearch.xml#extend-counters-tooltip') !important");
  121.             document.getElementById("mainPopupSet").appendChild(tooltip);
  122.           }
  123.           
  124.           this.setAttribute("tooltip", tooltipId);
  125.           this.setAttribute("yaCounterTooltiptext", this.getAttribute("tooltiptext") ||
  126.                                                     this.getAttribute("yaCounterTooltiptext"));//"double" constr from Customize
  127.           this.removeAttribute("tooltiptext");
  128.         ]]>
  129.       </constructor>
  130.     </implementation>
  131.     
  132.     <handlers>
  133.       <handler event="mousedown"><![CDATA[
  134.         if (!event.cancelBubble && event.target == this && this.disabled) {
  135.           Ya.checkOnCommandEvent(event);
  136.         }
  137.       ]]></handler>
  138.       <handler event="popupshowing"><![CDATA[
  139.         return !this.disabled;
  140.       ]]></handler>
  141.     </handlers>
  142.   </binding>
  143.   
  144.   <binding id="extend-mail-toolbarbutton"
  145.            extends="chrome://yasearch/content/yasearch.xml#extend-toolbarbutton-base">
  146.     <handlers>
  147.       <handler event="mousedown" phase="capturing"><![CDATA[
  148.         event.stopPropagation();
  149.         return true;
  150.       ]]></handler>
  151.       
  152.       <handler event="popupshowing" phase="capturing"><![CDATA[
  153.         event.stopPropagation();
  154.         return true;
  155.       ]]></handler>
  156.     </handlers>
  157.   </binding>
  158.   
  159.   <binding id="extend-counters-tooltip"
  160.            extends="chrome://global/content/bindings/popup.xml#tooltip">
  161.     <resources>
  162.       <stylesheet src="chrome://yasearch/skin/toolbar-items/counters-tooltip.css"/>
  163.     </resources>
  164.     
  165.     <content>
  166.       <children>
  167.         <xul:hbox>
  168.           <xul:label anonid="main-label" class="tooltip-label" flex="1"
  169.                      yaLabelNoAuthPrefix="&yasearch.counters.noauth.prefix;"
  170.                      yaLabelNoAuthPostfix="&yasearch.counters.noauth.postfix;"/>
  171.         </xul:hbox>
  172.         <xul:label class="tooltip-label" flex="1" value="&yasearch.counters.noauth.label;"/>
  173.       </children>
  174.     </content>
  175.     
  176.     <implementation>
  177.       <field name="_mainLabel">document.getAnonymousElementByAttribute(this, "anonid", "main-label");</field>
  178.       
  179.       <property name="_isUserHasAuth" readonly="true">
  180.         <getter><![CDATA[
  181.           return Components.classes["@yandex.ru/yasearch;1"]
  182.                            .getService(Components.interfaces.nsIYaSearch)
  183.                            .wrappedJSObject
  184.                            .isLogin;
  185.         ]]></getter>
  186.       </property>
  187.     </implementation>
  188.     
  189.     <handlers>
  190.       <handler event="popupshowing">
  191.       <![CDATA[
  192.         var ttNode = document.tooltipNode;
  193.         if (!ttNode || !ttNode.hasAttribute("yaCounterTooltiptext"))
  194.           return false;
  195.         
  196.         var showAuthTooltip = !ttNode.disabled || this._isUserHasAuth;
  197.         var nodeIsCounter = ttNode._isCounter;
  198.         
  199.         this.setAttribute("yaHasAuthMode", showAuthTooltip);
  200.         
  201.         var tooltiptext =
  202.             (showAuthTooltip ? "" : ttNode.getAttribute("yaNeedAuthTooltiptext")) ||
  203.             ttNode.getAttribute("yaCounterTooltiptext") ||
  204.             "";
  205.         
  206.         let textArray = [tooltiptext];
  207.         let label = this._mainLabel;
  208.         
  209.         if (nodeIsCounter && tooltiptext && !showAuthTooltip) {
  210.           let fix = label.getAttribute("yaLabelNoAuthPrefix");
  211.           if (fix) {
  212.             textArray.unshift(fix);
  213.             
  214.             if (nodeIsCounter && tooltiptext)
  215.               textArray[1] = tooltiptext.replace(/^./, function(aChar) aChar.toLowerCase());
  216.           }
  217.           
  218.           fix = label.getAttribute("yaLabelNoAuthPostfix");
  219.           if (fix)
  220.             textArray.push(fix);
  221.         }
  222.         
  223.         label.setAttribute("value", textArray.join(" "));
  224.         
  225.         return true;
  226.       ]]>
  227.       </handler>
  228.     </handlers>
  229.   </binding>
  230.   
  231.   <binding id="extend-login-toolbarbutton"
  232.            extends="chrome://yasearch/content/yasearch.xml#extend-toolbarbutton">
  233.     <resources>
  234.       <stylesheet src="chrome://yasearch/skin/toolbar-items/login.css"/>
  235.     </resources>
  236.     
  237.     <content>
  238.       <children includes="observes|template|menupopup|tooltip"/>
  239.       <xul:image class="toolbarbutton-icon" xbl:inherits="validate,src=image,toolbarmode,buttonstyle"/>
  240.       <xul:label class="toolbarbutton-text" crop="right" flex="1"
  241.                  xbl:inherits="value=label,accesskey,crop,toolbarmode,buttonstyle"/>
  242.       <xul:yasearchloginlabel xbl:inherits="value=yaLabel,accesskey,crop,toolbarmode,buttonstyle"
  243.                               yaHiddenLoginLabel="&yasearch.go-login.hidden-login.label;"/>
  244.     </content>
  245.   </binding>
  246.   
  247.   <binding id="extend-login-toolbarbutton-label">
  248.     <content>
  249.       <xul:label anonid="login-start"/>
  250.       <xul:label anonid="login-middle"/>
  251.       <xul:label anonid="login-middle-3"/>
  252.       <xul:label anonid="login-middle-2"/>
  253.       <xul:label anonid="login-middle-1"/>
  254.     </content>
  255.     
  256.     <implementation implements="nsIObserver">
  257.       <field name="_kMaxLength">12</field>
  258.       <field name="_isChanging">false</field>
  259.       <field name="_showLoginPrefName">"yasearch.general.ui.mybar.login.show"</field>
  260.       
  261.       <constructor>
  262.         <![CDATA[
  263.           this._refreshLabel();
  264.           
  265.           Components.classes["@mozilla.org/preferences-service;1"]
  266.                     .getService(Components.interfaces.nsIPrefBranchInternal)
  267.                     .addObserver(this._showLoginPrefName, this, false);
  268.           
  269.           this._isInited = true;
  270.         ]]>
  271.       </constructor>
  272.       
  273.       <destructor>
  274.         <![CDATA[
  275.           if (!this._isInited)
  276.             return;
  277.           
  278.           Components.classes["@mozilla.org/preferences-service;1"]
  279.                     .getService(Components.interfaces.nsIPrefBranchInternal)
  280.                     .removeObserver(this._showLoginPrefName, this);
  281.           
  282.           this._isInited = false;
  283.         ]]>
  284.       </destructor>
  285.       
  286.       <property name="isLoginVisible" readonly="true">
  287.         <getter><![CDATA[
  288.           return Components.classes["@mozilla.org/preferences-service;1"]
  289.                            .getService(Components.interfaces.nsIPrefBranch2)
  290.                            .getBoolPref(this._showLoginPrefName);
  291.         ]]></getter>
  292.       </property>
  293.       
  294.       <method name="_refreshLabel">
  295.         <body><![CDATA[
  296.           this._isChanging = true;
  297.           
  298.           var newValue = this.getAttribute("value") || "";
  299.           if (newValue == "0")
  300.             newValue = "";
  301.           
  302.           if (!this.isLoginVisible)
  303.             newValue = this.getAttribute("yaHiddenLoginLabel") || "";
  304.           
  305.           document.getBindingParent(this).parentNode.setAttribute("yaDisplayedLogin", newValue);
  306.           
  307.           var me = this;
  308.           function setLabelValue(aType, aValue) {
  309.             document.getAnonymousElementByAttribute(me, "anonid", "login-" + aType)
  310.                     .setAttribute("value", aValue);
  311.           }
  312.           
  313.           if (newValue.length > this._kMaxLength) {
  314.             var i=0;
  315.             setLabelValue("start", newValue[i++]);
  316.             setLabelValue("middle", newValue.substr(i, i += (this._kMaxLength-5)));
  317.             setLabelValue("middle-3", newValue.substr(++i, 1));
  318.             setLabelValue("middle-2", newValue.substr(++i, 1));
  319.             setLabelValue("middle-1", newValue.substr(++i, 1));
  320.           } else {
  321.             setLabelValue("start", newValue[0] || "");
  322.             setLabelValue("middle", newValue.substr(1));
  323.             setLabelValue("middle-3", "");
  324.             setLabelValue("middle-2", "");
  325.             setLabelValue("middle-1", "");
  326.           }
  327.           
  328.           this._isChanging = false;
  329.         ]]></body>
  330.       </method>
  331.       
  332.       <method name="observe">
  333.         <parameter name="aSubject"/>
  334.         <parameter name="aTopic"/>
  335.         <parameter name="aData"/>
  336.         <body><![CDATA[
  337.           switch (aTopic) {
  338.             case "nsPref:changed":
  339.               if (aData == this._showLoginPrefName)
  340.                 this._refreshLabel();
  341.               break;
  342.             
  343.             default:
  344.               break;
  345.           }
  346.         ]]></body>
  347.       </method>
  348.     </implementation>
  349.     
  350.     <handlers>
  351.       <handler event="DOMAttrModified">
  352.         <![CDATA[
  353.           if (!this._isChanging && "value" == event.attrName.toLowerCase() && event.prevValue != event.newValue)
  354.             this._refreshLabel();
  355.         ]]>
  356.       </handler>
  357.     </handlers>
  358.   </binding>
  359.   
  360.   <binding id="extend-bookmarks-toolbarbutton"
  361.            extends="chrome://yasearch/content/yasearch.xml#extend-toolbarbutton-base">
  362.     <implementation implements="nsIDOMEventListener, nsIObserver">
  363.       <property name="nsIYa">
  364.         <getter><![CDATA[
  365.           if (!this._nsIYa)
  366.             this._nsIYa = Components.classes["@yandex.ru/yasearch;1"]
  367.                                     .getService(Components.interfaces.nsIYaSearch)
  368.                                     .wrappedJSObject;
  369.           return this._nsIYa;
  370.         ]]></getter>
  371.       </property>
  372.       
  373.       <property name="mTooltip" readonly="true"
  374.                 onget="return document.getElementById('yasearch-bookmarks-tooltip')"/>
  375.       
  376.       <field name="mPrefsNamePrefix">"yasearch.general.ui.bookmarks."</field>
  377.       
  378.       <field name="CLICK_ACTIONS">({
  379.         OPEN_MENU: 0,
  380.         ADD_IN_DIALOG: 1,
  381.         ADD_IN_BACKGROUND: 2
  382.       })</field>
  383.       
  384.       <property name="addInBackgroundEnabled">
  385.         <getter><![CDATA[
  386.           return !!(this.mCurrentClickAction === this.CLICK_ACTIONS.ADD_IN_BACKGROUND);
  387.         ]]></getter>
  388.       </property>
  389.       
  390.       <property name="mCurrentClickAction">
  391.         <getter><![CDATA[
  392.           return parseInt(this.getAttribute("yaCurrentClickAction"), 10) || 0;
  393.         ]]></getter>
  394.         <setter><![CDATA[
  395.           this.setAttribute("yaCurrentClickAction", val);
  396.           
  397.           this.setAttribute("yaCounterTooltiptext",
  398.               this.nsIYa.getString(val == this.CLICK_ACTIONS.OPEN_MENU ?
  399.                                           "bookmark.button.tooltiptext.open" :
  400.                                           "bookmark.button.tooltiptext.add"));
  401.         ]]></setter>
  402.       </property>
  403.       
  404.       <constructor><![CDATA[
  405.         if (this.parentNode.parentNode.localName == "toolbarpaletteitem")
  406.           return;
  407.         
  408.         if (this.mTooltip)
  409.           this.mTooltip.addEventListener("popupshowing", this, true);
  410.         
  411.         this.mCurrentClickAction = Components.classes["@mozilla.org/preferences-service;1"]
  412.                                              .getService(Components.interfaces.nsIPrefBranch2)
  413.                                              .getIntPref(this.mPrefsNamePrefix + "action");
  414.         
  415.         Components.classes["@mozilla.org/preferences-service;1"]
  416.                   .getService(Components.interfaces.nsIPrefBranchInternal)
  417.                   .addObserver(this.mPrefsNamePrefix, this, false);
  418.         
  419.         YaProgressListener.addListener(this.mLocationListener);
  420.         
  421.         var os = Components.classes["@mozilla.org/observer-service;1"]
  422.                            .getService(Components.interfaces.nsIObserverService);
  423.         os.addObserver(this, "Ya-Refresh-Data", false);
  424.         
  425.         this.rebuildMenupopup();
  426.         
  427.         this._isInited = true;
  428.       ]]></constructor>
  429.       
  430.       <destructor><![CDATA[
  431.         this.yaDestroy();
  432.       ]]></destructor>
  433.       
  434.       <method name="yaDestroy">
  435.         <body><![CDATA[
  436.           if (!this._isInited)
  437.             return;
  438.  
  439.           var os = Components.classes["@mozilla.org/observer-service;1"]
  440.                              .getService(Components.interfaces.nsIObserverService);
  441.           os.removeObserver(this, "Ya-Refresh-Data");
  442.  
  443.           Components.classes["@mozilla.org/preferences-service;1"]
  444.                     .getService(Components.interfaces.nsIPrefBranchInternal)
  445.                     .removeObserver(this.mPrefsNamePrefix, this);
  446.  
  447.           YaProgressListener.removeListener(this.mLocationListener);
  448.           this._clearUpdateBookmarkedTimer();
  449.  
  450.           if (this.mTooltip)
  451.             this.mTooltip.removeEventListener("popupshowing", this, true);
  452.           
  453.           this._isInited = false;
  454.         ]]></body>
  455.       </method>
  456.       
  457.       <method name="observe">
  458.         <parameter name="aSubject"/>
  459.         <parameter name="aTopic"/>
  460.         <parameter name="aData"/>
  461.         <body><![CDATA[
  462.           switch (aTopic) {
  463.             case "nsPref:changed":
  464.               var prefsvc = aSubject.QueryInterface(Components.interfaces.nsIPrefBranch2);
  465.               var prefName = aData.split(this.mPrefsNamePrefix)[1];
  466.               
  467.               switch (prefName) {
  468.                 case "action":
  469.                   this.mCurrentClickAction = prefsvc.getIntPref(aData);
  470.                   break;
  471.                 
  472.                 case "showaddtofolderontop":
  473.                   this.nsIYa.yaBookmarks.refreshBookmarksDOMMenu();
  474.                   break;
  475.                 
  476.                 default:
  477.                   break;
  478.               }
  479.               break;
  480.             
  481.             case "Ya-Refresh-Data":
  482.               switch (aData) {
  483.                 case "bookmarks":
  484.                   this.rebuildMenupopup();
  485.                 case "bookmarks-url-status":
  486.                   this.updateBookmarkedState(gBrowser.currentURI);
  487.                   break;
  488.               }
  489.               break;
  490.             
  491.             default:
  492.               break;
  493.           }
  494.         ]]></body>
  495.       </method>
  496.       
  497.       <method name="rebuildMenupopup">
  498.         <body><![CDATA[
  499.           if (this.open)
  500.             this.open = false;
  501.           
  502.           this.nsIYa.DOMUtils.replaceChildNodes(this.nsIYa.bookmarksDOMMenu, this);
  503.           this.getBookmarkedURI();
  504.         ]]></body>
  505.       </method>
  506.       
  507.       <method name="_yaFillTooltip">
  508.         <parameter name="aAttrArray"/>
  509.         <body>
  510.         <![CDATA[
  511.           var rows = this.mTooltip.getElementsByTagName("row");
  512.           
  513.           var row, i=0;
  514.           while ((row = rows.item(i))) {
  515.             if (aAttrArray[i]) {
  516.               row.style.display = "";
  517.               row.lastChild.setAttribute("value", aAttrArray[i].replace(/[\r\n]/g, " "));
  518.             } else {
  519.               row.style.display = "none";
  520.             }
  521.             i++;
  522.           }
  523.           
  524.         ]]>
  525.         </body>
  526.       </method>
  527.       
  528.       <method name="handleEvent">
  529.         <parameter name="aEvent"/>
  530.         <body><![CDATA[
  531.           switch (aEvent.type) {
  532.             case "popupshowing":
  533.               var tooltipNode = document.tooltipNode;
  534.               
  535.               this._yaFillTooltip([tooltipNode.getAttribute("statustext"),
  536.                                    tooltipNode.getAttribute("label"),
  537.                                    tooltipNode.getAttribute("descr")]);
  538.               break;
  539.             
  540.             default:
  541.               break;
  542.           }
  543.         ]]></body>
  544.       </method>
  545.       
  546.       <field name="mLocationListener"><![CDATA[({
  547.         _self: this,
  548.         
  549.         observe: function() {
  550.           if (arguments[0] == "onWindowLocationChange")
  551.             this._self.updateBookmarkedState(arguments[3]);
  552.         }
  553.       })]]></field>
  554.       
  555.       <field name="_updateBookmarkedStateTimer">null</field>
  556.       
  557.       <method name="_clearUpdateBookmarkedTimer">
  558.         <body><![CDATA[
  559.           if (this._updateBookmarkedStateTimer) {
  560.             this._updateBookmarkedStateTimer.cancel();
  561.             this._updateBookmarkedStateTimer = null;
  562.           }
  563.         ]]></body>
  564.       </method>
  565.       
  566.       <method name="updateBookmarkedState">
  567.         <parameter name="aLocation"/>
  568.         <body><![CDATA[
  569.           this._clearUpdateBookmarkedTimer();
  570.           
  571.           var yaBookmarks = this.nsIYa.yaBookmarks;
  572.           var isBookmarked = yaBookmarks.isBookmarkedURIinCache(aLocation);
  573.           
  574.           this.setAttribute("yaBookmarked", isBookmarked);
  575.           
  576.           if (isBookmarked === null) {
  577.             var me = this;
  578.             this._updateBookmarkedStateTimer = new this.nsIYa.utils.G_Timer(
  579.               function() {
  580.                 me.setAttribute("yaBookmarked", me.getBookmarkedURI(aLocation).bookmarked);
  581.               }, 0
  582.             )
  583.           }
  584.         ]]></body>
  585.       </method>
  586.       
  587.       <method name="getBookmarkedURI">
  588.         <parameter name="aURI"/>
  589.         <body><![CDATA[
  590.           var uri = (typeof aURI !== "undefined") ?
  591.                         aURI :
  592.                         ((gBrowser && gBrowser.currentURI) ? gBrowser.currentURI : null);
  593.           
  594.           return this.nsIYa.yaBookmarks.isBookmarkedURI(uri);
  595.         ]]></body>
  596.       </method>
  597.       
  598.       <method name="conditionalAddBookmark">
  599.         <parameter name="aAddBookmarkInBackground"/>
  600.         <body><![CDATA[
  601.           var res = this.getBookmarkedURI();
  602.           
  603.           if (res && res.bookmarked === "url") {
  604.             Ya.addBookmark(res.folderId, res.id);
  605.           } else {
  606.             aAddBookmarkInBackground ?
  607.                 this.nsIYa.yaBookmarks.addBookmarkInBackground(gBrowser) :
  608.                 Ya.addBookmark();
  609.           }
  610.         ]]></body>
  611.       </method>
  612.       
  613.       <!-- not just 'handler'; menupopup in chevron -->
  614.       <method name="_doCommand">
  615.         <parameter name="aTarget"/>
  616.         <body><![CDATA[
  617.           if (aTarget.hasAttribute("anonid")) {
  618.             switch (aTarget.getAttribute("anonid")) {
  619.               case "menuitem-add":
  620.               case "menuitem-edit":
  621.                 this.conditionalAddBookmark();
  622.                 break;
  623.               
  624.               default:
  625.                 break;
  626.             }
  627.           }
  628.         ]]></body>
  629.       </method>
  630.       
  631.     </implementation>
  632.     
  633.     <handlers>
  634.       <handler event="command">
  635.         <![CDATA[
  636.         if (Ya.checkOnCommandEvent(event)) {
  637.           if (event.ctrlKey || event.metaKey || event.shiftKey) {
  638.             Ya.loadURI("zakladki.yandex.ru", event);
  639.           } else if (this.mCurrentClickAction == this.CLICK_ACTIONS.OPEN_MENU) {
  640.             this.open = !this.open;
  641.           } else {
  642.             this.conditionalAddBookmark(this.addInBackgroundEnabled);
  643.           }
  644.         }
  645.         ]]>
  646.       </handler>
  647.       
  648.       <handler event="popupshowing"><![CDATA[
  649.         if (event.target.localName == "menupopup" && event.target.parentNode == this) {
  650.           var res = this.getBookmarkedURI();
  651.           this.setAttribute("yaBookmarked", res ? res.bookmarked : null);
  652.           
  653.           if (this.mCurrentClickAction == this.CLICK_ACTIONS.OPEN_MENU)
  654.             this.setAttribute("checked", "true");
  655.         }
  656.       ]]></handler>
  657.       
  658.       <handler event="popuphiding"><![CDATA[
  659.         if (event.target.localName == "menupopup" && event.target.parentNode == this) {
  660.           this.setAttribute("checked", "false");
  661.         }
  662.       ]]></handler>
  663.     </handlers>
  664.   </binding>
  665.   
  666.   <binding id="yawintitle">
  667.     <resources>
  668.       <stylesheet src="chrome://yasearch/skin/misc.css"/>
  669.     </resources>
  670.     <content>
  671.       <xul:stack anonid="yawintitle-stack" xbl:inherits="mode" flex="1">
  672.         <xul:image anonid="yawintitle-stack-bg"/>
  673.         <xul:hbox flex="1" pack="center" align="center" yadraggable="true">
  674.           <xul:label crop="end" xbl:inherits="value=label"/>
  675.         </xul:hbox>
  676.         <xul:vbox flex="1" pack="center" align="right">
  677.           <xul:hbox anonid="buttons-box">
  678.             <xul:toolbarbutton class="title-button-top" tooltiptext="&yasearch._gen.window.top;"
  679.                                xbl:inherits="label,oncommand=onmode"/>
  680.             <xul:toolbarbutton class="title-button-bottom" tooltiptext="&yasearch._gen.window.bottom;"
  681.                                xbl:inherits="label,oncommand=onmode"/>
  682.             <xul:toolbarbutton tooltiptext="&yasearch._gen.window.close;"
  683.                                xbl:inherits="label,oncommand=onclose,disabled=dontclose"/>
  684.           </xul:hbox>
  685.         </xul:vbox>
  686.       </xul:stack>
  687.     </content>
  688.   </binding>
  689.  
  690.   <binding id="extend-tooltip-mail" extends="chrome://global/content/bindings/popup.xml#tooltip">
  691.     <content>
  692.       <children>
  693.         <xul:grid flex="1">
  694.           <xul:columns><xul:column/><xul:column flex="1"/></xul:columns>
  695.           <xul:rows>
  696.             <xul:row>
  697.               <xul:hbox pack="end"><xul:description value="&yasearch.mail.tooltip.from;"/></xul:hbox>
  698.               <xul:vbox><xul:description anonid="from" crop="end"> </xul:description></xul:vbox>
  699.             </xul:row>
  700.             <xul:row>
  701.               <xul:hbox pack="end"><xul:description value="&yasearch.mail.tooltip.subject;"/></xul:hbox>
  702.               <xul:vbox><xul:description anonid="subject" crop="end"> </xul:description></xul:vbox>
  703.             </xul:row>
  704.           </xul:rows>
  705.         </xul:grid>
  706.       </children>
  707.     </content>
  708.     
  709.     <implementation>
  710.       <field name="from">document.getAnonymousElementByAttribute(this, "anonid", "from");</field>
  711.       <field name="subject">document.getAnonymousElementByAttribute(this, "anonid", "subject");</field>
  712.     </implementation>
  713.     
  714.     <handlers>
  715.       <handler event="popupshowing">
  716.       <![CDATA[
  717.         var node = document.tooltipNode;
  718.         
  719.         if (!(node && node.hasAttribute("yamailfrom") && node.hasAttribute("yamailsubject")))
  720.           return false;
  721.         
  722.         if ("state" in this) {
  723.           function safe(s) {
  724.             s = s.replace(/^\s+/, "").replace(/\s+$/, "")
  725.                  .replace(/([\/\-&\?\.])/g, "$1\u200B")
  726.                  .replace(/(\S{5})(\S{5})/g, "$1\u200B$2");
  727.             
  728.             if (s.length > 512)
  729.               s = s.substr(0, 512) + "\u2026";
  730.             
  731.             return s;
  732.           }
  733.           
  734.           this.from.textContent = safe(node.getAttribute("yamailfrom"));
  735.           this.subject.textContent = safe(node.getAttribute("yamailsubject"));
  736.         } else {
  737.           this.from.setAttribute("value", node.getAttribute("yamailfrom"));
  738.           this.subject.setAttribute("value", node.getAttribute("yamailsubject"));
  739.         }
  740.         
  741.         return true;
  742.       ]]>
  743.       </handler>
  744.     </handlers>
  745.   </binding>
  746.   
  747.   <binding id="extend-cy-toolbarbutton"
  748.            extends="chrome://yasearch/content/yasearch.xml#extend-toolbarbutton-base">
  749.     
  750.     <implementation implements="nsIObserver">
  751.       <field name="_showCyValuePrefName">"yasearch.general.ui.show.cy.value"</field>
  752.       
  753.       <field name="mShowCyValue">false</field>
  754.       
  755.       <field name="mCurrentCyData">({ rang: 0 })</field>
  756.       
  757.       <field name="mTooltip">(this.hasAttribute('tooltip') ? document.getElementById(this.getAttribute('tooltip')) : null)</field>
  758.       
  759.       <method name="setCYData">
  760.         <parameter name="aCYData"/>
  761.         <body><![CDATA[
  762.           let data = aCYData || { rang: 0 };
  763.           let stateEnabed = !!(data.state & 8);
  764.           let label = stateEnabed ? data.value : "0";
  765.           
  766.           this.disabled = !stateEnabed;
  767.           
  768.           this.setAttribute("yaLabel", label);
  769.           this.style.MozImageRegion = "rect(0px, " + 16 * (data.rang+1) + "px, 16px, " + 16 * data.rang + "px)";
  770.           
  771.           this.mCurrentCyData = data;
  772.           
  773.           if (this.mTooltip && this.mTooltip.state == "open")
  774.             this.mTooltip.refreshCYData();
  775.         ]]></body>
  776.       </method>
  777.       
  778.       <method name="refreshLabel">
  779.         <body><![CDATA[
  780.           this.mShowCyValue = Components.classes["@mozilla.org/preferences-service;1"]
  781.                                         .getService(Components.interfaces.nsIPrefBranch2)
  782.                                         .getBoolPref(this._showCyValuePrefName);
  783.           
  784.           this.setAttribute("yaLabelHidden", !this.mShowCyValue);
  785.         ]]></body>
  786.       </method>
  787.       
  788.       <method name="observe">
  789.         <parameter name="aSubject"/>
  790.         <parameter name="aTopic"/>
  791.         <parameter name="aData"/>
  792.         <body><![CDATA[
  793.           switch (aTopic) {
  794.             case "nsPref:changed":
  795.               if (aData == this._showCyValuePrefName)
  796.                 this.refreshLabel();
  797.               break;
  798.             
  799.             default:
  800.               break;
  801.           }
  802.         ]]></body>
  803.       </method>
  804.       
  805.       <constructor><![CDATA[
  806.         if (this._isInited)
  807.           return;
  808.         
  809.         Components.classes["@mozilla.org/preferences-service;1"]
  810.                   .getService(Components.interfaces.nsIPrefBranchInternal)
  811.                   .addObserver(this._showCyValuePrefName, this, false);
  812.         
  813.         this.refreshLabel();
  814.         
  815.         this._isInited = true;
  816.       ]]></constructor>
  817.       
  818.       <destructor><![CDATA[
  819.         if (!this._isInited)
  820.           return;
  821.         
  822.         Components.classes["@mozilla.org/preferences-service;1"]
  823.                   .getService(Components.interfaces.nsIPrefBranchInternal)
  824.                   .removeObserver(this._showCyValuePrefName, this);
  825.         
  826.         this._isInited = false;
  827.       ]]></destructor>
  828.     </implementation>
  829.   </binding>
  830.   
  831.   <binding id="extend-tooltip-cy"
  832.            extends="chrome://global/content/bindings/popup.xml#tooltip">
  833.     <content>
  834.       <children>
  835.         <vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  836.           <description value="&yasearch.cy.full.label;"
  837.                        style="text-align:center; font-weight:bold"/>
  838.         </vbox>
  839.         <vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  840.               xbl:inherits="hidden=yaCYHasData">
  841.           <hbox>
  842.             <grid flex="1">
  843.               <columns><column flex="1"/></columns>
  844.               <rows>
  845.                 <row align="center">
  846.                   <description value="(...&yasearch.no-data.label;...)"
  847.                                style="margin-right:0px; text-align:center"/>
  848.                 </row>
  849.               </rows>
  850.             </grid>
  851.           </hbox>
  852.         </vbox>
  853.         <vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  854.               xbl:inherits="hidden=yaCYNoData">
  855.           <hbox>
  856.             <grid flex="1">
  857.               <columns><column/><column flex="1"/></columns>
  858.               <rows>
  859.                 <row>
  860.                   <label value="&yasearch.cy.data.theme.label;:" style="text-align:right"/>
  861.                   <label xbl:inherits="value=yaCYtheme"/>
  862.                 </row>
  863.                 <row>
  864.                   <label value="&yasearch.cy.data.domain.label;:" style="text-align:right"/>
  865.                   <label xbl:inherits="value=yaCYdomain"/>
  866.                 </row>
  867.                 <row>
  868.                   <label value="&yasearch.cy.data.region.label;:" style="text-align:right"/>
  869.                   <label xbl:inherits="value=yaCYregion"/>
  870.                 </row>
  871.                 <row>
  872.                   <label value="&yasearch.cy.data.value.label;:" style="text-align:right"/>
  873.                   <label xbl:inherits="value=yaCYvalue"/>
  874.                 </row>
  875.               </rows>
  876.             </grid>
  877.           </hbox>
  878.         </vbox>
  879.       </children>
  880.     </content>
  881.     
  882.     <implementation>
  883.       <property name="mTooltip" readonly="true"
  884.                 onget="return this.hasAttribute('tooltip') ? document.getElementById(this.getAttribute('tooltip')) : null"/>
  885.       
  886.       <method name="refreshCYData">
  887.         <body><![CDATA[
  888.           let tooltipNode = document.tooltipNode;
  889.           if (!(tooltipNode && tooltipNode.tagName === "toolbarbutton"))
  890.             return false;
  891.           
  892.           let data = tooltipNode.mCurrentCyData;
  893.           let stateEnabed = !!(data.state & 8);
  894.  
  895.           if (stateEnabed) {
  896.             ["theme", "domain", "region", "value"]
  897.             .forEach(function(aCyProp) {
  898.               this.setAttribute("yaCY" + aCyProp, data[aCyProp]);
  899.             }, this);
  900.           }
  901.  
  902.           this.setAttribute("yaCYNoData", !stateEnabed);
  903.           this.setAttribute("yaCYHasData", stateEnabed);
  904.           
  905.           return true;
  906.         ]]></body>
  907.       </method>
  908.     </implementation>
  909.     
  910.     <handlers>
  911.       <handler event="popupshowing">
  912.         <![CDATA[
  913.           return this.refreshCYData();
  914.         ]]>
  915.       </handler>
  916.     </handlers>
  917.   </binding>
  918. </bindings>