/* * jQuery Autocomplete plugin 1.1 * * Copyright (c) 2009 Jörn Zaefferer * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * * Revision: $Id: jquery.autocomplete.js 15 2009-08-22 10:30:27Z joern.zaefferer $ */(function(d){d.fn.extend({autocomplete:function(a,b){var u="string"==typeof a;b=d.extend({},d.Autocompleter.defaults,{url:u?a:null,data:u?null:a,delay:u?d.Autocompleter.defaults.delay:10,max:b&&!b.scroll?10:150},b);b.highlight=b.highlight||function(a){return a};b.formatMatch=b.formatMatch||b.formatItem;return this.each(function(){new d.Autocompleter(this,b)})},result:function(a){return this.bind("result",a)},search:function(a){return this.trigger("search",[a])},flushCache:function(){return this.trigger("flushCache")},setOptions:function(a){return this.trigger("setOptions",[a])},unautocomplete:function(){return this.trigger("unautocomplete")}});d.Autocompleter=function(a,b){function u(){var h=q.selected();if(!h)return!1;var c=h.result;v=c;if(b.multiple){var m=t(k.val());if(1=b.minChars?(k.addClass(b.loadingClass),b.matchCase||(h=h.toLowerCase()),f(h,e,l)):(k.removeClass(b.loadingClass),q.hide())}}function t(a){return a?b.multiple?d.map(a.split(b.multipleSeparator),function(b){return d.trim(a).length?d.trim(b):null}):[d.trim(a)]:[""]}function g(h){if(!b.multiple)return h;var c=t(h);if(1==c.length)return c[0];c=d(a).selection().start;c=c==h.length?t(h):t(h.replace(h.substring(c),""));return c[c.length-1]}function l(){q.visible();q.hide();clearTimeout(w);k.removeClass(b.loadingClass);b.mustMatch&&k.search(function(a){a||(b.multiple?(a=t(k.val()).slice(0,-1),k.val(a.join(b.multipleSeparator)+(a.length?b.multipleSeparator:""))):(k.val(""),k.trigger("result",null)))})}function e(h,f){if(f&&f.length&&n){k.removeClass(b.loadingClass);q.display(f,h);var e=f[0].value;b.autoFill&&g(k.val()).toLowerCase()==h.toLowerCase()&&m!=c.BACKSPACE&&(k.val(k.val()+e.substring(g(v).length)),d(a).selection(v.length,v.length+e.length));q.show()}else l()}function f(c,f,m){b.matchCase||(c=c.toLowerCase());var h=r.load(c);if(h&&h.length)f(c,h);else if("string"==typeof b.url&&0a.cacheLength&&t();g[b]||l++;g[b]=d}function p(){if(!a.data)return!1;var b={},f=0;a.url||(a.cacheLength=1);b[""]=[];for(var c=0,k=a.data.length;c=a.minChars;c--)if(k=g[e.substr(0,c)])return f=[],d.each(k,function(a,c){b(c.value,e)&&(f[f.length]=c)}),f;return null}}};d.Autocompleter.Select=function(a,b,u,p){function t(){v&&(r=d("\x3cdiv/\x3e").hide().addClass(a.resultsClass).css("position","absolute").appendTo(document.body),n=d("\x3cul/\x3e").appendTo(r).mouseover(function(a){g(a).nodeName&&"LI"==g(a).nodeName.toUpperCase()&&(c=d("li",n).removeClass(e.ACTIVE).index(g(a)),d(g(a)).addClass(e.ACTIVE))}).click(function(a){d(g(a)).addClass(e.ACTIVE);u();b.focus();return!1}).mousedown(function(){p.mouseDownOnSelect=!0}).mouseup(function(){p.mouseDownOnSelect=!1}),0c?c=f.size()-1:c>=f.size()&&(c=0);b=f.slice(c,c+1).addClass(e.ACTIVE);if(a.scroll){var d=0;f.slice(0,c).each(function(){d+=this.offsetHeight});d+b[0].offsetHeight-n.scrollTop()>n[0].clientHeight?n.scrollTop(d+b[0].offsetHeight-n.innerHeight()):dc-8?l(-c):l(-8)},pageDown:function(){c!=f.size()-1&&c+8>f.size()?l(f.size()-1-c):l(8)},hide:function(){r&&r.hide();f&&f.removeClass(e.ACTIVE);c=-1},visible:function(){return r&&r.is(":visible")},current:function(){return this.visible()&&(f.filter("."+e.ACTIVE)[0]||a.selectFirst&&f[0])},show:function(){var c=d(b).offset();r.css({width:"string"==typeof a.width||0a.scrollHeight;n.css("height",c?a.scrollHeight:e);c||f.width(n.width()-parseInt(f.css("padding-left"))-parseInt(f.css("padding-right")))}},selected:function(){var a=f&&f.filter("."+e.ACTIVE).removeClass(e.ACTIVE);return a&&a.length&&d.data(a[0],"ac_data")},emptyList:function(){n&&n.empty()},unbind:function(){r&&r.remove()}}};d.fn.selection=function(a,b){if(void 0!==a)return this.each(function(){if(this.createTextRange){var d=this.createTextRange();void 0===b||a==b?d.move("character",a):(d.collapse(!0),d.moveStart("character",a),d.moveEnd("character",b));d.select()}else this.setSelectionRange?this.setSelectionRange(a,b):this.selectionStart&&(this.selectionStart=a,this.selectionEnd=b)});var d=this[0];if(d.createTextRange){var p=document.selection.createRange(),t=d.value,g=p.text.length;p.text="\x3c-\x3e";p=d.value.indexOf("\x3c-\x3e");d.value=t;this.selection(p,p+g);return{start:p,end:p+g}}if(void 0!==d.selectionStart)return{start:d.selectionStart,end:d.selectionEnd}}})(jQuery);