");
definitionDiv.addClass('result_definition');
definitionDiv.text("retreiving definitions...");
definitionDiv.append(definitionAjax);
return definitionDiv;
}
function jumpTo_setup_functions() {
var extra_params = {
subtreerootconceptid: encodeURIComponent(BP_search_branch)
};
var result_width = 350;
// Add extra space for definition
if (BP_include_definitions) {
result_width += 300;
}
// Add space for ontology name
if (BP_ontology_id === "") {
result_width += 250;
} else {
result_width += 100;
}
jQuery(jumpTo_searchBoxSelector).bioportal_autocomplete(BP_SEARCH_SERVER + "/search/json_search/" + BP_ontology_id, {
extraParams: extra_params,
lineSeparator: "~!~",
matchSubset: 0,
minChars: 3,
maxItemsToShow: 20,
onFindValue: jumpTo_jumpToValue,
onItemSelect: jumpTo_jumpToSelect,
width: result_width,
footer: '
',
formatItem: jumpTo_formatItem
});
// Setup polling to get definitions
if (BP_include_definitions) {
getWidgetAjaxContent();
}
}
// Poll for potential definitions returned with results
function getWidgetAjaxContent() {
// Look for anchors with a get_via_ajax class and replace the parent with the resulting ajax call
$(".get_definition_via_ajax").each(function() {
var def_link = $(this);
if (typeof def_link.attr("getting_content") === 'undefined') {
def_link.attr("getting_content", true);
$.getJSON(def_link.attr("href"), function(data) {
var definition = (typeof data.definition === 'undefined') ? "" : data.definition.join(" ");
def_link.parent().html(truncateText(decodeURIComponent(definition.replace(/\+/g, " "))));
});
}
});
setTimeout(getWidgetAjaxContent, 100);
}
// Sets a hidden form value that records the concept id when a concept is chosen in the jump to
// This is a workaround because the default autocomplete search method cannot distinguish between two
// concepts that have the same preferred name but different ids.
function jumpTo_jumpToSelect(li) {
jQuery("#jump_to_concept_id").val(li.extra[0]);
jQuery("#jump_to_ontology_id").val(li.extra[2]);
}
function jumpTo_jump_clicked() {
jQuery("#BP_search_box")[0].autocompleter.findValue();
}
function truncateText(text, max_length) {
if (typeof max_length === 'undefined' || max_length == "") {
max_length = 70;
}
var more = '...';
var content_length = $.trim(text).length;
if (content_length <= max_length)
return text; // bail early if not overlong
var actual_max_length = max_length - more.length;
var truncated_node = jQuery("
");
var full_node = jQuery("
").html(text).hide();
text = text.replace(/^ /, ''); // node had trailing whitespace.
var text_short = text.slice(0, max_length);
// Ensure HTML entities are encoded
// http://debuggable.com/posts/encode-html-entities-with-jquery:480f4dd6-13cc-4ce9-8071-4710cbdd56cb
text_short = $('
').text(text_short).html();
var other_text = text.slice(max_length, text.length);
text_short += "
" + more + "";
text_short += "
" + other_text + "";
return text_short;
}