<?xml version='1.0'?>
<!DOCTYPE bindings [
<!ENTITY % settings SYSTEM "/native/fx/bookmarks.dialog.dtd">
%settings;
]>

<bindings xmlns:html="http://www.w3.org/1999/xhtml" xmlns:xbl="http://www.mozilla.org/xbl" xmlns="http://www.mozilla.org/xbl" xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    
    <binding id="tags-container">
        <resources>
            <stylesheet src="bookmarks.css"/>
        </resources>

        <content>
            <xul:textbox xbl:inherits="value,maxlength,disabled,emptytext=placeholder,placeholder"/>

            <xul:hbox>
                <xul:vbox anonid="tags-cloud-container" flex="1">
                    <html:div anonid="tags-cloud" style="display:none;"/>
                </xul:vbox>
            </xul:hbox>

            <xul:tooltip anonid="maxLengthTooltip" noautohide="true" orient="vertical">
                <xul:description value="&bookmarks.maxLengthTooltipDefaultText;"/>
            </xul:tooltip>
        </content>

        <implementation>

            <destructor><![CDATA[this._clearMaxLengthTooltipTimeout();
this._clearTextInputTimeout();]]></destructor>

            <field name="_lastCursorPosition">0</field>

            <field name="_mTextbox">document.getAnonymousNodes(this)[0]</field>
            <field name="_tagsCloud">document.getAnonymousElementByAttribute(this, "anonid", "tags-cloud")</field>

            <field name="_lastTextValue">null</field>
            <field name="_lastTextComplete">null</field>
            <field name="_startTextValue">null</field>

            <field name="_arrAllTags">[]</field>
            <field name="_arrTags">[]</field>

            <field name="_mMaxLengthTooltip">document.getAnonymousElementByAttribute(this, "anonid", "maxLengthTooltip");</field>

            <field name="_maxLengthTooltipTimeout">null</field>
            <field name="_handleTextInputTimeout">null</field>

            <property name="value">
                <getter><![CDATA[var tagsArray = [];
var addedTagsLowerCase = [];
this._getTagsArray(this._mTextbox.value).forEach(function (tag) {
var tagLC = tag.toLowerCase();
if (addedTagsLowerCase.indexOf(tagLC) == - 1)
{
tagsArray.push(tag);
addedTagsLowerCase.push(tagLC);
}

}
);
return tagsArray.join(",");]]></getter>
            </property>

            <property name="startValue">
                <getter><![CDATA[return this._startTextValue;]]></getter>
            </property>

            <property name="disabled" onget="return this._mTextbox.disabled;" onset="this._mTextbox.disabled = val; return val;"/>

            <property name="maxLength" readonly="true">
                <getter><![CDATA[return this.hasAttribute("maxlength") ? parseInt(this.getAttribute("maxlength"),10) : 0;]]></getter>
            </property>

            <field name="_tagMaxLength">this.hasAttribute("yatagmaxlength") ? parseInt(this.getAttribute("yatagmaxlength"), 10) : 0</field>

            <property name="_selectionStart" onget="return this._mTextbox.selectionStart;"/>

            <property name="_selectionEnd" onget="return this._mTextbox.selectionEnd;"/>

            <method name="_selectTextRange">
                <parameter name="startIndex"/>
                <parameter name="endIndex"/>
                <body><![CDATA[this._mTextbox.setSelectionRange(startIndex,endIndex);
const nsISelectionController = Components.interfaces.nsISelectionController;
this._mTextbox.editor.selectionController.scrollSelectionIntoView(nsISelectionController.SELECTION_NORMAL,nsISelectionController.SELECTION_FOCUS_REGION,false);]]></body>
            </method>

            <method name="initWithValue">
                <parameter name="strBookmarkTags"/>
                <parameter name="arrAllTags"/>
                <body><![CDATA[this._arrAllTags = arrAllTags;
var arrBookmarkTags = this._getTagsArray(strBookmarkTags || "");
this._startTextValue = arrBookmarkTags.join(",");
this.trySetNewValue(arrBookmarkTags.join(", "),true);
this._arrTags = this._processTags(arrBookmarkTags,arrAllTags,10);
this.showTags(this._arrTags);]]></body>
            </method>

            <method name="addTag">
                <parameter name="tagElement"/>
                <body><![CDATA[if (! tagElement)
return false;
var spanDisabled = tagElement.getAttribute("disabled");
var txtValue = this._mTextbox.value;
var cleanValue = txtValue ? txtValue.replace(/^[,\s]*/,"").replace(/\s+,/g,",").replace(/\s+/g," ").replace(/,+/g,",").replace(/[,\s]*$/,", ") : "";
switch (spanDisabled) {
case "false":
cleanValue += tagElement.getAttribute("tooltiptext") + ", ";
spanDisabled = "true";
break;
case "true":
let re = new RegExp("(^|,\\s?)" + tagElement.getAttribute("tooltiptext").replace(/(\-|\.|\||\+|\?|\$|\(|\)|\[|\])/g,"\\$1") + "(,\\s?|$)", "gi");
while (re.test(cleanValue)) {
cleanValue = cleanValue.replace(re,"$1");
}

spanDisabled = "false";
break;
default:
return false;
}

if (this.trySetNewValue(cleanValue))
{
tagElement.setAttribute("disabled",spanDisabled);
return true;
}

return false;]]></body>
            </method>

            <method name="showTags">
                <parameter name="arrTags"/>
                <body><![CDATA[var tagsCloud = this._tagsCloud;
var style = tagsCloud.style;
var frag = document.createDocumentFragment();
Array.forEach(arrTags,function (tag) {
var span = document.createElementNS("http://www.w3.org/1999/xhtml","span");
var spanContent = tag.value.length > 22 ? tag.value.substr(0,18) + "\u2026" : tag.value;
span.setAttribute("disabled",tag.disabled ? "true" : "false");
span.setAttribute("tooltiptext",tag.value);
span.appendChild(document.createTextNode(spanContent));
frag.appendChild(span);
frag.appendChild(document.createTextNode(", "));
tag.element = span;
}
);
while (tagsCloud.firstChild) tagsCloud.removeChild(tagsCloud.firstChild);
if (frag.lastChild)
{
frag.removeChild(frag.lastChild);
tagsCloud.appendChild(frag);
style.display = "block";
let bo = this.boxObject;
style.left = bo.x + 5 + "px";
style.width = Math.max(0,bo.width - 10) + "px";
}
else
{
style.display = "none";
}
]]></body>
            </method>

            <method name="trySetNewValue">
                <parameter name="strTags"/>
                <parameter name="bSetAnyway"/>
                <body><![CDATA[if (this.maxLength && this.maxLength < strTags.length)
{
if (! bSetAnyway)
{
return false;
}

this.removeAttribute("maxlength");
}

this._mTextbox.value = strTags;
return true;]]></body>
            </method>

            <method name="_processTags">
                <parameter name="arrBookmarkTags"/>
                <parameter name="arrAllTags"/>
                <parameter name="maxNumber"/>
                <body><![CDATA[var arrTags = [];
Array.forEach(arrAllTags,function (strTag1) {
var tag = {
value: strTag1};
arrTags.push(tag);
if (arrBookmarkTags.indexOf(strTag1) > - 1)
{
tag.disabled = true;
}

}
);
if (maxNumber)
{
let arrSortedTags = arrTags.slice(0,maxNumber);
arrSortedTags.sort(function (a, b) {
return a.value < b.value ? - 1 : a.value > b.value ? 1 : a < b ? - 1 : a > b ? 1 : 0;
}
);
return arrSortedTags;
}

return arrTags;]]></body>
            </method>

            <method name="_showMaxLengthTooltip">
                <body><![CDATA[this._clearMaxLengthTooltipTimeout();
var tooltipText = document.documentElement.getFormattedString("MaxLengthTooltipText",[this._tagMaxLength]);
this._mMaxLengthTooltip.firstChild.setAttribute("value",tooltipText);
this._mMaxLengthTooltip.showPopup(this._mTextbox,this.boxObject.screenX + 4,this.boxObject.screenY,"tooltip",null,null);
this._maxLengthTooltipTimeout = window.setTimeout(function (tooltip) {
tooltip.hidePopup();
}
,2000,this._mMaxLengthTooltip);]]></body>
            </method>

            <method name="_clearMaxLengthTooltipTimeout">
                <body><![CDATA[if (this._maxLengthTooltipTimeout)
{
window.clearTimeout(this._maxLengthTooltipTimeout);
}

this._maxLengthTooltipTimeout = null;]]></body>
            </method>

            <method name="_clearTextInputTimeout">
                <body><![CDATA[if (this._handleTextInputTimeout)
{
window.clearTimeout(this._handleTextInputTimeout);
}

this._handleTextInputTimeout = null;]]></body>
            </method>

             <method name="_handleTextInput">
                <body><![CDATA[this._clearTextInputTimeout();
this._handleTextInputTimeout = window.setTimeout((function () {
var txtValue = this._mTextbox.value;
var selStart = this._selectionStart, selEnd = this._selectionEnd;
if (selEnd !== txtValue.length)
return;
var textBefore = txtValue.substr(0,selStart);
textBefore = textBefore.substr(textBefore.lastIndexOf(",") + 1).replace(/^( *)/,"");
var preparedValue = "," + txtValue.replace(/\s+/g,"") + ",";
if (! textBefore)
return;
var re = new RegExp("^" + textBefore);
this._arrAllTags.some(function (tagValue) {
if (re.test(tagValue) && preparedValue.indexOf("," + tagValue + ",") == - 1)
{
let postfix = tagValue.substr(textBefore.length);
let resultValue = txtValue.substr(0,selEnd) + postfix;
if (this.trySetNewValue(resultValue))
{
this._selectTextRange(selStart,resultValue.length);
this._lastTextComplete = postfix;
return true;
}

}

return false;
}
,this);
}
).bind(this),200);]]></body>
            </method>

            <method name="_handleTextChange">
                <body><![CDATA[var txtValue = this._mTextbox.value;
if (txtValue === this._lastTextValue)
return;
var arrTags = this._getTagsArray(txtValue);
if (this._tagMaxLength)
{
let violentTags = arrTags.filter(function (tag) {
return tag.length > this._tagMaxLength;
}
,this);
if (violentTags.length)
{
this._mTextbox.value = this._lastTextValue;
this._selectTextRange(this._lastCursorPosition,this._lastCursorPosition);
this._showMaxLengthTooltip();
return;
}

}

this._arrTags.forEach(function (tag) {
tag.element.setAttribute("disabled","false");
if (arrTags.indexOf(tag.value) != - 1)
{
tag.element.setAttribute("disabled","true");
}

}
);
this._lastTextValue = txtValue;
this._lastCursorPosition = this._selectionStart;]]></body>
            </method>

            <method name="_getTagsArray">
                <parameter name="strTags"/>
                <body><![CDATA[var arrTags = [];
Array.forEach(strTags.toString().split(","),function (strTag) {
var strTag = strTag.replace(/[^\x20-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]/g,"").trim().replace(/\s+/g," ");
if (strTag && arrTags.indexOf(strTag) == - 1)
{
arrTags.push(strTag);
}

}
);
return arrTags;]]></body>
            </method>

        </implementation>

        <handlers>
            <handler event="focus" phase="capturing"><![CDATA[this._lastTextComplete = null;]]></handler>

            <handler event="blur" phase="capturing"><![CDATA[this._handleTextChange();]]></handler>

            <handler event="input"><![CDATA[this._handleTextChange();]]></handler>

            <handler event="keyup" phase="capturing"><![CDATA[if ((event.keyCode == 0 || event.keyCode > 46) && ! event.ctrlKey && ! event.altKey)
this._handleTextInput();
return true;]]></handler>

            <handler event="keydown" phase="capturing"><![CDATA[this._clearTextInputTimeout();
var keyCode = event.keyCode;
var txtValue = this._mTextbox.value;
if (this._lastTextComplete === txtValue.substr(this._selectionStart,this._selectionEnd))
{
if (event.DOM_VK_RETURN == keyCode)
{
this.trySetNewValue(txtValue + ", ");
let len = txtValue.length;
this._selectTextRange(len + 2,len + 2);
this._handleTextChange();
return false;
}

}

return true;]]></handler>

            <handler button="0" event="click"><![CDATA[var target = event.originalTarget;
switch (target.localName) {
case "span":
if (target.parentNode.localName === "div")
{
this.addTag(target);
}

break;
}
]]></handler>
        </handlers>
    </binding>

    <binding id="yaru-container">
         <resources>
            <stylesheet src="yaru.css"/>
        </resources>

        <content>
            <grid flex="1" height="100%" id="settings-grid" status="nodata" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
                <columns>
                    <column/>
                    <column flex="1"/>
                </columns>
                <rows>
                    <row hidden="false" id="settings-container-1" yaCollapsed="true">
                        <vbox/>
                        <vbox>
                            <html:div>
                                <hbox align="center">
                                    <checkbox id="settings-checkbox" label="&yaru.checkbox.label;" oncommand="getBindingParent(this)._onCommand('checkbox');"/>
                                    <image/>
                                </hbox>
                                <html:div>
                                    <hbox id="settings-refresh-link">
                                        <label class="action-link small-text" value="&yaru.request.link.label;"/>
                                        <label class="action-link small-text" onclick="getBindingParent(this)._loadYaRuCommunities()" value="&yaru.reload.link.label;"/>
                                    </hbox>
                                    <hbox class="bg-arrow-dn" id="settings-collapse-link" onclick="getBindingParent(this)._expandSettings(true)" yaShowOnCollapsed="true">
                                        <label class="action-link small-text" value="&yaru.expand.link.label;"/>
                                    </hbox>
                                </html:div>
                            </html:div>

                            <deck class="small-text info-text" id="settings-informer-deck" selectedIndex="0">
                                <html:div yaDeckIndex="0">&#160;</html:div>
                                <html:div yaDeckIndex="1">&yaru.info.requestdata.label;.</html:div>
                                <html:div yaDeckIndex="2">&yaru.info.notfound.label;.</html:div>
                                <html:div yaDeckIndex="3">
                                    &yaru.info.deletedjournal.label;
                                    <label id="settings-informer-ressurect-link" yaLinkAction="1960" yaLinkTarget="new tab" yahref="http://wow.ya.ru/options_others_ressurect.xml">
                                    &yaru.info.deletedjournal.link.label;</label>.
                                </html:div>
                                <html:div yaDeckIndex="4">&yaru.info.hasnojournal.label;</html:div>
                                <html:div yaDeckIndex="5">&yaru.info.hasjournal.label;</html:div>
                            </deck>
                        </vbox>
                    </row>

                    <row id="settings-container-2" yaCollapsed="true">
                        <label value="&yaru.note.label;"/>
                        <radiogroup id="settings-communities-group" oncommand="getBindingParent(this)._onCommand('communities-radio')" yaHasClubs="false">
                            <radio label="&yaru.note.where.journal.label;" selected="true"/>
                            <hbox align="center">
                                <radio label="&yaru.note.where.community.label;"/>
                                <menulist id="settings-communities-menulist" oncommand="getBindingParent(this)._onCommand('communities-menulist')">
                                    <menupopup flex="0" id="settings-communities-menupopup">
                                        <menuitem hidden="true" label=" "/>
                                    </menupopup>
                                </menulist>
                            </hbox>
                            <html:div class="small-text">(&yaru.info.hasnocommunities.1.label; <label yaLinkAction="1920" yahref="http://wow.ya.ru/clubs.xml">&yaru.info.hasnocommunities.2.label;</label><html:br/>&yaru.info.hasnocommunities.3.label;)</html:div>
                        </radiogroup>
                    </row>

                    <row id="settings-container-3" yaCollapsed="true">
                        <label value="&yaru.public.label;"/>
                        <hbox>
                            <radiogroup flex="1" id="settings-public-group">
                                <radio label="&yaru.public.all.label;" value="10"/>
                                <radio label="&yaru.public.friends.label;" selected="true" value="5"/>
                                <radio label="&yaru.public.me.label;" value="0"/>
                            </radiogroup>
                            <hbox align="end" pack="end">
                                <hbox class="bg-arrow-up" onclick="getBindingParent(this)._expandSettings(false)">
                                    <label class="action-link small-text" value="&yaru.collapse.link.label;"/>
                                </hbox>
                            </hbox>
                        </hbox>
                    </row>
                </rows>
            </grid>
        </content>

        <implementation>
            <field name="params">window.yaWinArguments</field>
            <field name="username">this.params.username</field>
            <field name="api">this.params.api</field>
            <field name="services">this.params.services</field>

            <constructor><![CDATA[this.visible = false;]]></constructor>

            <property name="enabled">
                <setter><![CDATA[this._enabled = val;
document.getElementById("settings-checkbox").disabled = ! val;]]></setter>
                <getter><![CDATA[return this._enabled;]]></getter>
            </property>

            <property name="visible">
                <setter><![CDATA[this.hidden = ! val;
if (val)
{
this.enabled = false;
this._buildYaRu();
}
]]></setter>
                <getter><![CDATA[return ! ! this.hidden;]]></getter>
            </property>

            <property name="hasData">
                <getter><![CDATA[return this._status == "ok";]]></getter>
            </property>

            <method name="save">
                <body><![CDATA[this._saveSettings();]]></body>
            </method>

            <method name="getPostData">
                <body><![CDATA[var data = null;
if (this.exportChecked)
{
let postInCommunities = document.getElementById("settings-communities-group").selectedIndex == 1;
let uidItem = postInCommunities ? document.getElementById("settings-communities-menulist") : document.getElementById("settings-communities-group").selectedItem;
data = {
feed_id: uidItem.getAttribute("value")};
if (postInCommunities)
{
data.status = 10;
}
else
{
let publicItem = document.getElementById("settings-public-group").selectedItem;
data.status = publicItem.getAttribute("value");
}

}

return data;]]></body>
            </method>

            <method name="_buildYaRu">
                <body><![CDATA[var yaLink = document.getElementById("settings-informer-ressurect-link");
yaLink.setAttribute("yahref",yaLink.getAttribute("yahref").replace(/wow\.ya\.ru\//,this.username + ".ya.ru/"));
this._loadYaRuCommunities();
this._informerLabelsHack();]]></body>
            </method>

            <property name="exportChecked">
                <getter><![CDATA[return document.getElementById("settings-checkbox").checked;]]></getter>
                <setter><![CDATA[var rdGrp = document.getElementById("settings-grid").getElementsByTagName("radiogroup");
for (let i = 0, item;i < rdGrp.length;i++) {
item = rdGrp.item(i);
item.disabled = ! val;
}

document.getElementById("settings-communities-menulist").disabled = ! val;
var cumRgrp = document.getElementById("settings-communities-group");
var clubsRadio = cumRgrp.getItemAtIndex(1);
clubsRadio.setAttribute("disabled",! val || cumRgrp.getAttribute("yaHasClubs") == "false");
if (val)
{
let cumRgrp = document.getElementById("settings-communities-group");
this._visEnabled = cumRgrp.selectedIndex == 0;
}
]]></setter>
            </property>

            <property name="_status">
                <setter><![CDATA[document.getElementById("settings-grid").setAttribute("status",val);
this.enabled = val == "ok" || val == "ok-empty";
var statuses = ["nodata", "loading", "error", "deleted", "ok-empty", "ok"];
var index = statuses.indexOf(val);
document.getElementById("settings-informer-deck").selectedIndex = index;
if (val == "ok" || val == "ok-empty")
{
this._restoreSettings();
}
]]></setter>
                <getter><![CDATA[return document.getElementById("settings-grid").getAttribute("status");]]></getter>
            </property>

            <method name="setPref">
                <parameter name="strPrefName"/>
                <parameter name="strPrefValue"/>
                <body><![CDATA[var prefFullName = this.api.Settings.getPackageBranchPath() + strPrefName;
var prefsModule = this.api.Settings.PrefsModule;
return prefsModule.set(prefFullName,strPrefValue);]]></body>
            </method>

            <method name="getPref">
                <parameter name="strPrefName"/>
                <parameter name="defaultValue"/>
                <body><![CDATA[var prefFullName = this.api.Settings.getPackageBranchPath() + strPrefName;
var prefsModule = this.api.Settings.PrefsModule;
return prefsModule.get(prefFullName,defaultValue);]]></body>
            </method>

            <method name="_restoreSettings">
                <body><![CDATA[if (parseInt(this.getPref("yaruBookmarksSaved",0),10) > 10 || parseInt(this.getPref("yaruPublicBookmarksSaved",0),10))
{
document.getElementById("settings-informer-deck").setAttribute("yaHiddenIndex","5");
}

var pubPref = this.getPref("yaruPublicVal",5);
var pubRgrp = document.getElementById("settings-public-group");
var radio, i = 0;
while (radio = pubRgrp.getItemAtIndex(i++)) {
if (radio.getAttribute("value") == pubPref)
{
pubRgrp.selectedItem = radio;
break;
}

}

document.getElementById("settings-checkbox").checked = this.getPref("yaruExportChecked",false);
this._onCommand("checkbox");
var state = this.getPref("yaruBlockExpanded",false);
this._expandSettings(state);]]></body>
            </method>

            <method name="_saveSettings">
                <body><![CDATA[if (this.hasData)
{
let publicItem = document.getElementById("settings-public-group").selectedItem;
this.setPref("yaruPublicVal",publicItem.getAttribute("value"));
this.setPref("yaruExportChecked",this.exportChecked);
let nPublicSaved = this.getPref("yaruPublicBookmarksSaved",0);
this.setPref("yaruPublicBookmarksSaved",++nPublicSaved);
}
]]></body>
            </method>

            <method name="_loadYaRuCommunities">
                <body><![CDATA[this._status = "loading";
this.services.getYaRuCommunities((function (domXMLResponse) {
if (domXMLResponse.querySelector("has_not_journal"))
{
document.getElementById("settings-communities-group").getItemAtIndex(0).setAttribute("value","create");
this._status = "ok-empty";
}
else
{
let strStatus = domXMLResponse.querySelector("has_journal").getAttribute("status");
if (strStatus == "deleted")
{
this._status = "deleted";
}
else
{
if (strStatus == "normal")
{
this._buildCommunitiesList(domXMLResponse);
this._status = "ok";
}
else
{
this._status = "error";
}

}

}

}
).bind(this),(function () {
this._status = "error";
}
).bind(this));]]></body>
            </method>

            <method name="_buildCommunitiesList">
                <parameter name="domXMLCommunities"/>
                <body><![CDATA[var uidValue = domXMLCommunities.querySelector("has_journal").firstChild.nodeValue;
document.getElementById("settings-communities-group").getItemAtIndex(0).setAttribute("value",uidValue);
var menu = document.getElementById("settings-communities-menulist");
var menuItemCount = menu.menupopup.childNodes.length;
while (menuItemCount-- > 1) menu.removeItemAt(menuItemCount);
var arrCommunities = [];
var communities = domXMLCommunities.querySelectorAll("communities community");
for (let i = 0, length = communities.length;i < length;i++) {
let titleNode = communities[i].querySelector("title");
let feedIdNode = communities[i].querySelector("feed_id");
let label = titleNode.firstChild && titleNode.firstChild.nodeValue;
let value = feedIdNode.firstChild && feedIdNode.firstChild.nodeValue;
if (label && value)
{
arrCommunities.push(communities[i]);
}

}

arrCommunities.sort(function (a, b) {
var titleA = a.querySelector("title"), titleB = b.querySelector("title");
var labelA = titleA.firstChild && titleA.firstChild.nodeValue, labelB = titleB.firstChild && titleB.firstChild.nodeValue;
var labelALower = labelA && labelA.toLowerCase() || "", labelBLower = labelB && labelB.toLowerCase() || "";
return labelALower < labelBLower ? - 1 : labelALower > labelBLower ? 1 : labelA < labelB ? - 1 : labelA > labelB ? 1 : 0;
}
);
arrCommunities.forEach(function (community) {
var titleNode = community.querySelector("title");
var feedIdNode = community.querySelector("feed_id");
var label = titleNode.firstChild && titleNode.firstChild.nodeValue || "";
var value = feedIdNode.firstChild && feedIdNode.firstChild.nodeValue || "";
menu.appendItem(label,value);
}
);
menuItemCount = menu.menupopup.childNodes.length;
document.getElementById("settings-communities-group").setAttribute("yaHasClubs",menuItemCount > 1);
if (menuItemCount > 1)
menu.selectedIndex = 1;]]></body>
            </method>

            <method name="_onCommand">
                <parameter name="strCommand"/>
                <body><![CDATA[switch (strCommand) {
case "checkbox":
let exportCheckbox = document.getElementById("settings-checkbox");
this.exportChecked = exportCheckbox.checked;
break;
case "communities-radio":
let cumRgrp = document.getElementById("settings-communities-group");
this._visEnabled = cumRgrp.selectedIndex == 0;
break;
case "communities-menulist":
document.getElementById("settings-communities-group").selectedIndex = 1;
break;
}
]]></body>
            </method>

            <property name="_visEnabled">
                <setter><![CDATA[document.getElementById("settings-public-group").disabled = ! val;]]></setter>
                <getter><![CDATA[return document.getElementById("settings-public-group").disabled;]]></getter>
            </property>

            <method name="_expandSettings">
                <parameter name="state"/>
                <body><![CDATA[this.setPref("yaruBlockExpanded",state);
for (let i = 1;i <= 3;i++) {
document.getAnonymousElementByAttribute(this,"id","settings-container-" + i).setAttribute("yaCollapsed",! state);
}

var newEvent = document.createEvent("Events");
newEvent.initEvent("more",true,true);
this.dispatchEvent(newEvent);]]></body>
            </method>

            <method name="_informerLabelsHack">
                <body><![CDATA[var informerDeck = document.getElementById("settings-informer-deck");
var settingsCheckbox = document.getElementById("settings-checkbox");
var labelElement = settingsCheckbox.labelElement || settingsCheckbox.boxObject.lastChild;
var diff = parseInt(labelElement.boxObject.x - informerDeck.boxObject.x + 1,10);
if (diff > 0 && diff < 100)
{
informerDeck.style.marginLeft = diff + "px";
document.getElementById("settings-communities-group").lastChild.style.marginLeft = diff + "px";
}
]]></body>
            </method>
        </implementation>
    </binding>

    <binding extends="chrome://global/content/bindings/dialog.xml#dialog" id="dialog">
        <implementation implements="nsIObserver">
            <constructor><![CDATA[var relBundleSrc = document.getElementById("string-bundle-bookmarks").src;
document.getElementById("string-bundle-bookmarks").src = window.yaWinArguments.api.Package.resolvePath(relBundleSrc);]]></constructor>

            <method name="changeMode">
                <parameter name="data"/>
                <parameter name="domXMLResponse"/>
                <body><![CDATA[var yaRu = document.getElementById("yaru-settings");
window.yaWinArguments.data = data;
window.yaWinArguments.hasData = yaRu.hasData;
window.yaWinArguments.domXMLResponse = domXMLResponse;
Dlg.onDialogUnload();
document.getElementById("content").removeChild(document.getElementById("content").firstChild);
document.loadOverlay(window.yaWinArguments.api.Package.resolvePath("/native/fx/dialogs/bookmarks/livewindow.xul"),this);]]></body>
            </method>

            <method name="openURL">
                <parameter name="strURL"/>
                <parameter name="nAction"/>
                <parameter name="strTarget"/>
                <body><![CDATA[if (nAction)
{
window.yaWinArguments.api.Statistics.logShortAction(nAction);
}

window.yaWinArguments.api.Controls.navigateBrowser({
url: strURL,
target: strTarget});]]></body>
            </method>

            <method name="getLocalizedString">
                <parameter name="strName"/>
                <body><![CDATA[var bundle = document.getElementById("string-bundle-bookmarks");
return bundle.getString(strName);]]></body>
            </method>

             <method name="getFormattedString">
                <parameter name="strName"/>
                <parameter name="aStrArray"/>
                <body><![CDATA[var bundle = document.getElementById("string-bundle-bookmarks");
return bundle.getFormattedString(strName,aStrArray,aStrArray.length);]]></body>
            </method>

            <method name="observe">
                <parameter name="subj"/>
                <parameter name="topic"/>
                <parameter name="data"/>
                <body><![CDATA[switch (topic) {
case "xul-overlay-merged":
window.setTimeout(function (me) {
if (me && "load" in me)
me.load();
}
,100,this);
break;
}
]]></body>
            </method>

            <method name="load">
                <parameter name="event"/>
                <body><![CDATA[Dlg.onDialogLoad();
window.sizeToContent();]]></body>
            </method>
        </implementation>

        <handlers>
            <handler event="more"><![CDATA[window.sizeToContent();]]></handler>

            <handler event="link"><![CDATA[var strURL = event.originalTarget.getAttribute("yahref");
var nAction = event.originalTarget.getAttribute("yaLinkAction");
var strTarget = event.originalTarget.getAttribute("yaLinkTarget");
window.minimize();
if (strURL)
{
this.openURL(strURL,nAction,strTarget || "tab");
}
]]></handler>
        </handlers>
    </binding>

    <binding id="extra-dialog-button-box">
        <content>
            <xul:checkbox id="dont-show-again" label="&yaru.dontshowlivewindow.checkbox.label;"/>
            <xul:spacer flex="1"/>
            <children/>
        </content>
    </binding>

    <binding id="extra-dialog-button-box1">
        <content>
            <xul:hbox class="throbber"/>
            <children/>
        </content>
    </binding>
</bindings>
