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 / filFB66E56B5A10E55458B31762FEEC3B3C < prev    next >
Extensible Markup Language  |  2010-07-12  |  10KB  |  281 lines

  1. <?xml version="1.0"?>
  2. <!DOCTYPE bindings SYSTEM "chrome://yasearch/locale/dialogs/welcome.dtd">
  3.  
  4. <bindings xmlns="http://www.mozilla.org/xbl"
  5.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  6.           xmlns:xbl="http://www.mozilla.org/xbl"
  7.           xmlns:html="http://www.w3.org/1999/xhtml">
  8.   
  9.   <binding id="status">
  10.     <resources>
  11.       <stylesheet src="chrome://yasearch/skin/dialogs/status.css"/>
  12.     </resources>
  13.     
  14.     <content>
  15.       <xul:vbox flex="1" tooltip="_child">
  16.         <xul:tooltip orient="vertical"
  17.                      noautohide="true" onpopupshowing="return _fillTooltip(this);"
  18.                      style="max-width:40em">
  19.           <xul:vbox flex="1">
  20.             <html:div/>
  21.           </xul:vbox>
  22.         </xul:tooltip>
  23.         <html:div class="ya-status" mode="text">
  24.           <!-- arrow -->
  25.           <html:div class="ya-status-arrow"/>
  26.             <html:div class="ya-status-border">
  27.               <html:div/>
  28.               <!-- content -->
  29.               <html:div class="ya-status-content">
  30.                 <!-- error -->
  31.                 <html:div class="ya-status-error">&yasearch.welcome.status.request.error.label; <html:span>&yasearch.welcome.status.request.error.close.label;</html:span></html:div>
  32.                 <!-- text -->
  33.                 <html:div class="ya-status-text"><html:span/><html:span class="ya-status-text-empty">&yasearch.welcome.status.empty.label;</html:span><html:div class="ya-status-fade"/></html:div>
  34.                 <!-- edit -->
  35.                 <html:div class="ya-status-edit">
  36.                     <html:div class="left">
  37.                     <html:textarea id="ya-status-textarea" class="ya-status-textarea"></html:textarea>
  38.                   </html:div>
  39.                   <html:div class="right">
  40.                     <xul:scrollbar orient="vertical"/>
  41.                     <html:div class="ya-status-ok"/>
  42.                   </html:div>
  43.                 </html:div>
  44.                 <!-- throbber -->
  45.                 <html:div class="ya-status-throbber"/>
  46.               </html:div>
  47.               <html:div/>
  48.             </html:div>
  49.         </html:div>
  50.       </xul:vbox>
  51.     </content>
  52.  
  53.     <implementation implements="nsIDOMEventListener">
  54.       <field name="status">document.getAnonymousElementByAttribute(this, "class", "ya-status")</field>
  55.       <field name="text">document.getAnonymousElementByAttribute(this, "class", "ya-status-text")</field>
  56.       <field name="edit">document.getAnonymousElementByAttribute(this, "class", "ya-status-textarea")</field>
  57.       <field name="content">document.getAnonymousElementByAttribute(this, "class", "ya-status-content")</field>
  58.       <field name="ok">document.getAnonymousElementByAttribute(this, "class", "ya-status-ok")</field>
  59.       <field name="error">document.getAnonymousElementByAttribute(this, "class", "ya-status-error")</field>
  60.  
  61.       <property name="value">
  62.         <setter><![CDATA[
  63.           this.theValue = val;
  64.           
  65.           var node = this.text.firstChild;
  66.           var n = this.text;
  67.           if (!node.firstChild)
  68.             node.appendChild(document.createTextNode(""));
  69.           
  70.           var textNode = node.firstChild;
  71.           var text = this.softHyphen(this.normalize(val));
  72.           textNode.nodeValue = text;
  73.           this.shade();
  74.           
  75.           this.text.setAttribute("empty", val == "" ? "true" : "false");
  76.         ]]></setter>
  77.         <getter><![CDATA[
  78.           return this.theValue;
  79.         ]]></getter>
  80.       </property>
  81.  
  82.       <constructor><![CDATA[
  83.         this.nsIYa = Cc["@yandex.ru/yasearch;1"].getService(Ci.nsIYaSearch).wrappedJSObject;
  84.       ]]></constructor>
  85.  
  86.       <method name="softHyphen">
  87.         <parameter name="text"/>
  88.         <body><![CDATA[
  89.           var result = "", space = 0;
  90.           for (var i = 0; i < text.length; i++) {
  91.             if (text.charAt(i) <= 32)
  92.               space = 0;
  93.             
  94.             result += text.charAt(i) + ((i > 22) || (space > 10) ? "\u200B" : "");
  95.             space++;
  96.           }
  97.           
  98.           text = result;
  99.           return text;
  100.         ]]></body>
  101.       </method>
  102.  
  103.       <method name="onTextClick">
  104.         <parameter name="event"/>
  105.         <body><![CDATA[
  106.           this.status.setAttribute("mode", "edit");
  107.           this.edit.value = this.value;
  108.           this.edit.focus();
  109.           this.edit.select();
  110.         ]]></body>
  111.       </method>
  112.  
  113.       <method name="normalize">
  114.         <parameter name="string"/>
  115.         <body><![CDATA[
  116.           return string.replace(/[\s\xA0]{2,}/g, ' ').replace(/(^[\s\xA0]+|[\s\xA0]+$)/g, '');
  117.         ]]></body>
  118.       </method>
  119.  
  120.       <method name="onOkClick">
  121.         <parameter name="event"/>
  122.         <body><![CDATA[
  123.           if (this.edit.value != this.value) {
  124.             this.value = this.normalize(this.edit.value);
  125.             this.request();
  126.           }
  127.           
  128.           this.status.setAttribute("mode", "text");
  129.         ]]></body>
  130.       </method>
  131.  
  132.       <method name="onErrorClick">
  133.         <parameter name="event"/>
  134.         <body><![CDATA[
  135.           this.status.removeAttribute("request");
  136.         ]]></body>
  137.       </method>
  138.  
  139.       <method name="request">
  140.         <body><![CDATA[
  141.           var xml = 
  142.             <entry xmlns="http://www.w3.org/2005/Atom" xmlns:y="yandex:data">
  143.               <category term="status" scheme="urn:wow.ya.ru:posttypes"/>
  144.               <content>{this.value}</content>
  145.             </entry>;
  146.           
  147.           var uid = this.nsIYa.yaAuth.session.id.split(".")[3];
  148.           var url = "http://api-yaru.yandex.ru/person/" + uid + "/post/";
  149.           var request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
  150.           
  151.           request.open("POST", url, true);
  152.           request.setRequestHeader("Content-Type", "application/atom+xml; type=entry; charset=utf-8");
  153.           request.setRequestHeader("Connection", "close");
  154.           
  155.           var target = request.QueryInterface(Ci.nsIDOMEventTarget);
  156.           var context = this;
  157.           target.addEventListener("load", this, false);
  158.           target.addEventListener("error", this, false);
  159.           
  160.           request.send(xml.toString());
  161.           
  162.           this.status.setAttribute("request", "wait");
  163.         ]]></body>
  164.       </method>
  165.       
  166.       <method name="handleEvent">
  167.         <parameter name="aEvent"/>
  168.         <body><![CDATA[
  169.           switch (aEvent.type) {
  170.             case "load":
  171.             case "error":
  172.               if (this.response)
  173.                 this.response(aEvent);
  174.               break;
  175.             
  176.             default:
  177.               break;
  178.           }
  179.         ]]></body>
  180.       </method>
  181.       
  182.       <method name="response">
  183.         <parameter name="event"/>
  184.         <body><![CDATA[
  185.           var request = event.target;
  186.           if (request && request.responseXML) {
  187.             this.status.removeAttribute("request");
  188.           } else {
  189.             this.status.setAttribute("request", "error");
  190.           }
  191.         ]]></body>
  192.       </method>
  193.  
  194.       <method name="onEditKeyDown">
  195.         <parameter name="event"/>
  196.         <body><![CDATA[
  197.           switch (event.keyCode) {
  198.             case event.DOM_VK_RETURN:
  199.             case event.DOM_VK_ENTER:
  200.               this.onOkClick(event);
  201.               break;
  202.             
  203.             case event.DOM_VK_CANCEL:
  204.             case event.DOM_VK_ESCAPE:
  205.               event.stopPropagation();
  206.               event.preventDefault();
  207.               this.status.setAttribute("mode", "text");
  208.               break;
  209.           }
  210.         ]]></body>
  211.       </method>
  212.  
  213.       <method name="contains">
  214.         <parameter name="child"/>
  215.         <parameter name="parent"/>
  216.         <body><![CDATA[
  217.           return (child == parent) || (parent.compareDocumentPosition(child) & Node.DOCUMENT_POSITION_CONTAINED_BY);
  218.         ]]></body>
  219.       </method>
  220.  
  221.       <method name="shade">
  222.         <body><![CDATA[
  223.           setTimeout(function(context) {
  224.             if (context && "shadeEx" in context)
  225.               context.shadeEx();
  226.           }, 100, this);
  227.         ]]></body>
  228.       </method>
  229.  
  230.       <method name="shadeEx">
  231.         <body><![CDATA[
  232.           if (this.text.clientHeight >= this.text.scrollHeight - 3)
  233.             this.text.removeAttribute("overflow");
  234.           else
  235.             this.text.setAttribute("overflow", "overflow");
  236.         ]]></body>
  237.       </method>
  238.       
  239.       <method name="_fillTooltip">
  240.         <parameter name="aTooltip"/>
  241.         <body><![CDATA[
  242.           var tooltiptext = this.softHyphen(this.normalize(this.value));
  243.           
  244.           if (!tooltiptext)
  245.             return false;
  246.           
  247.           if (tooltiptext.length > 1000)
  248.             tooltiptext = tooltiptext.substr(0, 1000) + "\u2026";
  249.           
  250.           var descr = aTooltip.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "div")[0];
  251.           descr.textContent = tooltiptext;
  252.           
  253.           aTooltip.style.height = "";
  254.           
  255.           window.setTimeout(function() {
  256.             aTooltip.style.height = aTooltip.boxObject.height + "px";
  257.           }, 0);
  258.           
  259.           return true;
  260.         ]]></body>
  261.       </method>
  262.       
  263.     </implementation>
  264.     
  265.     <handlers>
  266.       <handler event="keydown"><![CDATA[
  267.         if (this.contains(event.originalTarget, this.edit))
  268.           this.onEditKeyDown(event);
  269.       ]]></handler>
  270.  
  271.       <handler event="click"><![CDATA[
  272.         if (this.contains(event.originalTarget, this.error))
  273.           this.onErrorClick(event);
  274.         else if (this.contains(event.originalTarget, this.ok))
  275.           this.onOkClick(event);
  276.         else if (this.contains(event.originalTarget, this.text))
  277.           this.onTextClick(event);
  278.       ]]></handler>   
  279.     </handlers>
  280.   </binding>
  281. </bindings>