JAVASCRIPT 21
UAAutoComplete.js Guest on 11th July 2020 03:42:36 PM
  1. var acConfig={"EDITION-SELECTION":{"UA-GeneralSearch-input":{UA_GeneralSearch_input_form:{AU:"off",SO:"on"}},"WOS-GeneralSearch-input":{WOS_GeneralSearch_input_form:{AU:"off",SO:"on"}},"ARCI-GeneralSearch-input":{ARCI_GeneralSearch_input_form:{AU:"off",SO:"on"}},"BCI-GeneralSearch-input":{BCI_GeneralSearch_input_form:{AU:"off",SO:"on"}},"CSCD-GeneralSearch-input":{CSCD_GeneralSearch_input_form:{AU:"off",SO:"on"}},"FSTA-GeneralSearch-input":{FSTA_GeneralSearch_input_form:{AU:"off",SO:"on"}},"MEDLINE-GeneralSearch-input":{MEDLINE_GeneralSearch_input_form:{AU:"off",SO:"on"}},"CABI-GeneralSearch-input":{CABI_GeneralSearch_input_form:{AU:"off",SO:"on"}},"CCC-GeneralSearch-input":{CCC_GeneralSearch_input_form:{AU:"off",SO:"on"}},"INSPEC-GeneralSearch-input":{INSPEC_GeneralSearch_input_form:{AU:"off",SO:"on"}},"ZOOREC-GeneralSearch-input":{ZOOREC_GeneralSearch_input_form:{AU:"off",SO:"on"}},"DIIDW-GeneralSearch-input":{DIIDW_GeneralSearch_input_form:{AU:"off",SO:"off"}},"BIOABS-GeneralSearch-input":{BIOABS_GeneralSearch_input_form:{AU:"off",SO:"on"}},"BIOSIS-GeneralSearch-input":{BIOSIS_GeneralSearch_input_form:{AU:"off",SO:"on"}},"DRCI-GeneralSearch-input":{DRCI_GeneralSearch_input_form:{AU:"off",SO:"on"}},"SCIELO-GeneralSearch-input":{SCIELO_GeneralSearch_input_form:{AU:"off",SO:"on"}},"KJD-GeneralSearch-input":{KJD_GeneralSearch_input_form:{AU:"off",SO:"on"}},"RSCI-GeneralSearch-input":{RSCI_GeneralSearch_input_form:{AU:"off",SO:"on"}}}};var acFieldConfig={"default":{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},UA:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},WOS:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},ARCI:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},BCI:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},CSCD:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},FSTA:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},MEDLINE:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},CABI:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},CCC:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},INSPEC:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},ZOOREC:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},DIIDW:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},BIOABS:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},BIOSIS:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},DRCI:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},SCIELO:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},KJD:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}},RSCI:{AU:{sort:"alphabetical",index:"author",boolRegExp:"\\b(and|or|not|same)\\b"},SO:{sort:"alphabetical",index:"source",boolRegExp:"\\b(or)\\b"}}};var acSearchLanguageConfig={auto:"ON",en:"ON",zh:"OFF",pt:"OFF"};var enableAC="TRUE";var STATUS_ON="ON";var STATUS_OFF="OFF";var STATUS_DISABLED="DISABLED";var dataType="json";var jsonpCallback="";var jsonpRequestParameter="";var editions="";var testEditions="WOS.SCI";var regDoubleQuotes=new RegExp('"',"g");$.ui.autocomplete.prototype._renderItem=function(b,d){var a=$.trim(this.term.toLowerCase());a=a.replace(/\s{2,}/g," ");a=a.replace(/[+|&|\']/g,"");var c=new RegExp("^"+a);t=d.label.replace(c,"<span style='font-weight:normal;'>"+a+"</span>");return $("<li></li>").data("item.autocomplete",d).append("<a><span style='font-size:75%;font-weight:bold;font-family:Arial, Helvetica, sans-serif;'>"+t+"</span></a>").appendTo(b)};function createCORSRequest_to_be_removed_05_30_2013(c,a){var b=new XMLHttpRequest();if("withCredentials" in b){b.open(c,a,true)}else{if(typeof XDomainRequest!="undefined"){b=new XDomainRequest();b.open(c,a)}else{b=null}}return b}function makeCorsRequestInitial_to_be_removed_05_30_2013(d,a,c,e,g,b,h){var f=createCORSRequest("GET",g);if(!f){alert("CORS not supported");return}f.onload=function(){prepareACForBodyOnLoad(d,a,c,e,g,b,h)};f.onerror=function(){displayACNotAvailable()};f.send()}function convertToJSON(a){a=JSON.stringify(a)}function prepareACForBodyOnLoadInitial(c,d,i,l,k,j,b,g,a){var e=$('select[name="ss_query_language"] option:selected').val();var m=null;if(e!=null){m=acSearchLanguageConfig[e]}var h=$('select[name="ss_showsuggestions"] option:selected').val();enableAC=c.toUpperCase();if($('input:checkbox[name$="editions"]').size()<=0||d!="EDITION-SELECTION"){editions=a}else{prepareEditions(k,a)}if(!$.support.cors){jsonpRequestParameter="jsonp";dataType="jsonp";jsonpCallback="convertToJSON"}if(enableAC=="TRUE"){if(h!=null){if(m==null||m==STATUS_ON){$.ajax({type:"GET",url:j+"&field=source&count="+g+"&term=journal&editions="+testEditions,jsonp:jsonpRequestParameter,jsonpCallback:jsonpCallback,contentType:"text/plain",dataType:dataType,crossDomain:true,success:function(n){if(h==STATUS_ON){prepareACForBodyOnLoad(d,i,l,k,j,b,g)}else{turnOffAutoComplete(l)}},error:function(){displayACNotAvailable()}})}else{turnOffAutoComplete(l)}}else{}$('select[name="ss_showsuggestions"]').select2({minimumResultsForSearch:Infinity}).on("change",function(n){$(this).removeClass("select2-offscreen").select2({data:n[$(this).val()]})}).trigger("change")}else{var f=acConfig[d][i][l]["SO"];if(f=="on"){displayACNotAvailable()}}}function prepareEditions(c,a){editions="";var b="";if(c!="UA"){b=c+"."}$('input:checkbox[name$="editions"]').each(function(){if($(this).is(":checked")){editions+=b+$(this).val()+","}$(this).unbind("change");$(this).change(function(){editions="";$('input:checkbox[name$="editions"]:checked').each(function(){editions+=b+$(this).val()+","});if(editions!=""){editions=editions.substring(0,editions.length-1)}else{editions=a}})});if(editions!=""){editions=editions.substring(0,editions.length-1)}else{editions=a}}function prepareACForBodyOnLoad(d,a,c,e,f,b,g){$('form[name="'+c+'"] select[name^="value(select"]').each(function(){prepareAutoComplete($(this),d,a,c,e,f,b,g)})}function prepareACForAddSearchRow(b,c,g,j,i,h,a,e){enableAC=b.toUpperCase();var d=$('select[name="ss_query_language"] option:selected').val();var k=null;if(d!=null){k=acSearchLanguageConfig[d]}var f=$('select[name="ss_showsuggestions"] option:selected').val();if(enableAC=="TRUE"&&(k==null||k==STATUS_ON)&&f==STATUS_ON){if(!$.support.cors){h+="&jsonp=?"}var l=$('form[name="'+j+'"] select[name^="value(select"]').last();prepareAutoComplete(l,c,g,j,i,h,a,e)}}function prepareAutoComplete(e,j,g,o,a,b,s,u){var k=e.val();var n=e.attr("name");var v=e.attr("id");var m=v.substring(6);var p=parseInt(m)-1;var h="value(input"+m+")";var f=acConfig[j][g][o][k];if(f=="on"){var l=acFieldConfig[a][k].index;var r=acFieldConfig[a][k].sort;var c=acFieldConfig[a][k].boolRegExp;enableAutoComplete(h,b,l,s,u,r,c,o)}var d=function(){if($('select[name="ss_showsuggestions"] option:selected').val()==STATUS_ON){var z=true;if($('form[name="'+o+'"] select[name="value(input'+m+')"]').length>0){z=false}var y=$(this).val();var i=acConfig[j][g][o][y];if(z){if(i=="on"){var A=acFieldConfig[a][y].index;var w=acFieldConfig[a][y].sort;var x=acFieldConfig[a][y].boolRegExp;enableAutoComplete(h,b,A,s,u,w,x,o)}else{disableAutoComplete(h)}}}};var q=function(){$(this).unbind("change",d)};$(document).delegate('select[name$="'+n+'"]',"change",d);$(document).delegate('select[name$="'+n+'"]',"acunbindevent",q)}function enableAutoComplete(b,i,e,a,f,d,h,j){var c=$('select[name="ss_query_language"] option:selected').val();var k=null;if(c!=null){k=acSearchLanguageConfig[c]}var g=$('select[name="ss_showsuggestions"] option:selected').val();if(enableAC=="TRUE"&&(k==null||k==STATUS_ON)&&g==STATUS_ON){$('input[name$="'+b+'"]').attr("autocomplete","off");$('input[name$="'+b+'"]').autocomplete({disabled:false,open:function(){var m=$('input[name$="'+b+'"]').position().left;$(".ui-autocomplete:visible").css({left:"-="+m});var l=$('input[name$="'+b+'"]').width()+40;$(".ui-autocomplete:visible").css({width:l})},source:function(p,o){var m=p.term;m=m.replace(/^\s+/,"");m=m.replace(/[+|&|\']/g,"");m=m.replace(/\"\"/g,"");var n="";var l=m.charAt(m.length-1);if(l!='"'&&l!="'"){n=getACPhrase(m,h)}n=n.replace(/^\s+/,"");n=n.replace(/[+|&|\']/g,"");n=n.replace(/\"\"/g,"");if(n!=null&&n.length>a-1){getACResults(o,b,i,e,d,f,m,n)}else{$('input[name$="'+b+'"]').autocomplete("close")}},select:function(m,n){var l=$('input[name$="'+b+'"]');l.val(n.item.value);saveForm(j)},minLength:a})}}function getACResults(d,c,g,f,e,h,a,b){$.ajax({type:"GET",url:g+"&field="+f+"&count="+h+"&term="+b+"&editions="+editions,jsonp:jsonpRequestParameter,jsonpCallback:jsonpCallback,contentType:"text/plain",dataType:dataType,crossDomain:true,success:function(i){a=$.trim(a.toLowerCase());a=a.replace(/\s{2,}/g," ");b=$.trim(b.toLowerCase());b=b.replace(/\s{2,}/g," ");if(i==null){$('input[name$="'+c+'"]').autocomplete("close")}else{if(e=="alphabetical"){i=getKeysOfArray(i);i=i.sort();d($.map(i,function(j){j=j.replace(b,"");return a+j}))}else{d($.map(i,function(k,j){j=j.replace(b,"");return{label:a+j,value:a+j}}))}}},error:function(){$('input[name$="'+c+'"]').autocomplete("close")}})}function disableAutoComplete(a){$('input[name$="'+a+'"]').attr("autocomplete","on");$('input[name$="'+a+'"]').autocomplete({disabled:true})}function getACPhrase(d,j){var a=d;var k="";var c="";var g=new RegExp(j,"i");while(c=g.exec(a)){k="";a=a.substring(c.index+c.length+1,a.length);k=c[0]}var h=d.lastIndexOf(" "+k+" ");var b="";if(h>0){b=d.substring(0,h)}else{b=d}var f=b.match(regDoubleQuotes);var i=0;if(f!=null){i=f.length}var e=d;if(i%2==0&&k){e=d.substring(b.length+k.length+1,d.length)}e=e.replace(new RegExp('"',"g"),"");return e}function getKeysOfArray(b){var a=[];$.each(b,function(c){a.push(c)});return a}function turnOnAutoComplete(c,f,i,h,g,b,d,a,e){if(e!=null){$.ajax({url:e+"&status="+STATUS_ON})}prepareACForBodyOnLoad(c,f,i,h,g,b,d)}function turnOffAutoComplete(a,b){if(b!=null){$.ajax({url:b+"&status="+STATUS_OFF})}$('form[name="'+a+'"] input:text').each(function(){disableAutoComplete($(this).attr("id"))});$('form[name="'+a+'"] select[name^="value(select"]').each(function(){$(this).trigger("acunbindevent")})}function updateACStatusOnSearchLanguageChange(c,h,k,j,i,b,e,a,f){var d=$('select[name="ss_query_language"] option:selected').val();var l=null;if(d!=null){l=acSearchLanguageConfig[d]}var g=$('select[name="ss_showsuggestions"] option:selected').val();if(l==STATUS_ON){if(g==null){}else{if(g==STATUS_ON){$('select[name="ss_showsuggestions"]').val(STATUS_ON).attr("selected","selected").trigger("change");turnOnAutoComplete(c,h,k,j,i,b,e,a,f)}else{$('select[name="ss_showsuggestions"]').val(STATUS_OFF).attr("selected","selected").trigger("change");turnOffAutoComplete(k,f)}}}else{if(g==STATUS_ON){$('select[name="ss_showsuggestions"]').val(STATUS_OFF).attr("selected","selected").trigger("change");turnOffAutoComplete(k,f)}else{}}}function changeACStatus(c,h,k,j,i,b,e,a,f){var d=$('select[name="ss_query_language"] option:selected').val();var l=null;if(d!=null){l=acSearchLanguageConfig[d]}var g=$('select[name="ss_showsuggestions"] option:selected').val();if(g==STATUS_ON){if(l==null||l==STATUS_ON){turnOnAutoComplete(c,h,k,j,i,b,e,a,f)}else{$('select[name="ss_showsuggestions"]').val(STATUS_OFF).attr("selected","selected").trigger("change");turnOffAutoComplete(k,f)}}else{turnOffAutoComplete(k,f)}}function displayACNotAvailable(){$("#autoCompleteNotAvailable").css("display","block");$("#autoCompleteAvailable").css("display","none")};

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.