$1");},滚动:true,滚动高度:300};$.自动完成器。Cache=函数(选项){var数据={};var长度=0;函数matchSubset(s,sub){if(!options.matchCase)s=s.到LowerCase();var i=s.indexOf(子);如果(i==-1)返回false;return i==0||options.matchContains;};函数加法(q,value){if(长度>options.cacheLength){flush();}if(!数据[q]){长度++;}数据[q]=值;}函数populate(){如果(!options.data)返回false;//追踪比赛var stMatchSets={},nullData=0;//没有指定url,我们需要调整缓存长度以确保它适合本地数据存储如果(!options.url)options.cacheLength=1;//跟踪minChars=0的所有选项stMatchSets[“”]=[];//循环遍历数组并创建查找结构for(var i=0,ol=options.data.length;i<ol;i++){var rawValue=选项.data[i];//如果rawValue是字符串,则创建数组,否则只引用数组rawValue=(类型rawValue==“字符串”)?[rawValue]:rawValue;var值=options.formatMatch(rawValue,i+1,options.data.length);if(值===假)继续;var firstChar=value.charAt(0).toLowerCase();//如果不存在此字符的查找数组,请立即查找if(!stMatchSets[firstChar])stMatchSets[firstChar]=[];//如果匹配是字符串var行={value:值,数据:rawValue,结果:options.formatResult&&options.formatResult(rawValue)||value};//将当前匹配项推入集合列表stMatchSets[firstChar].push(行);//跟踪minChars零项if(nullData++<options.max){stMatchSets[“”].push(行);}};//将数据项添加到缓存$.each(stMatchSets,函数(i,值){//增加缓存大小选项.cacheLength++;//添加到缓存添加(i,值);});}//填充任何现有数据setTimeout(填充,25);函数flush(){数据={};长度=0;}返回{冲洗:冲洗,添加:添加,populate:填充,载荷:函数(q){if(!options.cacheLength||!length)返回null;/* *如果处理w/本地数据并匹配Contains,则必须确保*在所有数据集合中循环查找匹配项*/if(!options.url&&options.matchContains){//跟踪所有匹配项var csub=[];//遍历所有数据网格以进行匹配for(数据中的var k){//不搜索stMatchSets[“”](minChars:0)缓存//这样可以防止重复如果(k.长度>0){var c=数据[k];$.each(c,函数(i,x){//如果有匹配项,请将其添加到数组中if(匹配子集(x.value,q)){csub.push(x);}});}} 返回csub;}其他//如果确实存在,请使用它if(数据[q]){返回数据[q];}其他if(options.matchSubset){for(var i=q.length-1;i>=选项.minChars;i--){var c=数据[q.subtr(0,i)];如果(c){var csub=[];$.each(c,函数(i,x){if(匹配子集(x.value,q)){csub[csub.length]=x;}});返回csub;}}}返回null;}};};$.自动完成器。Select=功能(选项、输入、选择、配置){var类别={激活:“ac_over”};var列表项,活动=-1,数据,术语=“”,needsInit=true,元素,列表;//创建结果函数init(){if(!needsUnit)回报;元素=$(“")隐藏().addClass(options.resultsClass).css(“位置”,“绝对”).appendTo(document.body);innerElement=$(“").addClass('ac_results-inner').appendTo(元素);列表=$(““).appendTo(innerElement).mouseover(函数(事件){if(target(event).nodeName&&target(event).nodeName.toUpperCase()=='LI'){active=$(“li”,list).removeClass(CLASSES.active).index(target(event));$(target(event)).addClass(CLASSES.ACTIVE);}}).click(函数(事件){$(target(event)).addClass(CLASSES.ACTIVE);选择();//TODO是否提供选项以避免在选择后再次设置焦点?用于焦点清理input.focus();返回false;}).moosedown(函数(){config.mouseDownOnSelect=true;}).mouseup(函数(){config.mouseDownOnSelect=false;});if(选项宽度>0)element.css(“width”,options.width);needsInit=false;} 功能目标(事件){var元素=事件目标;while(element&&element.tagName!=“LI”)元素=element.parentNode;//IE更有趣,有时事件目标为空,那么就忽略它if(!元素)返回[];回流元件;}函数moveSelect(步骤){listItems.slice(active,active+1).removeClass(CLASSES.active);移动位置(步进);var activeItem=listItems.sice(active,active+1).addClass(CLASSES.active);if(选项滚动){var偏移=0;listItems.slice(0,active).each(function()){offset+=this.offsetHeight;});if((offset+activeItem[0].offsetHeight-list.crollTop())>列表[0].clientHeight){list.crollTop(offset+activeItem[0].offsetHeight-list.innerHeight());}else if(偏移量<list.crollTop()){list.crollTop(偏移量);}}};函数movePosition(步进){active+=步长;if(有效<0){active=listItems.size()-1;}否则if(active>=listItems.size()){活动=0;}}函数limitNumberOfItems(可用){return options.max和options.max<可用? 选项.max:可用;}函数fillList(){list.empty();var max=limitNumberOfItems(data.length);对于(var i=0;i<最大值;i++){if(!数据[i])继续;var formatd=options.formatItem(data[i].data,i+1,max,data[i].value,term);if(格式化===false)继续;var li=$(““).html(options.highlight(formated,term)).addClass(i%2==0?”ac_even“:”ac_add“).appendTo(list)[0];$.data(li,“ac_data”,数据[i]);}listItems=list.find(“li”);if(选项.selectFirst){listItems.slice(0,1).addClass(CLASSES.ACTIVE);活动=0;}//如果可用,应用bgiframe如果($.fn.bgiframe)list.bgiframe();}返回{显示:功能(d,q){init();数据=d;项=q;fillList();},下一步:function(){移动选择(1);},上一页:function(){移动选择(-1);},pageUp:函数(){if(活动!=0&&活动-8<0){moveSelect(-active);}其他{移动选择(-8);}},pageDown:函数(){if(active!=listItems.size()-1&&active+8>listItems.si()){moveSelect(listItems.size()-1-活动);}其他{moveSelect(移动选择)(8);}},隐藏:函数(){元素&&element.hide();listItems&&listItems.removeClass(CLASSES.ACTIVE);有效=-1;},可见:函数(){返回元素&element.is(“:visible”);},当前:函数(){return this.visible()&&(listItems.filter(“.”+CLASSES.ACTIVE)[0]||options.selectFirst&listItems[0]);},显示:函数(){var偏移=$(input).offset();元素.css({width:typeofoptions.width==“string”||options.width>0?options.width:$(输入).width(),顶部:offset.top+input.offsetHeight,左:offset.left}).show();if(选项滚动){list.crollTop(0);列表.css({maxHeight:选项.scrollHeight,溢出:“自动”});if($.browser.msie&&typeof document.body.style.maxHeight===“未定义”){var listHeight=0;listItems.each(function(){listHeight+=this.offsetHeight;列表高度+=this.offsetHeight;});var scrollbarsVisible=listHeight>options.scrollHeight;list.css('height',滚动条Visible?options.scrollHeight:listHeight);if(!滚动条可见){//滚动条消失时IE不会重新计算宽度listItems.width(list.width)-parseInt(listItems.css(“padding-left”))-parse Int(列表项.css(“pading-right”));}}}},选定:函数(){var selected=listItems&&listItems.filter(“.”+CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE);return selected&selected.length&$.data(selected[0],“ac_data”);},emptyList:函数(){list&&list.empty();},unbind:function(){元素&&element.remove();}};};$.自动完成器。选择=功能(字段、开始、结束){if(field.createTextRange){var selRange=字段.createTextRange();selRange.collapse(true);selRange.moveStart(“字符”,开始);selRange.moveEnd(“字符”,结束);selRange.select();}else if(field.setSelectionRange){field.setSelectionRange(开始,结束);}其他{if(field.selectionStart){field.selectionStart=开始;field.selectionEnd=结束;}}field.focus();};})(jQuery);