/*
 * XenForo title_prefix.min.js
 * Copyright 2010-2017 XenForo Ltd.
 * Released under the XenForo License Agreement: http://xenforo.com/license-agreement
 */
(function(b,s,t){XenForo.TitlePrefix=function(d){function p(a){var q,c=d.val();d.find("option, optgroup").not("[value=0]").empty().remove();b.each(a,function(a,c){a=c.prefix_group_id;q=a!=0?b("<optgroup />").attr("label",c.title).appendTo(d):d;b.each(c.prefixes,function(c,a){c=a.prefix_id;b("<option />").attr("value",c).data("css",a.css).text(a.title).appendTo(q)})});r(i);var f=j;setTimeout(function(){var a=d.find("option[value="+f+"]");a.length<1&&(a=d.find("option[value=0]"));k(a.data("link"),!0)},
0);d.val(c).trigger("change")}function l(){if(e.length){var a=g.innerWidth()-10;e.siblings().not(e).each(function(){var d=b(this).css("position");d=="absolute"||d=="fixed"||(a-=b(this).outerWidth(!0))});a<130?(e.css("width","100%"),g.addClass("blockInput")):(e.css("width",a),g.removeClass("blockInput"))}}function k(a,b){if(e.length){var c=a.data("option"),f;a.closest("ul.PrefixMenu").find("li.PrefixOption, li.PrefixGroup").removeClass("selected");c instanceof jQuery&&(c.val()!=0&&a.closest("li.PrefixOption").addClass("selected"),
f=a.closest("li.PrefixGroup"),f.length&&f.find("li.PrefixOption").not(".selected").length==0&&f.addClass("selected"),h.data("css")&&h.removeClass(h.data("css")),h.addClass(c.data("css")).data("css",c.data("css")).find("span.prefixText").text(c.text()),j=c.val(),console.info("set prefix %s",j),d.val(j).trigger("change"));l();d.trigger({type:"XFSetPrefix",link:a});b||e.get(0).select()}}function m(a,d){var c=b(a),f=b('<a href="javascript:" />').data("option",c).text(c.text()).addClass(c.data("css")).click(function(){k(f)});
d.append(b("<li />").addClass("PrefixOption").append(f));c.data("link",f);a.selected&&setTimeout(function(){k(f,!0)},0)}function u(){if(e.length)return i=b('<ul class="Menu PrefixMenu secondaryContent" />'),r(i),b('<div class="Popup PrefixPopup"></div>').append(h).append(i)}function r(a){e.length&&(a.empty(),d.children("optgroup").each(function(d,c){var f=b(c),e,g;e=b("<li />").addClass("PrefixGroup").appendTo(a);b("<h3 />").text(f.attr("label")).appendTo(e);g=b("<ul />").appendTo(e);f.children("option").each(function(a,
c){m(c,g)})}),d.children("option:not([value=0])").each(function(b,c){m(c,a)}),d.children("option[value=0]").each(function(b,c){m(c,a)}))}var g,v=b(d.data("container")),e=b(d.data("textbox")),h=b('<span rel="Menu"><span class="prefixText"></span></span>').addClass("prefix noPrefix").data("css","prefix noPrefix"),i=null,n=b(d.data("nodecontrol")),j=0,o={};n.length&&d.data("prefixurl")&&n.change(function(){var a=n.val(),b=d.data("prefixurl"),c=null;o[a]?p(o[a]):b&&setTimeout(function(){c&&c.abort();
c=XenForo.ajax(b,{node_id:a},function(b){c=null;if(XenForo.hasResponseError(b))return!1;if(b.prefixGroups)o[a]=b.prefixGroups,p(b.prefixGroups)})},0)});e.length&&(v.hide(),g=b("<div />").addClass("textCtrlWrap").addClass(e.attr("class")).insertBefore(e).append(e),g.prepend(u()),e.bind({focus:function(){g.addClass("Focus")},blur:function(){g.removeClass("Focus")}}),b(t).bind("XenForoActivationComplete OverlayOpened TitlePrefixRecalc",l),b(s).on("resize",l))};XenForo.register("select.TitlePrefix","XenForo.TitlePrefix")})(jQuery,
this,document);
