/* * jQuery SimpleTree Drag&Drop plugin * Update on 22th May 2008 * Version 0.3 * * Licensed under BSD * Copyright (c) 2008, Peter Panov , IKEEN Group http://www.ikeen.com * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Peter Panov, IKEEN Group nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY Peter Panov, IKEEN Group ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL Peter Panov, IKEEN Group BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ (function($) { var NCBOTree = function(element, opt) { var _this = this; var OPTIONS; var ROOT_ID = "roots"; var mousePressed = false; var $TREE_CONTAINER; var TREE; var ROOT; var startingRoot; OPTIONS = { autoclose: false, beforeExpand: false, afterExpand: false, afterExpandError: false, afterSelect: false, afterJumpToClass: false, timeout: 999999, treeClass: "ncboTree", autocompleteClass: "ncboAutocomplete", width: 450, ncboAPIURL: "http://data.bioontology.org", ncboUIURL: "http://bioportal.bioontology.org", apikey: null, pagesize: 1000, ontology: null, startingClass: null, startingRoot: ROOT_ID, defaultRoot: ROOT_ID }; OPTIONS = $.extend(OPTIONS, opt); // Required options if (OPTIONS.apikey == null) throw new Error("You must provide an API Key for NCBO Tree Widget to operate"); if (OPTIONS.ontology == null) throw new Error("You must provide an ontology id for NCBO Tree Widget to operate"); this.options = function() { return OPTIONS; } this.jumpToClass = function(cls, callback) { ROOT.html($("").html("Loading...").css("font-size", "smaller")); $.ajax({ url: determineHTTPS(OPTIONS.ncboAPIURL) + "/ontologies/" + OPTIONS.ontology + "/classes/" + encodeURIComponent(cls) + "/tree", data: {apikey: OPTIONS.apikey, pagesize: OPTIONS.pagesize, display: "prefLabel,definition,subClassOf,hasChildren", no_context: true}, contentType: 'json', crossDomain: true, success: function(roots) { roots = findRootNode(roots); ROOT.html(formatNodes(roots)); setTreeNodes(ROOT, false); if (typeof callback == 'function') { callback(); } _this.selectClass(cls); if (typeof OPTIONS.afterJumpToClass == 'function') { OPTIONS.afterJumpToClass(cls); } $TREE_CONTAINER.trigger("afterJumpToClass", cls); } }); } this.selectClass = function(cls) { var foundClass = $(TREE.find("a[data-id='" + encodeURIComponent(cls) + "']")); $(TREE.find("a.active")[0]).removeClass("active"); foundClass.addClass("active"); } this.selectedClass = function() { var cls = $(TREE.find("a.active")[0]); if (cls.length == 0) { return null; } else { return { id: decodeURIComponent(cls.data("id")), prefLabel: cls.html(), URL: cls.attr("href") }; } } this.changeOntology = function(ont) { var newTree = $("