"use strict";function FAQ(t,e,i){if(t&&(this._data=t),e&&(this._gaUrl=e),i&&(this._kbCategory=i),this._create(),this._kbCategory){var c=document.getElementById("kb_"+this._kbCategory);c&&eventFire(c,"click")}}function eventFire(t,e){if(t.fireEvent)t.fireEvent("on"+e);else{var i=document.createEvent("Events");i.initEvent(e,!0,!1),t.dispatchEvent(i)}}$.extend(FAQ.prototype,{_create:function(){var t=this,e={},i={};this._allArticles=[],this._data.children&&this._data.children.forEach(function(c){e[c.id]=c.articles,i[c.id]=c.title,t._allArticles=t._allArticles.concat(c.articles)}),this._articles=e,this._categories=i,this._createView()},_createView:function(){if(this._data.children){this._createCategoryItemView(),$("span.search-icon").off("click").on("click",this._onSearchButtonClick.bind(this)),$("#searchvalue").off("keyup").on("keyup",this._onSearchInputKeyUp.bind(this)).focus();var t=$("
").css({position:"absolute",top:"-9999px",left:"-9999px"});$("body").append(t),this.__$helper=t}},_createCategoryItemView:function(){var t=$("ul.flex-container");this._data.children.forEach(function(e,i){var c=$("").data("id",e.id).addClass("flex-item").attr("id","kb_"+e.id),n=$("");e.icon?n.addClass("fa").addClass(e.icon):n.html(" "),c.append(n),c.append($("").text(e.title)),t.append(c)}),$("li.flex-item").off("click").on("click",this._onItemSelect.bind(this))},_createAccordion:function(){var t=this._filteredArticles||[],e=$("#accordion");e.accordion("instance")&&(e.accordion("destroy"),e.empty()),t&&t.length&&(t.forEach(function(t){e.append($("").text(t.subject));var i=$("").html(t.contents);i.find("*").removeAttr("style"),e.append(i)}),$("#accordion").accordion({collapsible:!0,heightStyle:"content",active:!1}))},_applySearch:function(t){if(!t)return delete this._filteredArticles,this._createAccordion(),void this._notifyGoogleAnalytics("/search/empty","Search without value");var e=this,i=e.__$helper,c={};this._filteredArticles=[];var n,a,o=new RegExp((n=t.split(" "),a=[],n.forEach(function(t){""!==t&&a.push(t)}),a).join("|"),"i");this._allArticles.forEach(function(t){var n=t.contents,a=t.id;i.html(n),n=i.text(),o.test(t.subject)?a in c||(e._filteredArticles.unshift(t),c[a]=""):o.test(n)&&(a in c||(e._filteredArticles.push(t),c[a]=""))}),this._createAccordion(),this._showNoResultsMessage(),this._notifyGoogleAnalytics("/search/"+encodeURIComponent(t),"Search with value")},_showNoResultsMessage:function(t){void 0===t&&(t=!this._filteredArticles.length),t?($(".search-no-results > div#search-term").text($("#searchvalue").val()),$(".search-no-results").show()):$(".search-no-results").hide()},_showFormLink:function(){$("div.form-faq").show()},_setActiveState:function(t){var e=this._$activeCategory;e&&(t?e.addClass("active"):(e.removeClass("active"),delete this._$activeCategory))},_notifyGoogleAnalytics:function(t,e){if(this._gaUrl&&t){var i=this._gaUrl+t;ga("send","pageview",{page:i,title:e||"Knowledgebase"})}},_onItemSelect:function(t){var e=$(t.currentTarget),i=e.data("id");if(i){this._setActiveState(!1),this._$activeCategory=e,this._setActiveState(!0),this._filteredArticles=this._articles[i],this._createAccordion(),this._showNoResultsMessage(!1);var c=encodeURIComponent(this._categories[i]);this._notifyGoogleAnalytics("/categories/"+c,"Select category")}},_onSearchButtonClick:function(){var t=$("#searchvalue").val();t.length&&(this._setActiveState(!1),this._applySearch(t))},_onSearchInputKeyUp:function(t){13==t.keyCode&&$("span.search-icon").click()}}),Function.prototype.bind||(Function.prototype.bind=function(t){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var e=Array.prototype.slice.call(arguments,1),i=this,c=function(){},n=function(){return i.apply(this instanceof c?this:t,e.concat(Array.prototype.slice.call(arguments)))};return c.prototype=this.prototype,n.prototype=new c,n});