/** * @summary Main JS of Ajax Product Search for WooCommerce * * @version 1.0.5 * @since 1.0.0 * @requires jQuery.js */ jQuery(function(e){var t={init:function(){t.activate_select2()},minimum_input_length:function(e){return"undefined"!=typeof e.attr("multiple")?0:3},closeOnSelect:function(e){return"undefined"==typeof e.attr("multiple")},activate_select2:function(){var a=e(alg_wc_aps.search_input_css_selector);a.each(function(){var a=e(this);a.select2({containerCssClass:"alg-wc-aps-select",dropdownCssClass:"alg-wc-aps-dropdown",minimumResultsForSearch:1/0,maximumInputLength:40,minimumInputLength:t.minimum_input_length(a),closeOnSelect:t.closeOnSelect(a),placeholder:a.attr("placeholder")||"",ajax:{cache:!0,url:alg_wc_aps.ajaxurl,dataType:"json",delay:250,data:function(t){var n={s:t.term,action:alg_wc_aps.ajax_actions.search_products,page:t.page||1};return a.each(function(){e.each(this.attributes,function(){this.specified&&this.name.indexOf("data-")!=-1&&(n[this.name.replace("data-","")]=this.value)})}),n},processResults:function(e,t){return t.page=t.page||1,{results:e.data.items,pagination:{more:t.page*e.data.posts_per_page'+e.text+"":e.text},escapeMarkup:function(e){return e},language:{inputTooShort:function(e){var t=e.minimum-e.input.length,a=alg_wc_aps.select2_args.inputTooShort;return a=a.replace("%d",t)},inputTooLong:function(e){var t=e.input.length-e.maximum,a=alg_wc_aps.select2_args.inputTooLong;return a=a.replace("%d",t)},errorLoading:function(){return alg_wc_aps.select2_args.errorLoading},loadingMore:function(){return alg_wc_aps.select2_args.loadingMore},searching:function(){return alg_wc_aps.select2_args.searching},noResults:function(){return alg_wc_aps.select2_args.noResults}}})}),a.on("select2:select",function(e){e.preventDefault();var t=!1;"undefined"!=typeof e.target.attributes["data-redirect"]&&(t=!0),"undefined"!=typeof e.target.attributes.multiple&&(t="undefined"!=typeof e.params.data.default&&1==e.params.data.default),t&&(window.location.href=e.params.data.permalink)}),a.on("change",function(e){a.resize()})}};t.init()});