$(function(){
scrolldiv();
loadStartClass();
$('#searchstart').keypress(function(e) {
if ( e.which == 13 ) {
return false;
}
});
$('#searchstart').keyup(function(e) {
search();
});
$('#searchend').keypress(function(e) {
if ( e.which == 13 ) {
return false;
}
});
$('#searchend').keyup(function(e) {
search();
});
});
function scrolldiv(){
if(($('div.startclass').height() + $('#searchstart').height()) > $('div.left').height()){
$('div.left').css('overflow-y', 'scroll');
}else{
$('div.left').css('overflow-y', 'hidden');
}
if(($('div.endclass').height() + $('#searchend').height()) > $('div.right').height()){
$('div.right').css('overflow-y', 'scroll');
}else{
$('div.right').css('overflow-y', 'hidden');
}
}
function loadStartClass(){
var url = "http://www.sparqlbuilder.org/api/clist?ep=" + encodeURIComponent("http://www.ebi.ac.uk/rdf/services/reactome/sparql");
$.ajax({
type : "GET",
url : url,
success : function(data) {
var list = eval(data);
$('div.startclass').empty();
var startclasstable = $('
');
for (var i = 0; i < list.length; ++i) {
startclasstable.append('' + list[i]['label'] + ' (' + list[i]['number'] + ')' + ' |
');
}
$('div.startclass').append(startclasstable);
requestEndClass();
scrolldiv();
}
});
}
function requestEndClass(){
$('.startclasscell').each(function(){
$(this).unbind('click');
$(this).click(function(){
$('.endclass').empty();
$('.endclass').append('');
var ep = $(this).children('.endpointuri').attr('title');
var sc = $(this).children('.startclassuri').attr('title');
var url = "http://www.sparqlbuilder.org/api/clist?ep=" + encodeURIComponent(ep) + '&class=' + encodeURIComponent(sc);
$.ajax({
type : "GET",
url : url,
success : function(data) {
var list = eval(data);
$('.endclass').empty();
var endclasstable = $('');
for (var i = 0; i < list.length; ++i) {
endclasstable.append('' + list[i]['label'] + ' (' + list[i]['number'] + ')' + ' |
');
}
$('.endclass').append(endclasstable);
requestSPARQLBuilder();
}
});
});
});
}
function requestSPARQLBuilder(){
$('.endclasscell').each(function(){
$(this).unbind('click');
$(this).click(function(){
var ep = $(this).children('.endpointuri').attr('title');
var sc = $(this).children('.startclassuri').attr('title');
var ec = $(this).children('.endclassuri').attr('title');
var url = "http://www.sparqlbuilder.org/?ep=" + encodeURIComponent(ep) + '&st=' + encodeURIComponent(sc) + '&en=' + encodeURIComponent(ec);
window.open(url);
});
})
}
function search(){
if($('#searchstart').val() == ''){
$('.startclasscell').parent().removeClass('nohit');
}else{
var keyword = $('#searchstart').val().toLowerCase();
$('.startclasscell').each(function(){
var label = $(this).children('.startclassuri').text().toLowerCase();
if(label.indexOf(keyword) != -1){
$(this).parent().removeClass('nohit');
}else{
$(this).parent().addClass('nohit');
}
});
}
if($('#searchend').val() == ''){
$('.endclasscell').parent().removeClass('nohit');
}else{
var keyword = $('#searchend').val().toLowerCase();
$('.endclasscell').each(function(){
var label = $(this).children('.endclassuri').text().toLowerCase();
if(label.indexOf(keyword) != -1){
$(this).parent().removeClass('nohit');
}else{
$(this).parent().addClass('nohit');
}
});
}
setTimeout('scrolldiv()',30);
}