CINXE.COM
!function(t){var e=function(e,a){var n,o,s,r,i,l=this,c="roots",d=!1;if(n={autoclose:!1,beforeExpand:!1,afterExpand:!1,afterExpandError:!1,afterSelect:!1,afterJumpToClass:!1,timeout:999999,treeClass:"ncboTree",autocompleteClass:"ncboAutocomplete",width:350,ncboAPIURL:"http://data.bioontology.org",ncboUIURL:"http://bioportal.bioontology.org",apikey:null,ontology:null,startingClass:null,startingRoot:c,defaultRoot:c},n=t.extend(n,a),null==n.apikey)throw new Error("You must provide an API Key for NCBO Tree Widget to operate");if(null==n.ontology)throw new Error("You must provide an ontology id for NCBO Tree Widget to operate");this.options=function(){return n},this.jumpToClass=function(e,a){r.html(t("<span>").html("Loading...").css("font-size","smaller")),t.ajax({url:y(n.ncboAPIURL)+"/ontologies/"+n.ontology+"/classes/"+encodeURIComponent(e)+"/tree",data:{apikey:n.apikey,display:"prefLabel,hasChildren",no_context:!0},contentType:"json",crossDomain:!0,success:function(t){t=f(t),r.html(p(t)),C(r,!1),"function"==typeof a&&a(),l.selectClass(e),"function"==typeof n.afterJumpToClass&&n.afterJumpToClass(e),o.trigger("afterJumpToClass",e)}})},this.selectClass=function(e){var a=t(s.find("a[data-id='"+encodeURIComponent(e)+"']"));t(s.find("a.active")[0]).removeClass("active"),a.addClass("active")},this.selectedClass=function(){var e=t(s.find("a.active")[0]);return 0==e.length?null:{id:decodeURIComponent(e.data("id")),prefLabel:e.html(),URL:e.attr("href")}},this.changeOntology=function(e){var a=t("<ul>").append(t("<li>").addClass("root"));o.html(""),s=a,n.ontology=e,l.init()};var p=function(e){var a=t("<span>"),n=t("<ul>");return e.sort(function(t,e){var a=t.prefLabel.toLowerCase(),n=e.prefLabel.toLowerCase();return n>a?-1:a>n?1:0}),t.each(e,function(e,a){var o=t("<li>"),s=t("<a>").attr("href",y(a.links.self)).html(a.prefLabel);s.attr("data-id",encodeURIComponent(a["@id"])),n.append(o.append(s));var r="undefined"!=typeof a.children&&a.hasChildren&&0==a.children.length;if(a.hasChildren&&"undefined"==typeof a.children||r){var i=t("<ul>").addClass("ajax"),l=t("<li>"),c=t("<a>").attr("href",a.links.children);o.append(i.append(l.append(c)))}else if("undefined"!=typeof a.children&&a.children.length>0){var d=p(a.children);o.attr("class","folder-open"),o.append(d)}}),a.append(n),a.html()},f=function(t){var e=n.startingRoot==n.defaultRoot?null:n.startingRoot;if(null==e)return t;for(var a=!1,o=t;o.length>0||0==a;){var s=o.shift();s["@id"]==e?a=[s]:"undefined"!=typeof s.children&&s.children.length>0&&(o=o.concat(s.children))}return a},u=function(e){t(e).siblings().filter(".folder-open, .folder-open-last").each(function(){var e=t(">ul",this),a=this.className;this.className=a.replace("open","close"),e.hide()})},h=function(e){var a=t(">ul",e);a.is(":visible")?(e.className=e.className.replace("open","close"),a.hide()):(e.className=e.className.replace("close","open"),a.show(),n.autoclose&&u(e),a.is(".ajax")&&m(a,e.id))},m=function(e,a,s,r){"function"==typeof n.beforeExpand&&n.beforeExpand(e),o.trigger("beforeExpand",e);var i=y(t.trim(t("a",e).attr("href")));i&&t.ajax({type:"GET",url:i,data:{apikey:n.apikey,display:"prefLabel,hasChildren",no_context:!0},crossDomain:!0,contentType:"json",timeout:n.timeout,success:function(a){var r=p(a.collection);e.removeAttr("class"),e.html(r),t.extend(e,{url:i}),C(e,!0),"function"==typeof n.afterExpand&&n.afterExpand(e),o.trigger("afterExpand",e),"function"==typeof s&&s(e)},error:function(t){"function"==typeof n.afterExpandError&&n.afterExpandError(e),"function"==typeof r&&r(e),o.trigger("afterExpandError",e)}})},C=function(e,a){e=a?e.parent():e,t("li>a",e).addClass("text").bind("selectstart",function(){return!1}).click(function(){var e=(t(this).parent(),t(this));return t(".active",s).attr("class","text"),"text"==this.className&&(this.className="active"),"function"==typeof n.afterSelect&&n.afterSelect(decodeURIComponent(e.data("id")),e.text(),e),o.trigger("afterSelect",[decodeURIComponent(e.data("id")),e.text(),e]),!1}).bind("contextmenu",function(){return t(".active",s).attr("class","text"),"text"==this.className&&(this.className="active"),"function"==typeof n.afterContextMenu&&n.afterContextMenu(parent),!1}).mousedown(function(e){d=!0,cloneNode=t(this).parent().clone();t(this).parent();return!1}),t("li",e).each(function(e){var a=this.className,n=!1,o=t(">ul",this);if(o.size()>0){var s="folder-";a&&a.indexOf("open")>=0?(s+="open",n=!0):s+="close",this.className=s+(t(this).is(":last-child")?"-last":""),(!n||a.indexOf("ajax")>=0)&&o.hide(),g(this)}else{var s="doc";this.className=s+(t(this).is(":last-child")?"-last":"")}}).before('<li class="line"> </li>').filter(":last-child").after('<li class="line-last"></li>')},g=function(e){t(">a",e).before('<img class="trigger" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" border=0>');var a=t(">.trigger",e);a.click(function(t){h(e)})},y=function(t){return t.replace("http:","https:"==document.location.protocol?"https:":"http:")},v=function(){var e=t("<div>").addClass(n.autocompleteClass).addClass("ncboTree"),a=t("<input>").addClass(n.autocompleteClass).css("width",n.width).attr("placeholder","Search for class...");e.append(a),a.NCBOAutocomplete({url:n.ncboAPIURL+"/search",searchParameter:"q",resultAttribute:"collection",property:"prefLabel",searchTextSuffix:"*",searchFromRoot:i,onSelect:function(t,e){l.jumpToClass(t["@id"]),e.val("")},minCharacters:3,additionalParameters:{apikey:n.apikey,no_context:!0,ontologies:n.ontology}}),o.append(e)};this.init=function(){o=e,s=t("<ul>").append(t("<li>").addClass("root")),r=t(".root",s),s.css("width",n.width).addClass(n.treeClass),o.html(""),i=n.startingRoot==n.defaultRoot?null:n.startingRoot,v(),o.append(s),null!==n.startingClass?(l.jumpToClass(n.startingClass),n.startingClass=null):(r.html(t("<span>").html("Loading...").css("font-size","smaller")),t.ajax({url:y(n.ncboAPIURL)+"/ontologies/"+n.ontology+"/classes/"+encodeURIComponent(n.startingRoot),data:{apikey:n.apikey,display:"prefLabel,hasChildren",no_context:!0},contentType:"json",crossDomain:!0,success:function(e){e=t.map([e],function(t){return t}),r.html(p(e)),C(r,!1)}}))}};t.fn.NCBOTree=function(a){return this.each(function(){var n=t(this);if(!n.data("NCBOTree")){var o=new e(n,a);this.NCBOTree=o,t.ajax({url:o.options().ncboUIURL.replace("http:","https:"==document.location.protocol?"https:":"http:")+"/widgets/jquery.ncbo.autocomplete.js",type:"GET",crossDomain:!0,dataType:"script",success:function(){o.init(),n.data("NCBOTree",o)}})}})}}(jQuery);