ncbo/bioportal_web_ui

View on GitHub
public/widgets/minified/jquery.ncbo.autocomplete.min.js

Summary

Maintainability
A
0 mins
Test Coverage
(function(a){a.fn.NCBOAutocomplete=function(c){var d={url:"",data:[],minCharacters:1,maxResults:undefined,wildCard:"",caseSensitive:false,notCharacter:"!",maxHeight:350,highlightMatches:true,onSelect:undefined,width:undefined,property:"text",searchParameter:"search",additionalParameters:{},resultAttribute:null,searchTextSuffix:"",searchFromRoot:null},b;c=a.extend(d,c);if(c.searchFromRoot!=null){c.additionalParameters.subtree_id=c.searchFromRoot;c.additionalParameters.ontology=c.additionalParameters.ontologies}return this.each(function(){function h(t,x){var u=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];if(x){for(var w=0;w<u.length;w++){if(u[w]===x){u.splice(w,1)}}}var v=new RegExp("(\\"+u.join("|\\")+")","g");return t.replace(v,"\\$1")}var l=a(this),g=new RegExp(h(c.wildCard||""),"g"),m=a("<ul />"),i,k,j;function f(t){l.val(t[c.property]);a(m).html("").hide();if(typeof c.onSelect==="function"){c.onSelect(t,l)}}function p(t){return t.height()<t[a.fn.prop?"prop":"attr"]("scrollHeight")}function n(t,y,C,B){var v=a.extend({scrollTarget:y,offsetTop:185,duration:0,easing:"linear"},C);var u=a(t);var z=(typeof v.scrollTarget==="number")?v.scrollTarget:a(v.scrollTarget);if(p(u)){var w=z.offset().top-u.offset().top,A=u.scrollTop(),x=u.height();if(w<0){u.scrollTop(A+w)}else{if(w>=x){u.scrollTop(A+w-x+z.height())}}}}function e(t){a("li a",m).removeClass("ui-state-hover");if(t){a("a",t).addClass("ui-state-hover")}i=t}function s(w,t){t="("+t+")";var A=true,u,z=0,x=c.caseSensitive?new RegExp(t,"g"):new RegExp(t,"ig");a(m).html("").hide();for(u=0;u<w.length;u+=1){var v=a("<li />"),y=w[u][c.property];if(c.highlightMatches===true){y=y.replace(x,"<strong>$1</strong>")}a(v).append('<a class="ui-corner-all">'+y+"</a>");if(typeof w[u].image==="string"){a(">a",v).prepend('<img src="'+w[u].image+'" />')}if(typeof w[u].extra==="string"){a(">a",v).append("<small>"+w[u].extra+"</small>")}a(v).addClass("ui-menu-item").addClass((A)?"odd":"even").attr("role","menuitem").click((function(B){return function(){f(w[B])}})(u)).mouseover((function(B){return function(){e(B)}})(v));a(m).append(v);A=!A;z+=1;if(typeof c.maxResults==="number"&&z>=c.maxResults){break}}if(a("li",m).length>0){i=undefined;a(m).show().css("height","auto");if(a(m).height()>c.maxHeight){a(m).css({overflow:"auto",height:c.maxHeight+"px"})}}}function o(u){var t=function(z){if(this.value.length<c.minCharacters){r();return false}var A=[],x=(!c.wildCard)?h(this.value):h(this.value,c.wildCard).replace(g,".*"),w=true,B,y;if(c.notCharacter&&x.indexOf(c.notCharacter)===0){x=x.substr(c.notCharacter.length,x.length);if(x.length>0){w=false}}x=x||".*";x=c.wildCard?"^"+x:x;B=c.caseSensitive?new RegExp(x):new RegExp(x,"i");for(y=0;y<z.length;y+=1){if(B.test(z[y][c.property])===w){A.push(z[y])}}s(A,x)};if(c.data&&c.data.length){t.apply(this,[c.data])}else{if(c.url&&typeof c.url==="string"){var v=this.value;if(v.length<c.minCharacters){r();return false}a(m).html('<li class="ui-menu-item ajaxSearching"><a class="ui-corner-all">Searching...</a></li>').show().css("height","auto");b=window.clearTimeout(b);b=window.setTimeout(function(){var w={};w[c.searchParameter]=v+c.searchTextSuffix;a.extend(w,c.additionalParameters);a.ajax({url:c.url.replace("http:",("https:"==document.location.protocol?"https:":"http:")),data:w,contentType:"json",success:function(y){if(y){var x=(c.resultAttribute===null)?y:y[c.resultAttribute];s(x,v)}else{r()}}})},500)}}}function r(){a(m).html("").hide()}function q(t){switch(t.keyCode){case 9:case 27:case 16:case 17:case 18:case 20:case 91:case 93:case 144:case 224:return false;case 13:a(i).trigger("click");return false;case 40:if(t.type=="keyup"){return false}if(typeof i==="undefined"){i=a("li:first",m).get(0)}else{i=a(i).next().get(0)}e(i);if(i){n(m,i)}return false;case 38:if(t.type=="keyup"){return false}if(typeof i==="undefined"){i=a("li:last",m).get(0)}else{i=a(i).prev().get(0)}e(i);if(i){n(m,i)}return false;default:o.apply(this,[t])}}a(m).addClass("jsonSuggest ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all").attr("role","listbox").css({top:(l.position().top+l.outerHeight())+"px",left:l.position().left+"px",width:c.width||(l.outerWidth()+"px"),"z-index":999}).hide();l.after(m).keydown(q).keyup(q).blur(function(u){var t=a(m).offset();t.bottom=t.top+a(m).height();t.right=t.left+a(m).width();if(j<t.top||j>t.bottom||k<t.left||k>t.right){a(m).hide()}}).focus(function(t){a(m).css({top:(l.position().top+l.outerHeight())+"px",left:l.position().left+"px"});if(a("li",m).length>0){a(m).show()}}).attr("autocomplete","off");a(window).mousemove(function(t){k=t.pageX;j=t.pageY});c.notCharacter=h(c.notCharacter||"");if(c.data&&typeof c.data==="string"){c.data=a.parseJSON(c.data)}})}})(jQuery);