home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0"?>
- <!DOCTYPE bindings [
- <!ENTITY % yasearchDTD SYSTEM "chrome://yasearch/locale/yasearch.dtd">
- %yasearchDTD;
- ]>
- <bindings xmlns="http://www.mozilla.org/xbl"
- xmlns:xbl="http://www.mozilla.org/xbl"
- xmlns:html="http://www.w3.org/1999/xhtml"
- xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
-
- <binding id="balloon"
- extends="chrome://global/content/bindings/popup.xml#panel">
- <resources>
- <stylesheet src="chrome://yasearch/skin/translate/balloon.css"/>
- </resources>
-
- <content>
- <html:div class="border">
- <html:div>
- <html:div
- ><html:div class="translations"
- /><html:div class="more"
- ><html:span>&yasearch.translate.balloon.more.label;</html:span
- ></html:div
- ></html:div>
- </html:div>
- </html:div>
- </content>
-
- <implementation implements="nsIDOMEventListener">
- <field name="_tooltipController"/>
-
- <field name="_timeoutNodeCheckId"/>
- <field name="_mouseoutTimestamp">0</field>
- <field name="_mouseOver">false</field>
-
- <field name="_hideEvents">["mousemove", "mouseout", "click", "DOMAttrModified"]</field>
-
- <field name="_translations">document.getAnonymousElementByAttribute(this, "class", "translations")</field>
- <field name="_more">document.getAnonymousElementByAttribute(this, "class", "more")</field>
-
- <property name="tooltipController"
- onget="return this._tooltipController;"
- onset="this._tooltipController = val;"/>
-
- <property name="from"
- onget="return this._from;"
- onset="this._from = val;"/>
-
- <property name="to"
- onget="return this._to;"
- onset="this._to = val;"/>
-
- <property name="language"
- readonly="true"
- onget="return this.from != 'ru' ? this.from : this.to"/>
-
- <property name="translations">
- <setter><![CDATA[
- let translations = this._translations;
-
- while (translations.firstChild)
- translations.removeChild(translations.firstChild);
-
- const kHTMLNS = "http://www.w3.org/1999/xhtml";
- var olTranslations = document.createElementNS(kHTMLNS, "ol");
-
- let language = document.createElementNS(kHTMLNS, "div");
- language.className = "language";
- language.textContent = "(" + Ya.stringBundleSet.getString("translate.balloon.language." + this.from) + ")";
-
- (val || []).forEach(function(translation) {
- let liTranslation = document.createElementNS(kHTMLNS, "li");
- liTranslation.className = "translation";
-
- let word = document.createElementNS(kHTMLNS, "div");
- word.className = "word";
- word.textContent = translation.word + "\u00a0";
-
- liTranslation.appendChild(word);
- liTranslation.appendChild(language.cloneNode(true));
-
- let parts = translation.parts;
- let part = translation.part;
-
- let olParts = document.createElementNS(kHTMLNS, "ol");
- olParts.className = "parts";
-
- for (let j = 0; j < parts.length; j++) {
- let partOfSpeech = parts[j];
- let words = part[partOfSpeech];
-
- let liPart = document.createElementNS(kHTMLNS, "li");
- liPart.className = "part";
-
- let divPartOfSpeech = document.createElementNS(kHTMLNS, "div");
- divPartOfSpeech.className = "partOfSpeech";
- divPartOfSpeech.textContent = "(" + partOfSpeech + ")";
-
- liPart.appendChild(divPartOfSpeech);
-
- let spanWords = document.createElementNS(kHTMLNS, "span");
- spanWords.textContent = words.join(", ") + "\u00a0";
-
- liPart.appendChild(spanWords);
-
- olParts.appendChild(liPart);
- }
-
- liTranslation.appendChild(olParts);
-
- olTranslations.appendChild(liTranslation);
-
- }, this);
-
- translations.appendChild(olTranslations);
- ]]></setter>
- </property>
-
- <method name="contains">
- <parameter name="aChild"/>
- <parameter name="aParent"/>
- <body><![CDATA[
- let parent = arguments.length == 1 ? this : aParent;
-
- try {
- return (aChild == parent) ||
- !!(parent.compareDocumentPosition(aChild) & Node.DOCUMENT_POSITION_CONTAINED_BY);
- } catch(e) {}
-
- return false;
- ]]></body>
- </method>
-
- <method name="showMore">
- <parameter name="event"/>
- <body><![CDATA[
- this.tooltipController.hideBalloon();
- Ya.loadURI(this.url, "new-tab", {action: 630});
- ]]></body>
- </method>
-
- <method name="_checkForNewNode">
- <parameter name="aSelf"/>
- <parameter name="aRangeParent"/>
- <parameter name="aRangeOffset"/>
- <body><![CDATA[
- aSelf._clearNodeCheckTimeout();
- aSelf.tooltipController.checkForNewNode(aRangeParent, aRangeOffset);
- ]]></body>
- </method>
-
- <method name="handleEvent">
- <parameter name="aEvent"/>
- <body><![CDATA[
- switch (aEvent.type) {
- case "DOMAttrModified":
- if (aEvent.attrName == "active" &&
- aEvent.target == aEvent.originalTarget &&
- aEvent.newValue != "true") {
-
- this.tooltipController.hideBalloon();
- }
-
- break;
-
- case "click":
- this.tooltipController.hideBalloon();
- break;
-
- case "mousemove":
- if (!this._timeoutNodeCheckId && ((new Date().getTime() - this._mouseoutTimestamp) > 100)) {
- this._timeoutNodeCheckId = setTimeout(this._checkForNewNode, 200,
- this, aEvent.rangeParent, aEvent.rangeOffset);
- }
- break;
-
- case "mouseout":
- if (!aEvent.relatedTarget) {
-
- this.tooltipController.clearShowTimeout();
-
- if (aEvent.explicitOriginalTarget == this) {
- this._mouseoutTimestamp = new Date().getTime();
- this._clearNodeCheckTimeout();
-
- setTimeout(function(aSelf) {
- if (aSelf && aSelf.state == "open" && !aSelf.tooltipController.showTimeout) {
- aSelf.tooltipController.hideBalloon();
- }
- }, 200, this);
-
- } else {
- setTimeout(function(aSelf) {
- if (aSelf && aSelf.state == "open" && !aSelf._mouseOver && !aSelf.tooltipController.showTimeout) {
- aSelf.tooltipController.hideBalloon();
- }
- }, 200, this);
- }
-
- } else if (aEvent.target.localName == "tabbrowser" && !this.contains(aEvent.relatedTarget)) {
- this.tooltipController.hideBalloon();
- }
-
- break;
-
- default:
- break;
- }
- ]]></body>
- </method>
-
- <method name="_clearNodeCheckTimeout">
- <body><![CDATA[
- if (this._timeoutNodeCheckId) {
- clearTimeout(this._timeoutNodeCheckId);
- this._timeoutNodeCheckId = null;
- }
- ]]></body>
- </method>
-
- <destructor><![CDATA[
- this.tooltipController = null;
- ]]></destructor>
-
- </implementation>
-
- <handlers>
- <handler event="click"><![CDATA[
- if (this.contains(event.originalTarget, this._more))
- this.showMore(event);
- ]]></handler>
-
- <handler event="mousemove" phase="capturing"><![CDATA[
- event.stopPropagation();
- ]]></handler>
-
- <handler event="mouseover"><![CDATA[
- this.tooltipController.clearShowTimeout();
- this._mouseOver = true;
- ]]></handler>
-
- <handler event="mouseout"><![CDATA[
- this._mouseOver = false;
- ]]></handler>
-
- <handler event="popupshowing"><![CDATA[
- this._hideEvents.forEach(function(aEventName) {
- window.addEventListener(aEventName, this, false, true);
- }, this);
-
- if (this.getAttribute("yaIsLinux") == "true") {
- this.style.height = "";
- window.setTimeout(function(aSelf) {
- aSelf.style.height = aSelf.boxObject.height + "px";
- }, 0, this);
- }
- ]]></handler>
-
- <handler event="popuphiding"><![CDATA[
- this._hideEvents.forEach(function(aEventName) {
- window.removeEventListener(aEventName, this, false, true);
- }, this);
-
- this._clearNodeCheckTimeout();
-
- this._mouseOver = false;
- ]]></handler>
- </handlers>
- </binding>
- </bindings>