LiDa_Search/js/cesareBrowse.js

279 lines
7.3 KiB
JavaScript
Raw Normal View History

2022-11-06 17:12:56 +01:00
/**
*
*/
2022-11-08 10:44:20 +01:00
$(document).ready(function() {
2022-11-06 17:12:56 +01:00
const sparqlGenerator = sparqljs.Generator;
const myEngine = new Comunica.QueryEngine();
const sparqlEndpoint = "https://hdnlab1.isti.cnr.it/fuseki/commediaontosintgra/query";
2022-11-08 10:44:20 +01:00
var primaCanticaLoaded = false;
var secondaCanticaLoaded = false;
var terzaCanticaLoaded = false;
2022-11-06 17:12:56 +01:00
var listaVersi = new Set()
2022-11-08 10:44:20 +01:00
2022-11-07 11:52:54 +01:00
//caricamento prima cantica
2022-11-06 17:12:56 +01:00
$('#cantica1').on('click', function() {
2022-11-07 11:52:54 +01:00
$('.canto').each(function() {
2022-11-08 10:44:20 +01:00
$(this).attr("style", 'display:none');
2022-11-07 11:52:54 +01:00
});
hideListaCanti()
2022-11-08 10:44:20 +01:00
activateMenuItem('#cantica1')
if (!(primaCanticaLoaded)) {
2022-11-07 11:52:54 +01:00
jsonQuery = versiCantica("Inferno");
execQuery = new sparqlGenerator().stringify(jsonQuery);
2022-11-08 10:44:20 +01:00
executeQueryVersi(execQuery);
primaCanticaLoaded = true;
}
else {
$("#InfernoCanto_1").attr('style', 'display:block')
$("#CantiInferno").attr('style', 'display:block')
2022-11-07 11:52:54 +01:00
}
2022-11-08 10:44:20 +01:00
2022-11-07 11:52:54 +01:00
});
2022-11-08 10:44:20 +01:00
2022-11-07 11:52:54 +01:00
//caricamento seconda cantica
$('#cantica2').on('click', function() {
$('.canto').each(function() {
2022-11-08 10:44:20 +01:00
$(this).attr("style", 'display:none');
2022-11-07 11:52:54 +01:00
});
hideListaCanti()
2022-11-08 10:44:20 +01:00
activateMenuItem('#cantica2')
if (!(secondaCanticaLoaded)) {
2022-11-07 11:52:54 +01:00
jsonQuery = versiCantica("Purgatorio");
execQuery = new sparqlGenerator().stringify(jsonQuery);
2022-11-08 10:44:20 +01:00
executeQueryVersi(execQuery);
secondaCanticaLoaded = true;
2022-11-07 11:52:54 +01:00
}
2022-11-08 10:44:20 +01:00
else {
$("#PurgatorioCanto_1").attr('style', 'display:block')
$("#CantiPurgatorio").attr('style', 'display:block')
}
2022-11-07 11:52:54 +01:00
});
2022-11-08 10:44:20 +01:00
2022-11-07 11:52:54 +01:00
//caricamento terza cantica
$('#cantica3').on('click', function() {
$('.canto').each(function() {
2022-11-08 10:44:20 +01:00
$(this).attr("style", 'display:none');
2022-11-07 11:52:54 +01:00
});
hideListaCanti()
2022-11-08 10:44:20 +01:00
activateMenuItem('#cantica3')
if (!(terzaCanticaLoaded)) {
2022-11-07 11:52:54 +01:00
jsonQuery = versiCantica("Paradiso");
execQuery = new sparqlGenerator().stringify(jsonQuery);
2022-11-08 10:44:20 +01:00
executeQueryVersi(execQuery);
terzaCanticaLoaded = true;
2022-11-07 11:52:54 +01:00
}
2022-11-08 10:44:20 +01:00
else {
$("#ParadisoCanto_1").attr('style', 'display:block')
$("#CantiParadiso").attr('style', 'display:block')
}
2022-11-06 17:12:56 +01:00
});
2022-11-08 10:44:20 +01:00
2022-11-06 17:12:56 +01:00
jQuery(document).delegate('.navig-canto', 'click', function(e) {
$('.canto').each(function() {
2022-11-08 10:44:20 +01:00
$(this).attr("style", 'display:none');
2022-11-06 17:12:56 +01:00
});
2022-11-08 10:44:20 +01:00
$("#" + $(this).attr('name').replace(" ", "_")).attr('style', 'display:block')
showMinimap($(this).attr('name').replace(" ", "_"))
2022-11-06 17:12:56 +01:00
});
2022-11-08 10:44:20 +01:00
2022-11-06 17:12:56 +01:00
//Utility functions
2022-11-08 10:44:20 +01:00
2022-11-06 17:12:56 +01:00
//activate navigation menu items
2022-11-08 10:44:20 +01:00
function activateMenuItem(menuItem) {
2022-11-06 17:12:56 +01:00
$('.blog-nav-item').each(function() {
2022-11-08 10:44:20 +01:00
$(this).attr("class", $(this).attr("class").replace(' active', ''));
2022-11-06 17:12:56 +01:00
});
2022-11-08 10:44:20 +01:00
$(menuItem).attr("class", $(menuItem).attr("class") + ' active');
2022-11-06 17:12:56 +01:00
}
2022-11-08 10:44:20 +01:00
2022-11-07 11:52:54 +01:00
//hides liste canti
2022-11-08 10:44:20 +01:00
function hideListaCanti() {
$("#CantiInferno").attr('style', 'display:none')
$("#CantiPurgatorio").attr('style', 'display:none')
$("#CantiParadiso").attr('style', 'display:none')
}
2022-11-08 12:25:59 +01:00
// utils
function managePunctuation(stringa) {
var tempstringa=stringa.replaceAll(" ,", ",")
tempstringa=tempstringa.replaceAll(" .", ".")
tempstringa=tempstringa.replaceAll(" :", ":")
tempstringa=tempstringa.replaceAll(" !", "!")
tempstringa=tempstringa.replaceAll(" ?", "?")
tempstringa=tempstringa.replaceAll(" ;", ";")
return tempstringa
}
2022-11-08 10:44:20 +01:00
//minimap management
let minimap = document.createElement('div');
let minimapSize = document.createElement('div');
let viewer = document.createElement('div');
let minimapContent = document.createElement('iframe');
let scale=0.1;
let realScale;
function showMinimap(element) {
minimap.className = 'minimap_container'
minimapSize.className = 'minimap_size'
viewer.className = 'minimap_viewer'
minimapContent.className = 'minimap_content'
minimap.append(minimapSize, viewer, minimapContent);
document.body.appendChild(minimap)
let html = document.getElementById(element).innerHTML
console.log(html)
let iFrameDoc = minimapContent.contentWindow.document;
iFrameDoc.open();
iFrameDoc.write(html);
iFrameDoc.close();
getDimensions()
window.addEventListener('scroll', trackScroll)
window.addEventListener('resize', getDimensions)
}
2022-11-07 11:52:54 +01:00
2022-11-08 10:44:20 +01:00
function getDimensions(){
let bodyWidth = document.body.clientWidth;
let bodyRatio = document.body.clientHeight / bodyWidth;
let winRatio = window.innerHeight / window.innerWidth;
minimap.style.width = '10%';
realScale = minimap.clientWidth / (bodyWidth);
minimapSize.style.paddingTop = `${bodyRatio * 100}%`
viewer.style.paddingTop = `${winRatio * 100}%`;
minimapContent.style.transform = `scale(${realScale})`;
minimapContent.style.width = `${(100 / realScale)}%`
minimapContent.style.height = `${(100 / realScale)}%`
}
function trackScroll(){
viewer.style.transform=`translateY(${window.scrollY * realScale}px)`
2022-11-07 11:52:54 +01:00
}
2022-11-08 10:44:20 +01:00
//end minimap management
async function executeQueryVersi(query) {
bindingsStream = await myEngine.queryBindings(query, { sources: [{ type: 'sparql', value: sparqlEndpoint },], });
2022-11-06 17:12:56 +01:00
alert(query)
try {
var listaCanti = new Set()
listaVersi = new Set()
2022-11-08 10:44:20 +01:00
let cantica = 0;
2022-11-06 17:12:56 +01:00
bindingsStream.on('data', (binding) => {
2022-11-07 11:52:54 +01:00
//cantica
2022-11-08 10:44:20 +01:00
cantica = binding.get('Cantica').value;
2022-11-06 17:12:56 +01:00
//la lista dei canti
2022-11-08 10:44:20 +01:00
listaCanti.add(binding.get('Canto').value)
2022-11-06 17:12:56 +01:00
//la lista dei versi
var obj = new Object();
obj.numverso = binding.get('NumeroVerso').value;
obj.verso = binding.get('Verso').value;
obj.canto = binding.get('Canto').value;
obj.from = binding.get('from').value;
obj.to = binding.get('to').value;
listaVersi.add(obj)
2022-11-08 10:44:20 +01:00
2022-11-06 17:12:56 +01:00
});
bindingsStream.on('end', () => {
2022-11-08 10:44:20 +01:00
2022-11-06 17:12:56 +01:00
var orderedListaCanti = Array.from(listaCanti)
orderedListaCanti = orderedListaCanti.sort((a, b) => {
2022-11-08 10:44:20 +01:00
if (parseInt(a.split(" ")[1]) < parseInt(b.split(" ")[1])) {
return -1;
}
2022-11-06 17:12:56 +01:00
});
2022-11-08 10:44:20 +01:00
2022-11-06 17:12:56 +01:00
var orderedListaVersi = Array.from(listaVersi)
orderedListaVersi = orderedListaVersi.sort((a, b) => {
2022-11-08 10:44:20 +01:00
if (parseInt(a.numverso) < parseInt(b.numverso)) {
return -1;
}
2022-11-06 17:12:56 +01:00
});
2022-11-08 10:44:20 +01:00
var divListaCanti = $('<DIV id="Canti' + cantica + '" />')
for (canto of orderedListaCanti) {
2022-11-06 17:12:56 +01:00
var licanto = $('<li class="navig-canto"/>')
2022-11-08 10:44:20 +01:00
licanto.attr('name', cantica + canto)
2022-11-06 17:12:56 +01:00
licanto.attr('href', "#")
2022-11-07 11:52:54 +01:00
licanto.attr("style", "line-height: 1.2em")
2022-11-06 17:12:56 +01:00
licanto.append(canto)
2022-11-08 10:44:20 +01:00
2022-11-07 11:52:54 +01:00
//licanto.appendTo('#listacanti')
licanto.appendTo(divListaCanti)
2022-11-08 10:44:20 +01:00
var divcanto = $('<div />')
var titolocanto = $('<h1 class="titolo-canto" />')
2022-11-06 17:12:56 +01:00
titolocanto.append(canto)
divcanto.attr('class', 'canto')
divcanto.attr('style', 'display:none')
2022-11-08 10:44:20 +01:00
divcanto.attr('id', (cantica + canto).replace(" ", "_"))
2022-11-06 17:12:56 +01:00
titolocanto.appendTo(divcanto)
divcanto.appendTo(' .blog-main')
}
2022-11-07 11:52:54 +01:00
divListaCanti.appendTo('#listacanti')
2022-11-08 10:44:20 +01:00
for (verso of orderedListaVersi) {
2022-11-08 12:25:59 +01:00
2022-11-08 10:44:20 +01:00
var elementoverso = $('<p />')
2022-11-08 12:25:59 +01:00
elementoverso.append(verso.numverso + ". " + managePunctuation(verso.verso))
2022-11-06 17:12:56 +01:00
elementoverso.attr("style", "line-height: 0.5em")
2022-11-08 10:44:20 +01:00
elementoverso.appendTo('#' + cantica + verso.canto.replace(" ", "_"))
2022-11-08 12:25:59 +01:00
2022-11-06 17:12:56 +01:00
}
2022-11-08 10:44:20 +01:00
2022-11-06 17:12:56 +01:00
});
}
2022-11-08 10:44:20 +01:00
catch (err) {
console.log(err.message);
$("#loader").hide();
2022-11-06 17:12:56 +01:00
};
};
2022-11-08 10:44:20 +01:00
// scroll function
/*
$(window).scroll(function(e){
var $el = $('.blog-masthead');
var isPositionFixed = ($el.css('position') == 'fixed');
if ($(this).scrollTop() > 10 && !isPositionFixed){
$el.css({'position': 'fixed', 'top': '0px'});
}
if ($(this).scrollTop() < 10 && isPositionFixed){
$el.css({'position': 'static', 'top': '0px'});
}
});
*/
2022-11-06 17:12:56 +01:00
});