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