var monocle_host = global_site_host;
var taxonomy;
var sub_taxonomy = '';
$(document).ready(function () {
var isTouchSupported = 'ontouchstart' in window;
var isTouchEnd = 'touchend' in window;
var clickEvent = isTouchSupported && isTouchEnd ? 'touchend' : 'mouseup';
var mouseOutEvent = isTouchSupported && isTouchEnd ? '' : 'mouseout';
var mouseMoveEvent = isTouchSupported && isTouchEnd ? '' : 'mousemove';
var mouseOverEvent = isTouchSupported && isTouchEnd ? '' : 'mouseover';
getTaxonomy(getTaxonomyId());
////console.log(taxonomy);
});
function getTaxonomyId()
{
var tax_id = location.pathname.match(/\/taxonomy\/(.*)/)[1];
var pathArray = window.location.pathname.split( '/' );
tax_id = pathArray[2];
return tax_id;
}
function getTaxonomy(id){
z_url = "/get_taxonomy?id=" + id;
$.ajax({
url: z_url,
method: 'GET',
headers: {
Accept: 'application/json'
},
success: function (result) {
//result = JSON.parse(result);
taxonomy = result;
document.title = document.title + " - " + taxonomy.name;
$("#title").html(taxonomy.name);
if(taxonomy.taxonomies.length > 0)
{
sub_taxonomy = '';
getSubTaxonomy(taxonomy.taxonomies);
} else {
sub_taxonomy = '';
}
$("#content").html("
" + taxonomy.long_description + "
" + sub_taxonomy);
$.when(getItemsByTaxonomy(taxonomy.id)).done(function( items){
//console.log("Items by Taxonomy");
tax_items = items; // JSON.parse(items);
//console.log(tax_items);
ds_item = '';
if(tax_items.datasets.length > 0){
ds_item += 'Datasets
';
$.each(tax_items.datasets, function(i, dataset){
//console.log(dataset);
ds_item += '
' + dataset.title + '';
});
ds_item += '
';
}
if(tax_items.pages.length > 0){
ds_item += 'Pages
';
$.each(tax_items.pages, function(i, page){
//console.log(page);
ds_item += '
' + page.title + '';
});
ds_item += '
';
}
$("#tax_items").append(ds_item); //.addClass('well').addClass('bg-info');
});
return result;
}
});
}
function getSubTaxonomy(taxonomies){
console.log(taxonomies);
if(typeof taxonomies != 'undefined' && taxonomies.length > 0)
{
sub_taxonomy += "";
$.each(taxonomies, function (i, sub_tax) {
if(sub_tax.is_hidden){
//console.log("Hidden taxonomy!");
}
else {
sub_taxonomy += "- " + sub_tax.name + "
";
getSubTaxonomy(sub_tax.taxonomies);
}
});
sub_taxonomy += "
";
}
else {
return false;
}
}
function getItemsByTaxonomy(tax_id){
z_url = "/get_taxonomy_items?tax_id=" + tax_id;
return $.post(z_url).pipe(function(p){
return p;
});
}
function hasWhiteSpace(s) {
return /\s/g.test(s);
}