Changeset 1345
- Timestamp:
- Jan 7, 2011, 12:11:03 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web-app/js/ontology-chooser.min.js
r1321 r1345 1 function OntologyChooser(){}OntologyChooser.prototype={cache:[],ctrl:false,noSearch:false,clipboard:[],options:{minLength:3,showHide:null,spinner:" ../images/spinner.gif"},init:function(a){var b=this;if(a){$.each(a,function(c,d){b.options[c]=d})}if(this.options.showHide){this.options.showHide.hide()}$("input[rel*='ontology']").each(function(){b.initAutocomplete(this)})},initAutocomplete:function(d){var f=this;var g=$(d);var e=false;var c=g.attr("rel").split("-");var b=c[1];var a=c[2];if(b=="all"){b=""}g.bind("keydown",function(h){if(h.keyCode==17||h.keyCode==224){f.ctrl=true}if(h.keyCode==13){return false}if(h.keyCode==8&&f.options.showHide){f.options.showHide.hide()}if(h.keyCode==67&&f.ctrl){return f.copy(g)}if(h.keyCode==86&&f.ctrl){return f.paste(g)}});g.bind("keyup",function(h){if(h.keyCode==17||h.keyCode==224){f.ctrl=false}});g.autocomplete({minLength:f.options.minLength,delay:300,search:function(h,i){if(f.noSearch){f.noSearch=false;return false}if(f.options.spinner){g.css({background:"url("+f.options.spinner+") no-repeat right top"})}e=false},source:function(j,h){var k=$.trim(j.term);var i="http://bioportal.bioontology.org/search/json_search/"+b+"?q="+j.term+"&response=json&callback=?";if(f.cache[k]){g.css({background:"none"});h(f.cache[k])}else{$.getJSON(i,function(m){var l=f.parseData(m.data,b);f.cache[k]=l;g.css({background:"none"});if(!m.data){if(f.options.showHide){f.options.showHide.hide()}f.setInputValue(g,"concept_id",null);f.setInputValue(g,"ontology_id",null);f.setInputValue(g,"ncbo_id",null);f.setInputValue(g,"full_id",null)}h(l)})}},select:function(i,j){e=true;var h=g;f.setInputValue(h,"concept_id",j.item.concept_id);f.setInputValue(h,"ontology_id",j.item.ontology_id);f.setInputValue(h,"ncbo_id",j.item.ncbo_id);f.setInputValue(h,"full_id",j.item.full_id);h.removeClass("error");if(f.options.showHide){f.options.showHide.show()}},close:function(i,j){if(!e){var h=g;g.val("");f.setInputValue(h,"concept_id","");f.setInputValue(h,"ontology_id","");f.setInputValue(h,"ncbo_id","");f.setInputValue(h,"full_id","");h.addClass("error")}},html:true})},setInputValue:function(e,c,d){var a=e.attr("name")+"-"+c;var b=e.parent().find("input[name='"+a+"']");if(b.size()>0){$(b[0]).val(d)}else{e.after('<input type="hidden" name="'+a+'" value="'+d+'"/>')}},getInputValue:function(d,c){var a=d.attr("name")+"-"+c;var b=d.parent().find("input[name='"+a+"']");return(b.size()>0)?$(b[0]).val():""},parseData:function(d,f){var a=[];var c=d.split("~!~");for(var b=0;b<c.length;b++){var g=$.trim(c[b]);if(g){var e=g.split("|");var h;if(e.length>8){h=e[8]}else{h=f}a[a.length]={value:e[0],label:e[0]+' <span class="about">('+e[2]+')</span> <span class="from">from: '+e[(e.length-2)]+"</span>",preferred_name:e[0],concept_id:e[1],ontology_id:e[3],full_id:e[4],ncbo_id:h}}}return a},copy:function(a){this.clipboard={sourceValue:$(a).val(),concept_id:this.getInputValue(a,"concept_id"),ontology_id:this.getInputValue(a,"ontology_id"),ncbo_id:this.getInputValue(a,"ncbo_id"),full_id:this.getInputValue(a,"full_id")};return false},paste:function(b){if(this.clipboard.sourceValue&&this.clipboard.concept_id&&this.clipboard.ncbo_id&&this.clipboard.full_id){var a=new RegExp(this.clipboard.ncbo_id);if(b.attr("rel").match(a)||b.attr("rel").match(/all/)){this.noSearch=true;$(b).val(this.clipboard.sourceValue);this.setInputValue(b,"concept_id",this.clipboard.concept_id);this.setInputValue(b,"ontology_id",this.clipboard.ontology_id);this.setInputValue(b,"ncbo_id",this.clipboard.ncbo_id);this.setInputValue(b,"full_id",this.clipboard.full_id)}}return false}};1 function OntologyChooser(){}OntologyChooser.prototype={cache:[],ctrl:false,noSearch:false,clipboard:[],options:{minLength:3,showHide:null,spinner:"http://www.ajaxload.info/images/exemples/2.gif"},init:function(a){var b=this;if(a){$.each(a,function(c,d){b.options[c]=d})}if(this.options.showHide){this.options.showHide.hide()}$("input[rel*='ontology']").each(function(){b.initAutocomplete(this)})},initAutocomplete:function(d){var f=this;var g=$(d);var e=false;var c=g.attr("rel").split("-");var b=c[1];var a=c[2];if(b=="all"){b=""}g.bind("keydown",function(h){if(h.keyCode==17||h.keyCode==224){f.ctrl=true}if(h.keyCode==13){return false}if(h.keyCode==8&&f.options.showHide){f.options.showHide.hide()}if(h.keyCode==67&&f.ctrl){return f.copy(g)}if(h.keyCode==86&&f.ctrl){return f.paste(g)}});g.bind("keyup",function(h){if(h.keyCode==17||h.keyCode==224){f.ctrl=false}});g.autocomplete({minLength:f.options.minLength,delay:300,search:function(h,i){if(f.noSearch){f.noSearch=false;return false}if(f.options.spinner){g.css({background:"url("+f.options.spinner+") no-repeat right top"})}e=false},source:function(j,h){var k=$.trim(j.term);var i="http://bioportal.bioontology.org/search/json_search/"+b+"?q="+j.term+"&response=json&callback=?";if(f.cache[k]){g.css({background:"none"});h(f.cache[k])}else{$.getJSON(i,function(m){var l=f.parseData(m.data,b);f.cache[k]=l;g.css({background:"none"});if(!m.data){if(f.options.showHide){f.options.showHide.hide()}f.setInputValue(g,"concept_id",null);f.setInputValue(g,"ontology_id",null);f.setInputValue(g,"ncbo_id",null);f.setInputValue(g,"full_id",null)}h(l)})}},select:function(i,j){e=true;var h=g;f.setInputValue(h,"concept_id",j.item.concept_id);f.setInputValue(h,"ontology_id",j.item.ontology_id);f.setInputValue(h,"ncbo_id",j.item.ncbo_id);f.setInputValue(h,"full_id",j.item.full_id);h.removeClass("error");if(f.options.showHide){f.options.showHide.show()}},close:function(i,j){if(!e){var h=g;g.val("");f.setInputValue(h,"concept_id","");f.setInputValue(h,"ontology_id","");f.setInputValue(h,"ncbo_id","");f.setInputValue(h,"full_id","");h.addClass("error")}},html:true})},setInputValue:function(e,c,d){var a=e.attr("name")+"-"+c;var b=e.parent().find("input[name='"+a+"']");if(b.size()>0){$(b[0]).val(d)}else{e.after('<input type="hidden" name="'+a+'" value="'+d+'"/>')}},getInputValue:function(d,c){var a=d.attr("name")+"-"+c;var b=d.parent().find("input[name='"+a+"']");return(b.size()>0)?$(b[0]).val():""},parseData:function(d,f){var a=[];var c=d.split("~!~");for(var b=0;b<c.length;b++){var g=$.trim(c[b]);if(g){var e=g.split("|");var h;if(e.length>8){h=e[8]}else{h=f}a[a.length]={value:e[0],label:e[0]+' <span class="about">('+e[2]+')</span> <span class="from">from: '+e[(e.length-2)]+"</span>",preferred_name:e[0],concept_id:e[1],ontology_id:e[3],full_id:e[4],ncbo_id:h}}}return a},copy:function(a){this.clipboard={sourceValue:$(a).val(),concept_id:this.getInputValue(a,"concept_id"),ontology_id:this.getInputValue(a,"ontology_id"),ncbo_id:this.getInputValue(a,"ncbo_id"),full_id:this.getInputValue(a,"full_id")};return false},paste:function(b){if(this.clipboard.sourceValue&&this.clipboard.concept_id&&this.clipboard.ncbo_id&&this.clipboard.full_id){var a=new RegExp(this.clipboard.ncbo_id);if(b.attr("rel").match(a)||b.attr("rel").match(/all/)){this.noSearch=true;$(b).val(this.clipboard.sourceValue);this.setInputValue(b,"concept_id",this.clipboard.concept_id);this.setInputValue(b,"ontology_id",this.clipboard.ontology_id);this.setInputValue(b,"ncbo_id",this.clipboard.ncbo_id);this.setInputValue(b,"full_id",this.clipboard.full_id)}}return false}};
Note: See TracChangeset
for help on using the changeset viewer.