2023-02-06 12:51:34 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-02-09 19:21:04 +01:00
|
|
|
const displayCantoId = '#displaycanto';
|
|
|
|
const minimapviewerId = '#minimapviewer';
|
|
|
|
const displayminimapId = '#displayminimap';
|
|
|
|
const visCantoClass = '.visCanto';
|
2023-02-06 12:51:34 +01:00
|
|
|
|
|
|
|
let minimap = document.createElement('div');
|
|
|
|
let viewer = document.createElement('div');
|
|
|
|
let minimapContent = document.createElement('iframe');
|
|
|
|
let realScale;
|
2023-02-09 19:21:04 +01:00
|
|
|
let currentMinimap = '';
|
|
|
|
let initOffset = '';
|
2023-02-08 18:58:03 +01:00
|
|
|
|
2023-02-06 12:51:34 +01:00
|
|
|
|
|
|
|
function drawMinimap(name){
|
|
|
|
currentMinimap = name;
|
2023-02-09 19:21:04 +01:00
|
|
|
initOffset = parseInt($("body").css("padding-top").replace("px", ""));
|
|
|
|
showMinimap();
|
2023-02-08 18:58:03 +01:00
|
|
|
$(displayCantoId).scrollTop(0);
|
2023-02-09 19:21:04 +01:00
|
|
|
$(minimapviewerId).offset({ top: initOffset});
|
|
|
|
var minimapTopPos = $(minimapviewerId).offset().top;
|
2023-02-08 18:58:03 +01:00
|
|
|
|
|
|
|
$(minimapviewerId).draggable({
|
2023-02-06 12:51:34 +01:00
|
|
|
axis: "y",
|
2023-02-08 18:58:03 +01:00
|
|
|
containment: $(displayminimapId),
|
2023-02-06 12:51:34 +01:00
|
|
|
scroll: false,
|
|
|
|
start: function(event, ui) { minimapScrolling = true; },
|
|
|
|
stop: function(event, ui) { minimapScrolling = false; },
|
|
|
|
drag: function(event, ui) {
|
|
|
|
minimapScrolling = true;
|
2023-02-08 18:58:03 +01:00
|
|
|
$(displayCantoId).scrollTop((ui.offset.top - minimapTopPos) * (1 / (realScale*1.014)));
|
2023-02-06 12:51:34 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-09 19:21:04 +01:00
|
|
|
function showMinimap() {
|
|
|
|
|
|
|
|
viewer.className = 'minimap__viewer';
|
|
|
|
viewer.id = 'minimapviewer';
|
|
|
|
minimapContent.className = 'minimap__content';
|
2023-02-08 18:58:03 +01:00
|
|
|
minimap.append(viewer, minimapContent);
|
2023-02-09 19:21:04 +01:00
|
|
|
$(displayminimapId).append(minimap);
|
2023-02-06 12:51:34 +01:00
|
|
|
|
2023-02-09 19:21:04 +01:00
|
|
|
let html = $(currentMinimap)[0].outerHTML;
|
2023-02-06 12:51:34 +01:00
|
|
|
if (html == null | html == '')
|
|
|
|
return;
|
|
|
|
|
|
|
|
let iFrameDoc = minimapContent.contentWindow.document;
|
|
|
|
|
|
|
|
var cssLinkb = document.createElement("link");
|
|
|
|
cssLinkb.href = "https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css";
|
|
|
|
cssLinkb.rel = "stylesheet";
|
|
|
|
cssLinkb.type = "text/css";
|
|
|
|
|
|
|
|
var cssLinkscroll = document.createElement("link");
|
|
|
|
cssLinkscroll.href = "./css/browsingldc.css";
|
|
|
|
cssLinkscroll.rel = "stylesheet";
|
|
|
|
cssLinkscroll.type = "text/css";
|
|
|
|
|
|
|
|
iFrameDoc.open();
|
2023-02-08 18:58:03 +01:00
|
|
|
iFrameDoc.write('<div class="w-100 py-3 pl-3" style="display: d-flex; overflow-y: scroll;">'); // da pulire...
|
2023-02-06 12:51:34 +01:00
|
|
|
iFrameDoc.write(html);
|
2023-02-08 18:58:03 +01:00
|
|
|
iFrameDoc.write('</div>');
|
2023-02-06 12:51:34 +01:00
|
|
|
iFrameDoc.close();
|
|
|
|
|
|
|
|
iFrameDoc.head.appendChild(cssLinkb);
|
|
|
|
iFrameDoc.head.appendChild(cssLinkscroll);
|
2023-02-08 18:58:03 +01:00
|
|
|
|
2023-02-15 12:59:50 +01:00
|
|
|
let bgCanto = $(".visCanto").css('background-color');
|
|
|
|
$('iframe').contents().find('body').css('backgroundColor', bgCanto + ';');
|
2023-02-06 12:51:34 +01:00
|
|
|
|
2023-02-08 18:58:03 +01:00
|
|
|
getDimensionsDiv();
|
2023-02-06 12:51:34 +01:00
|
|
|
|
2023-02-09 19:21:04 +01:00
|
|
|
window.addEventListener('resize', getDimensionsDiv);
|
2023-02-06 12:51:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getDimensionsDiv() {
|
2023-02-09 19:21:04 +01:00
|
|
|
var srcCantoHeight = $(currentMinimap)[0].clientHeight;
|
|
|
|
var maxHeight = ($(displayminimapId)[0].clientHeight)-4; //h attuale dello spazio minimap -4 padding
|
|
|
|
var maxWidth = $(displayminimapId)[0].clientWidth; //w attuale della minimap (css) -2 bordi
|
|
|
|
var miniCantoHeight = Math.ceil(((srcCantoHeight-44)/25*26)+44+32); //h prevista del canto nella minimap
|
2023-02-06 12:51:34 +01:00
|
|
|
|
2023-02-09 19:21:04 +01:00
|
|
|
var resizableWidth = $(visCantoClass)[0].clientWidth;
|
|
|
|
var resizableHeight = $(visCantoClass)[0].clientHeight;
|
2023-02-15 12:59:50 +01:00
|
|
|
var resizableRatio = resizableHeight/resizableWidth;
|
|
|
|
var heightRatio = resizableHeight/srcCantoHeight;
|
2023-02-08 18:58:03 +01:00
|
|
|
|
2023-02-15 12:59:50 +01:00
|
|
|
let viewerHeight = (maxHeight*heightRatio)-2; // -2 = bordi
|
2023-02-09 19:21:04 +01:00
|
|
|
let viewerWidth = Math.min(viewerHeight/resizableRatio, maxWidth-2);
|
2023-02-08 18:58:03 +01:00
|
|
|
|
2023-02-09 19:21:04 +01:00
|
|
|
realScale = (maxHeight/miniCantoHeight);
|
2023-02-08 18:58:03 +01:00
|
|
|
|
|
|
|
minimap.style.width = '100%';
|
2023-02-06 12:51:34 +01:00
|
|
|
|
|
|
|
minimapContent.style.transform = `scale(${realScale})`;
|
2023-02-09 19:21:04 +01:00
|
|
|
minimapContent.style.height = Math.trunc(miniCantoHeight+25) + "px";
|
2023-02-08 18:58:03 +01:00
|
|
|
minimapContent.style.width = Math.trunc(maxWidth/realScale) + "px";
|
|
|
|
|
2023-02-09 19:21:04 +01:00
|
|
|
viewer.style.height = viewerHeight + "px";
|
|
|
|
viewer.style.width = viewerWidth + "px";
|
2023-02-08 18:58:03 +01:00
|
|
|
|
|
|
|
trackScrollCanto();
|
|
|
|
};
|
|
|
|
|
2023-02-06 12:51:34 +01:00
|
|
|
|
|
|
|
getDimDiv = function(){
|
|
|
|
getDimensionsDiv();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function trackScrollCanto() {
|
2023-02-08 18:58:03 +01:00
|
|
|
var minimapHeight = $(displayminimapId)[0].clientHeight;
|
|
|
|
var posDbefore = $(displayCantoId).scrollTop();
|
2023-02-09 19:21:04 +01:00
|
|
|
var srcCantoHeight = $(currentMinimap)[0].clientHeight;
|
|
|
|
var posAfter = (minimapHeight*posDbefore)/(srcCantoHeight*1.014);
|
2023-02-08 18:58:03 +01:00
|
|
|
$(minimapviewerId).offset({ top: initOffset + posAfter});
|
2023-02-06 12:51:34 +01:00
|
|
|
}
|
2023-02-08 18:58:03 +01:00
|
|
|
|
2023-02-06 12:51:34 +01:00
|
|
|
|
|
|
|
function hideMinimap() {
|
|
|
|
$('.canto').each(function() {
|
|
|
|
$(this).attr("style", 'display:none');
|
|
|
|
});
|
|
|
|
$(".minimap__container").remove();
|
|
|
|
currentMinimap = ''
|
|
|
|
}
|
|
|
|
|
|
|
|
|