File: /var/www/sites/1250.info/wp-content/themes/savoy/assets/js/nm-shop-search.min.js
/* NM: Shop search script */
(function(c){c.extend(c.nmTheme,{search_init:function(){this.headerSearch="0"!==nm_wp_vars.shopSearchHeader?!0:!1;this.searchCurrentQuery="";this.headerSearch?("0"!==nm_wp_vars.searchSuggestions?((this.instantSuggestions="0"!==nm_wp_vars.searchSuggestionsInstant?!0:!1)&&this.instantSuggestionsLoad(),this.suggestions=!0,this.suggestionsAjax=null,this.suggestionsCacheEnabled=!0,this.suggestionsCache={},this.suggestionsMaxResults=nm_wp_vars.searchSuggestionsMax):this.suggestions=!1,this.$searchPanel=
c("#nm-header-search"),this.$searchPanel.css("margin-right","-"+this.scrollbarWidth+"px"),this.$searchBtn=c("#nm-menu-search-btn"),this.$searchInput=c("#nm-header-search-input"),this.$searchNotice=c("#nm-header-search-notice"),this.headerSearchBind()):this.isShop&&(this.$searchBtn=c("#nm-shop-search-btn"),this.$searchPanel=c("#nm-shop-search"),this.$searchInput=c("#nm-shop-search-input"),this.$searchNotice=c("#nm-shop-search-notice"),this.searchAjax=null,this.currentSearch="",this.shopSearchBind())},
searchValidateInput:function(a,b){var d=a.replace(/ /g,"");return b||this.searchCurrentQuery!=d?0<d.length&&a.length>nm_wp_vars.shopSearchMinChar-1?(this.searchCurrentQuery=d,"valid"):"invalid":"unchanged"},searchShowNotice:function(){this.$searchNotice.addClass("show")},searchHideNotice:function(){this.$searchNotice.removeClass("show")},headerSearchBind:function(){var a=this;a.$searchBtn.on("click",function(b){b.preventDefault();a.headerSearchTogglePanel()});c("#nm-header-search-close").on("click",
function(b){b.preventDefault();a.headerSearchTogglePanel()});a.$searchInput.on("input",function(){var b=c(this).val(),d=a.searchValidateInput(b);"valid"===d?a.suggestions?a.suggestionsGet(b):a.searchShowNotice():"invalid"===d&&(a.suggestions?a.suggestionsHide():a.searchHideNotice())}).trigger("input");a.$searchInput.on("keypress",function(b){var d=c(this);"13"==(b.keyCode?b.keyCode:b.which)&&(b.preventDefault(),a.suggestionsAjax&&a.suggestionsAjax.abort(),a.headerSearchStaticSearch(d))});a.$document.on("keydown",
function(b){"27"==(b.keyCode?b.keyCode:b.which)&&a.$body.hasClass(a.classSearchOpen)&&a.headerSearchTogglePanel()})},headerSearchTogglePanel:function(){var a=this;a.$body.toggleClass(a.classSearchOpen);a.$body.hasClass(a.classSearchOpen)?(a.pageOverlayShow(),c("#nm-header-search-input").trigger("focus")):(a.pageOverlayHide(),setTimeout(function(){c("#nm-header-search-input").val("");a.suggestions&&a.suggestionsHide()},a.panelsAnimSpeed+150));a.searchHideNotice()},headerSearchStaticSearch:function(a){a=
a.val();"valid"===this.searchValidateInput(a,!0)&&(this.searchHideNotice(),this.suggestions&&(c("#nm-header-search-form").addClass("nm-loader"),c(".nm-header-search-wrap").addClass("redirecting")),a=nm_wp_vars.shopSearchUrl.toString().replace("%%nmsearchkey%%",encodeURIComponent(a)),window.location.href=a)},shopSearchBind:function(){var a=this;c("#nm-shop-search-close").on("click",function(b){b.preventDefault();a.$searchBtn.trigger("click")});c("#nm-shop-search-input").on("input",function(){var b=
a.searchValidateInput(c(this).val());"valid"===b?a.searchShowNotice():"invalid"===b&&a.searchHideNotice()}).trigger("input");if(a.filtersEnableAjax)a.$searchInput.on("keypress",function(b){var d=c(this),e=d.val();"13"==(b.keyCode?b.keyCode:b.which)&&(b.preventDefault(),"valid"===a.searchValidateInput(e,!0)&&a.currentSearch!==e?d.hasClass("nm-mobile-menu-search")?(a.pageOverlayHide(),setTimeout(function(){c("#nm-mobile-menu-shop-search-input").val("");a.shopSearchAjaxSearch(e)},a.panelsAnimSpeed)):
("0"!=nm_wp_vars.shopSearchAutoClose?a.$searchBtn.trigger("click"):a.searchHideNotice(),setTimeout(function(){a.shopSearchAjaxSearch(e)},a.filterPanelSlideSpeed)):a.currentSearch=e)})},shopSearchTogglePanel:function(){var a=this,b=c("#nm-shop-search-input");a.$searchPanel.slideToggle(200,function(){a.$searchPanel.toggleClass("fade-in");a.$searchPanel.hasClass("fade-in")?b.trigger("focus"):b.val("");a.filterPanelSliding=!1});a.searchHideNotice()},shopSearchAjaxSearch:function(a){var b=this;b.$searchInput.blur();
"popup"==b.shopSidebarLayout&&"0"!==nm_wp_vars.shopFiltersPopupAutoClose&&b.shopFiltersPopupHide();b.shopShowLoader();b.currentSearch=a;a=nm_wp_vars.searchUrl.toString().replace("%%nmsearchkey%%",encodeURIComponent(a));b.searchAjax=c.ajax({url:a,data:{shop_load:"search",post_type:"product",shop_filters_layout:b.shopSidebarLayout},dataType:"html",method:"GET",error:function(d,e,f){console.log("NM: AJAX error - shopSearchAjaxSearch() - "+f);b.shopHideLoader();b.searchAjax=null},success:function(d){b.shopUpdateContent(d);
b.searchAjax=null}})},suggestionsGet:function(a){var b=this;if(b.instantSuggestions)b.instantSuggestionsGet(a);else{b.suggestionsAjax&&b.suggestionsAjax.abort();var d=c("#nm-header-search-form"),e=c("#nm-search-suggestions"),f=b.suggestionsEscapeQuery(a);b.suggestionsCacheEnabled&&b.suggestionsCache[f]?b.suggestionsShow(b.suggestionsCache[f],null,e):(d.addClass("nm-loader"),e.children(".nm-search-suggestions-inner").children().length&&e.addClass("doing-search"),f="undefined"!==typeof wc_add_to_cart_params?
wc_add_to_cart_params.wc_ajax_url:nm_wp_vars.woocommerceAjaxUrl,f=f.toString().replace("%%endpoint%%","nm_shop_search"),b.suggestionsAjax=c.ajax({type:"POST",url:f,data:{s:a},dataType:"html",success:function(g){b.suggestionsCacheEnabled&&b.suggestionsCacheResults(a,g);b.suggestionsShow(g,null,e)},complete:function(){d.removeClass("nm-loader");b.suggestionsAjax=null}}))}},suggestionsEscapeQuery:function(a){return encodeURIComponent(a)},suggestionsCacheResults:function(a,b){var d=this.suggestionsEscapeQuery(a);
this.suggestionsCache[d]=b},suggestionsShow:function(a,b,d){var e=c("#nm-search-suggestions-product-list");e.html(a);d.removeClass("doing-search");d.addClass("show");b=b?b:e.children().length;a=0==b?"no-results":b==this.suggestionsMaxResults?"press-enter":"has-results";c("#nm-search-suggestions-notice").removeClass().addClass("show "+a)},suggestionsHide:function(){this.suggestionsAjax&&this.suggestionsAjax.abort();c("#nm-search-suggestions-product-list").html("");c("#nm-search-suggestions").removeClass();
c("#nm-search-suggestions-notice").removeClass();this.searchCurrentQuery=""},instantSuggestionsLoad:function(){var a=this;a.productDataJSON=null;var b="undefined"!==typeof wc_add_to_cart_params?wc_add_to_cart_params.wc_ajax_url:nm_wp_vars.woocommerceAjaxUrl;b=b.toString().replace("%%endpoint%%","nm_suggestions_product_data");c.ajax({type:"post",url:b,dataType:"json",error:function(d,e,f){console.log("NM: AJAX error - instantSuggestionsLoad() - "+f)},success:function(d){a.productDataJSON=d}})},instantSuggestionsSearchData:function(a){a.normalize&&
(a=a.normalize("NFD").replace(/[\u0300-\u036f]/g,""));var b=new RegExp(a,"i"),d=new RegExp("^"+a+"$"),e=0,f=[],g;for(g in this.productDataJSON)if(this.productDataJSON.hasOwnProperty(g)&&(a=this.productDataJSON[g],-1!=a.title.search(new RegExp(b))?(e++,f.push(a)):a.categories&&-1!=a.categories.search(new RegExp(b))?(e++,f.push(a)):a.tags&&-1!=a.tags.search(new RegExp(b))?(e++,f.push(a)):a.sku&&d.test(a.sku)&&(e++,f.push(a)),e==this.suggestionsMaxResults))break;return f},instantSuggestionsGet:function(a){a=
this.instantSuggestionsSearchData(a);var b="";if(0<a.length){for(var d=0;d<a.length;d++)b+=a[d].product_html;this.suggestionsShow(b,a.length,c("#nm-search-suggestions"))}else this.suggestionsShow("",0,c("#nm-search-suggestions"))}});c.nmThemeExtensions.search=c.nmTheme.search_init})(jQuery);