You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
11 KiB

(function(a){a.fn.autoSuggest=function(f,c){var i={asHtmlID:false,preferredLanguage:"en-US",startText:"",emptyText:"",preFill:{},limitText:"No More Selections Are Allowed",selectedItemProp:"value",selectedValuesProp:"value",searchObjProps:"value",queryParam:"q",retrieveLimit:false,extraParams:"",matchCase:false,minChars:2,keyDelay:300,resultsHighlight:true,neverSubmit:false,selectionLimit:false,showResultList:true,host:"",width:"600",height:"400",overflow:"auto",searchWithin:false,textSelectionOnly:false,start:function(){},selectionClick:function(j){},selectionAdded:function(j){},selectionRemoved:function(j){j.remove()
},formatList:false,beforeRetrieve:function(j){return j},retrieveComplete:function(j){return j},resultClick:function(j){},resultsComplete:function(){}};var e=a.extend(i,c);var d="object";var h=0;if(typeof f=="string"){d="string";var b=f}else{var g=f;for(k in f){if(f.hasOwnProperty(k)){h++}}}if((d=="object"&&h>0)||d=="string"){return this.each(function(z){if(!e.asHtmlID){z=z+""+Math.floor(Math.random()*100);var l="as-input-"+z}else{z=e.asHtmlID;var l=z}e.start.call(this);var B=a(this);B.searchWithin=B.attr("name").indexOf("txtPartKeywordSearch")>0;
B.attr("autocomplete","off").addClass("as-input").attr("id",l);if(B.val()==""){B.val(e.startText)}var G=false;var v=a("#as-original-"+z);var o=a('<div class="as-results" id="as-results-'+z+'"></div>').hide();var p=a('<ul class="as-list"></ul>');var K=a('<input type="hidden" class="as-values" name="as_values_'+z+'" id="as-values-'+z+'" />');var u=B.val();if(typeof e.preFill=="string"){var D=e.preFill.split(",");for(var H=0;H<D.length;H++){var n={};n[e.selectedValuesProp]=D[H];if(D[H]!=""){}}u=e.preFill}else{u="";
var L=0;for(k in e.preFill){if(e.preFill.hasOwnProperty(k)){L++}}if(L>0){for(var H=0;H<L;H++){var E=e.preFill[H][e.selectedValuesProp];if(E==undefined){E=""}u=u+E+",";if(E!=""){}}}}if(u!=""){B.val("");var A=u.substring(u.length-1);if(A!=","){u=u+","}K.val(","+u);a("li.as-selection-item").addClass("blur").removeClass("selected")}B.after(K);if(!e.textSelectionOnly&&!B.searchWithin&B.parent().find("#scopeOptionDiv").length>0){B.parent().after(o)}else{B.parent().append(o)}var y=null;var F="";var q=0;var r=false;
B.click(function(x){x.stopPropagation()}).focus(function(){a(".as-results").hide();if(a(this).val()==e.startText&&K.val()==""){a(this).val("")}else{if(C(a(this).val())){a("li.as-selection-item").removeClass("blur");if(a(this).val()!=""&&p.html()!=""){o.show()}}}G=true;return true}).blur(function(){if(a(this).val()==""&&K.val()==""&&u==""){a(this).val(e.startText)}else{if(G){}}}).keydown(function(N){lastKeyPressCode=N.keyCode;first_focus=false;switch(N.keyCode){case 38:N.preventDefault();w("up");break;case 40:N.preventDefault();
w("down");break;case 8:if(B.val()==""){var x=K.val().split(",");x=x[x.length-2];if(v.prev().hasClass("selected")){K.val(K.val().replace(","+x+",",","));e.selectionRemoved.call(this,v.prev())}else{e.selectionClick.call(this,v.prev());v.prev().addClass("selected")}}if(B.val().length==1){o.hide();F=""}if(a(":visible",o).length>=0){if(y){clearTimeout(y)}y=setTimeout(function(){j()},e.keyDelay)}break;case 13:r=false;var M=a("li.active:first",o);if(M.length>0){if(M.find("a").length>0){if(M.find("a").attr("href").length>0){B.blur();
M.find("a").click();window.location=M.find("a").attr("href")}}else{if(e.textSelectionOnly){B.val(M.data("data").attributes);B.focus()}}o.hide()}if(e.neverSubmit||M.length>0){N.preventDefault()}break;default:if(e.showResultList){if(e.selectionLimit&&a("li.as-selection-item").length>=e.selectionLimit){p.html('<li class="as-message">'+e.limitText+"</li>");o.show()}else{if(y){clearTimeout(y)}y=setTimeout(function(){j()},e.keyDelay)}}break}});function j(){if(lastKeyPressCode==46||(lastKeyPressCode>8&&lastKeyPressCode<32)){return o.hide()
}var M=B.val();searchTerm=B.val();F=M;var O=true;if(B.searchWithin&&(typeof lasttemplateid==="undefined"||navids=="-2")){O=false}if(C(a.trim(M))&&O){if(B.next("i.search-spinner").length==0){if(!e.textSelectionOnly&&!B.searchWithin){B.after('<i style="z-index: 100; right: 30px; position: absolute; top: 4px;" class="fa fa-spinner fa-pulse fa-2x fa-fw hidden-for-nojs tooltip-icon search-spinner"></i>')}else{B.after('<i class="fa fa-spinner fa-pulse fa-2x fa-fw hidden-for-nojs tooltip-icon search-spinner"></i>')
}}if(d=="string"){var x="";if(e.retrieveLimit){x="&limit="+encodeURIComponent(e.retrieveLimit)}if(e.beforeRetrieve){M=e.beforeRetrieve.call(this,M)}if(xhr&&xhr.readystate!=4){xhr.abort()}var N=!B.searchWithin?(scopeCategoryId>0?scopeCategoryId:"-1"):lasttemplateid;var P=b+"?"+e.queryParam+"="+encodeURIComponent(M)+"&preferredLanguage="+e.preferredLanguage+"&templateid="+N+"&navids="+((typeof navids=="undefined"||navids==0||navids=="")?N:navids);xhr=a.getJSON(P,function(R){h=0;var Q=e.retrieveComplete.call(this,R);
for(k in Q){if(Q.hasOwnProperty(k)){h++}}s(Q,M);if(h==0||isAta){if(ataAjaxCallsCount==0){ataAjaxStartTime=new Date().getMilliseconds();nonataCharCount=M.length}ataAjaxCallsCount++}});ataSearchBoxLocation=B.searchWithin?"Bottom":"Top"}else{if(e.beforeRetrieve){M=e.beforeRetrieve.call(this,M)}s(g,M)}}else{o.hide()}}function C(M){if(e.preferredLanguage.indexOf("zh")==0||e.preferredLanguage.indexOf("ja")==0||e.preferredLanguage.indexOf("ko")==0){if(M.match(/[^\x20-\x7e]/g)){return true}var x=M.match(/[^\x20-\x7e]/g);
var N=x?x.length:0;if(N>=3){return true}}if(M.length>=e.minChars){return true}else{return false}}var t=0;function s(am,P){if(!e.matchCase){P=P.toLowerCase()}var N=0;var M=false;var O=new Array();var V=0;var Z=true;var ai=true;o.html(p.html("")).hide();for(var af=0;af<h;af++){var S=af;t++;var X=true;if(e.searchObjProps=="value"){var W=am[S].GR;var Y=am[S].GN;var T=am[S].EGN==null?am[S].GN:am[S].EGN;var ad=am[S].GT}else{var ac="";var aa=e.searchObjProps.split(",");for(var U=0;U<aa.length;U++){var an=a.trim(aa[U]);
ac=ac+am[S][an]+" "}}if(ad=="A"){isAta=true}if(X){if(W.length>0){if(Z){var ak=a("<li class=header><span class=AS_header>"+Y+(ad=="P"&&!B.searchWithin&&scopeCategoryId!=0?(" - ("+scopeTranslatedCategoryName+")"):"")+"</span></li>");p.append(ak)}var ah=ad=="P"&&W.length>30;for(var ab=0;ab<W.length;ab++){var x=a('<li class="as-result-item" type="'+ad+'" id="'+ad+"-as-result-item-"+ab+'"></li>').click(function(){var aq=a(this).data("data");var ao=aq.num;if(a("#as-selection-"+ao).length<=0&&!r){var ap=aq.attributes;
if(e.textSelectionOnly){B.val(ap)}else{B.val("").focus();F="";e.resultClick.call(this,aq)}o.hide()}r=false}).mousedown(function(){G=false}).mouseover(function(){p.find(".active").removeClass("active");a(this).addClass("active")}).data("data",{attributes:W[ab].ER,r:ab});try{if(!e.matchCase){var R=new RegExp("("+encodeURIComponent(P)+")","gi")}else{var R=new RegExp("("+encodeURIComponent(P)+")","g")}}catch(aj){var R=new RegExp("()","gi")}var Q="";if(e.textSelectionOnly){Q="<txt>"+m(a.trim(ad=="M"?W[ab].ER:W[ab].TR))+"</txt>"
}else{var al="";if(W[ab].Image!=undefined&&W[ab].Image!=""){al="height:40px; background: url(http://www.mouser.com/images/"+W[ab].Image+") no-repeat right center/40px;"}Q=a("<a class='link' style='"+al+"' index="+ab+" href="+e.host+(ad=="P"?("_/?Keyword="+encodeURIComponent(W[ab].ER)):("search/refine.aspx?N="+W[ab].IDS))+"> "+m(a.trim(ad=="M"?W[ab].ER:W[ab].TR))+" </a>").data("GAData",{entryType:encodeURIComponent(ad),entryClicked:encodeURIComponent(ad!="T"?a.trim(W[ab].ER):a.trim(W[ab].ER)),searchTerm:a.trim(P),groupName:Y,englishGroupName:T,groupNum:af+1,itemIndex:ab+1}).click(function(ao){if(ai){GATracking(a(this).data("GAData").englishGroupName,a(this).data("GAData").entryClicked,a(this).data("GAData").searchTerm,a(this).data("GAData").groupNum,a(this).data("GAData").itemIndex,scopeCatgoryName)
}})}x=x.html(Q);if(x.width()>V){V=x.width()}p.append(x);if(x.width()>V){V=x.width()}}if(e.textSelectionOnly){}else{if(ah){p.append("<span><a href="+e.host+"_/?Keyword="+escape(P.replace("pn:",""))+" style='text-decoration:underline;padding:0px;' onclick=javascript:GATracking('MP','MoreParts','"+encodeURIComponent(a.trim(P))+"','-1','-1','"+scopeCatgoryName+"') >"+lblMoreParts+"</a></span>")}}}N++;if(e.retrieveLimit&&e.retrieveLimit==N){break}}}if(M){p.append("<span><a href="+e.host+"_/?Keyword="+escape(P)+" style='text-decoration:underline;padding:0px;'>More Parts</a></span>")
}var ag="<div class='bottomMsg'>"+auOffMsg+" <input class='autoimg_bottom' readonly='readonly' id='auimgoff' /></div>";p.parent("div").append(ag);a("input[id=auimgoff], .bottomMsg").click(function(){var ao=getPreferencesCookie();B.unbind();ao.as=0;ao.setCookie({expires:365,path:"/",domain:subdomainname,secure:false});o.hide();a("input[id=auimgon]").show();B.focus();B.val(B.val());a(this).attr("autocomplete","on")});p.height("").width("").css("overflow","auto");o.width("");if(N>0){o.show();if(p.height()>400){p.css("height","400")
}p.parent("div").css("height",p.height()+30);if(p.width()<e.width){p.css("padding","0px");o.css("width",e.width);o.css("padding","0px")}else{var ae=0;a(".as-list li").each(function(){if(a(this).width()>ae){ae=a(this).width()}});if(p.width()>ae){ae=p.width()}o.css("width",ae+15)}if(!e.textSelectionOnly&&B.searchWithin){o.css("top","30px")}if(disableScopeSearch){o.css("top","30px");o.css("left","0")}p.css("width","100%")}B.next("i.search-spinner").remove();e.resultsComplete.call(this)}function J(M,x){K.val(K.val()+M[e.selectedValuesProp]+",");
B.val(M[e.selectedValuesProp].split("##")[0]);B.blur()}function w(R){if(a(":visible",o).length>0){var T=a("li",o);var Q=T.filter(".as-result-item, .as-result-item active");if(R=="down"){var x=Q.eq(0)}else{var x=Q.filter(":last")}var N=a("li.active:first",o);if(N.length>0){if(R=="down"){x=N.next();if(x.hasClass("header")){x=N.next().next()}if((x.index())<(N.last().index())){a(p).scrollTop(T.eq(1))}else{var O=a(x).offset().top;var S=O+a(x).outerHeight();var U=a(p).offset().top;var P=U+a(p).outerHeight();var M=a(p).scrollTop();
if(S>P){a(p).scrollTop(M+(S-P))}else{if(U>O){a(p).scrollTop(M+(O-U))}}}}else{x=N.prev();if(x.hasClass("header")){x=N.prev().prev()}if((x.index())>(a("li",o).first().index())){var O=a(x).offset().top;var S=O+a(x).outerHeight();var U=a(p).offset().top;var P=U+a(p).outerHeight();var M=a(p).scrollTop();if(S>P){a(p).scrollTop(M+(S-P))}else{if(U>O){a(p).scrollTop(M+(O-U))}}}}}T.removeClass("active");x.addClass("active")}}function I(R,Q){var P=R.split(">");var O="";var N=false;if(P.length==1){return R}for(var M=0;M<P.length;
M++){if(P[M].toLowerCase().indexOf(a.trim(Q))>=0||N){O=O+P[M]+(M<(P.length-1)?" > ":"");N=true}}if(O==""){O=R}return O}function m(x){if(x.indexOf("color:red")>0){return x}var N=a.trim(B.val()).replace(/\s+/g," ").split(" ");for(var M=0;M<N.length;M++){if(N[M]!=" "){var O=B.val().length<3?"i":"gi";var P=new RegExp("("+encodeURIComponent(N[M])+")",O);x=x.replace(P,"\x80$1\x81")}}x=x.replace(/\x80/g,"<em>");x=x.replace(/\x81/g,"</em>");x=x.replace(/\*\*\*/g,"<span style='color:blue'>&nbsp;|&nbsp;</span>");x=x.replace(/\|\|\|/g,"<span style='color:blue'>&nbsp;in&nbsp;</span>");
return x}})}}})(jQuery);jQuery.expr[":"].Contains=jQuery.expr.createPseudo(function(a){return function(b){return jQuery(b).text().toUpperCase().indexOf(a.toUpperCase())>=0}});