woocommerce/assets/js/ajax-chosen.jquery.min.js

1 line
1.3 KiB
JavaScript

(function(a){a==null&&(a=jQuery);return a.fn.ajaxChosen=function(b,c){var d,e,f,g;b==null&&(b={});c==null&&(c=function(){});e={minTermLength:3,afterTypeDelay:500,jsonTermKey:"term"};g=this;d=null;f=a.extend({},e,b);this.chosen();return this.next(".chzn-container").find(".search-field > input, .chzn-search > input").bind("keyup",function(){var b,e,h;h=a.trim(a(this).attr("value"));e=h.length<f.minTermLength?"Keep typing...":"Looking for '"+h+"'";g.next(".chzn-container").find(".no-results").text(e);if(h===a(this).data("prevVal"))return!1;a(this).data("prevVal",h);this.timer&&clearTimeout(this.timer);if(h.length<f.minTermLength)return!1;b=a(this);f.data==null&&(f.data={});f.data[f.jsonTermKey]=h;if(typeof success=="undefined"||success===null)success=f.success;f.success=function(d){var e,f;if(d==null)return;f=[];g.find("option").each(function(){return a(this).is(":selected")?f.push(a(this).val()+"-"+a(this).text()):a(this).remove()});e=c(d);a.each(e,function(b,c){if(f.indexOf(b+"-"+c)===-1)return a("<option />").attr("value",b).html(c).appendTo(g)});g.trigger("liszt:updated");typeof success!="undefined"&&success!==null&&success();b.attr("value",h);return b.css("width","auto")};return this.timer=setTimeout(function(){d&&d.abort();return d=a.ajax(f)},f.afterTypeDelay)})}})($);