2023-02-06 12:51:34 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-02-09 19:21:04 +01:00
|
|
|
const displayCantoId = '#displaycanto';
|
2023-02-24 19:53:06 +01:00
|
|
|
const displayCantoWrapperId = '#displaycantoWrapper';
|
2023-02-09 19:21:04 +01:00
|
|
|
const minimapviewerId = '#minimapviewer';
|
|
|
|
const displayminimapId = '#displayminimap';
|
|
|
|
const visCantoClass = '.visCanto';
|
2023-03-10 13:04:38 +01:00
|
|
|
const fillerClass = '.filler';
|
|
|
|
const cssTableMainHeight = 0.95; //.tableMain {height: 95%;}
|
|
|
|
const cssCantoHeight = 0.65;
|
2023-03-09 13:27:42 +01:00
|
|
|
const bodyScript = '<script type="module" src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.esm.js"></script> <script nomodule src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.js"></script>'
|
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-03-10 13:04:38 +01:00
|
|
|
let correctionFactor = 1;
|
|
|
|
let scrollCorrectionFactor = 1.003;
|
2023-02-08 18:58:03 +01:00
|
|
|
|
2023-02-06 12:51:34 +01:00
|
|
|
|
|
|
|
function drawMinimap(name){
|
2023-03-10 13:04:38 +01:00
|
|
|
var cantoHeightToSet = $("body")[0].clientHeight*cssCantoHeight;
|
|
|
|
var maxCantoHeightToSet = $("body")[0].clientHeight*cssTableMainHeight-110; // 63 padding top + 47 margine bottom
|
2023-02-24 15:06:20 +01:00
|
|
|
$(visCantoClass).css("max-height", maxCantoHeightToSet);
|
|
|
|
$(visCantoClass).css("height", cantoHeightToSet);
|
|
|
|
$(displayCantoId).css("max-height", maxCantoHeightToSet);
|
|
|
|
$(displayCantoId).css("height", cantoHeightToSet);
|
|
|
|
|
2023-03-10 13:04:38 +01:00
|
|
|
//var infoHeightToSet = $("body")[0].clientHeight*cssTableMainHeight - $(visCantoClass)[0].clientHeight-2-63-2
|
|
|
|
//$("#displayinfo").css("maxHeight", infoHeightToSet+"px");
|
|
|
|
//$("#displayinfo").css("height", infoHeightToSet+"px");
|
|
|
|
//$(".visInfo").css("height", (infoHeightToSet+4)+"px");
|
|
|
|
|
2023-02-24 15:06:20 +01:00
|
|
|
currentMinimap = name;
|
2023-03-10 13:04:38 +01:00
|
|
|
|
|
|
|
if (currentMinimap == '#vistaFrasi') {
|
|
|
|
correctionFactor = 0.967;
|
2023-03-10 14:48:16 +01:00
|
|
|
//scrollCorrectionFactor = 1.02;
|
|
|
|
scrollCorrectionFactor = 1;
|
2023-03-10 13:04:38 +01:00
|
|
|
} else {
|
|
|
|
correctionFactor = 1;
|
|
|
|
scrollCorrectionFactor = 1.003;
|
|
|
|
};
|
|
|
|
|
2023-02-24 15:06:20 +01:00
|
|
|
initOffset = parseInt($("body").css("padding-top").replace("px", ""))+63;
|
2023-03-10 13:04:38 +01:00
|
|
|
|
|
|
|
if ($(displayminimapId).lenght > 0) {
|
|
|
|
$(displayminimapId)[0].remove();
|
|
|
|
}
|
|
|
|
|
2023-02-24 15:06:20 +01:00
|
|
|
showMinimap();
|
2023-03-10 13:04:38 +01:00
|
|
|
|
2023-03-09 13:27:42 +01:00
|
|
|
$(displayCantoWrapperId).scrollTop(0);
|
2023-02-24 15:06:20 +01:00
|
|
|
$(minimapviewerId).offset({ top: initOffset});
|
2023-03-10 13:04:38 +01:00
|
|
|
|
2023-02-24 15:06:20 +01:00
|
|
|
var minimapTopPos = $(minimapviewerId).offset().top;
|
|
|
|
|
|
|
|
$(minimapviewerId).draggable({
|
|
|
|
axis: "y",
|
|
|
|
containment: $(displayminimapId),
|
|
|
|
scroll: false,
|
|
|
|
start: function(event, ui) { minimapScrolling = true; },
|
|
|
|
stop: function(event, ui) { minimapScrolling = false; },
|
|
|
|
drag: function(event, ui) {
|
|
|
|
minimapScrolling = true;
|
2023-03-10 13:04:38 +01:00
|
|
|
$(displayCantoWrapperId).scrollTop((ui.offset.top - minimapTopPos) / (realScale*correctionFactor));
|
2023-02-24 15:06:20 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
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;
|
2023-02-17 13:35:01 +01:00
|
|
|
|
2023-02-06 12:51:34 +01:00
|
|
|
var cssLinkb = document.createElement("link");
|
2023-02-17 13:35:01 +01:00
|
|
|
cssLinkb.href = $("#" + currStyle + "-Boot")[0].href;
|
2023-02-06 12:51:34 +01:00
|
|
|
cssLinkb.rel = "stylesheet";
|
|
|
|
cssLinkb.type = "text/css";
|
|
|
|
|
|
|
|
var cssLinkscroll = document.createElement("link");
|
2023-02-17 13:35:01 +01:00
|
|
|
cssLinkscroll.href = $("#" + currStyle + "-Custom")[0].href;
|
2023-02-06 12:51:34 +01:00
|
|
|
cssLinkscroll.rel = "stylesheet";
|
|
|
|
cssLinkscroll.type = "text/css";
|
|
|
|
|
|
|
|
iFrameDoc.open();
|
2023-02-20 13:55:06 +01:00
|
|
|
iFrameDoc.write('<div class="blog-main w-100 " style="display: d-flex;">'); // 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-03-09 13:27:42 +01:00
|
|
|
iFrameDoc.write(bodyScript);
|
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-23 20:04:59 +01:00
|
|
|
let bgCanto = $(visCantoClass).css('background-color');
|
2023-03-10 14:48:16 +01:00
|
|
|
console.log(bgCanto);
|
2023-02-17 13:35:01 +01:00
|
|
|
$('iframe').contents().find('body').css('background-color', bgCanto + ' !important;');
|
2023-02-06 12:51:34 +01:00
|
|
|
|
2023-03-10 13:04:38 +01:00
|
|
|
var infoHeightToSet = $("body")[0].clientHeight*cssTableMainHeight - $(visCantoClass)[0].clientHeight-2-63-2
|
2023-02-24 15:06:20 +01:00
|
|
|
$("#displayinfo").css("maxHeight", infoHeightToSet+"px");
|
|
|
|
$("#displayinfo").css("height", infoHeightToSet+"px");
|
|
|
|
$(".visInfo").css("height", (infoHeightToSet+4)+"px");
|
2023-02-06 12:51:34 +01:00
|
|
|
|
2023-02-24 15:06:20 +01:00
|
|
|
getDimensionsDiv();
|
2023-02-23 20:04:59 +01:00
|
|
|
|
2023-02-24 19:53:06 +01:00
|
|
|
//window.addEventListener('resize', getDimensionsDiv);
|
2023-02-06 12:51:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-22 18:36:28 +01:00
|
|
|
function getDimensionsDiv(onlyViewer = false) {
|
|
|
|
var srcCantoWidth = $(currentMinimap)[0].clientWidth;
|
2023-02-09 19:21:04 +01:00
|
|
|
var srcCantoHeight = $(currentMinimap)[0].clientHeight;
|
2023-02-24 15:06:20 +01:00
|
|
|
var maxHeight = ($("#colMinimap")[0].clientHeight)-68; //h attuale dello spazio minimap; -63 top padding, -1 bordo col, -4 bordi iframe
|
2023-02-20 13:55:06 +01:00
|
|
|
var maxWidth = $(displayminimapId)[0].clientWidth; //w attuale della minimap (css)
|
2023-03-10 13:04:38 +01:00
|
|
|
var miniCantoWidth = srcCantoWidth+64; //w prevista del canto nella minimap 64: padding pr + blank space
|
|
|
|
var miniCantoHeight = srcCantoHeight*correctionFactor; //h prevista del canto nella minimap
|
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;
|
2023-03-10 13:04:38 +01:00
|
|
|
//var widthRatio = resizableWidth/srcCantoWidth;
|
2023-02-15 12:59:50 +01:00
|
|
|
var heightRatio = resizableHeight/srcCantoHeight;
|
2023-02-08 18:58:03 +01:00
|
|
|
|
2023-02-22 18:36:28 +01:00
|
|
|
if (onlyViewer == false) {
|
2023-02-23 20:04:59 +01:00
|
|
|
realScale= Math.min((maxWidth/miniCantoWidth), (maxHeight/miniCantoHeight), 1);
|
2023-02-22 18:36:28 +01:00
|
|
|
minimapContent.style.transform = `scale(${realScale})`;
|
|
|
|
minimapContent.style.height = miniCantoHeight + "px";
|
|
|
|
minimapContent.style.width = maxWidth/realScale + "px";
|
|
|
|
}
|
|
|
|
|
2023-03-10 13:04:38 +01:00
|
|
|
let viewerHeight = (miniCantoHeight*realScale*heightRatio/correctionFactor)-2; // -2 = bordi
|
2023-02-22 18:36:28 +01:00
|
|
|
let viewerWidth = Math.min(viewerHeight/resizableRatio, maxWidth-2); // -2 bordi
|
|
|
|
|
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
|
|
|
|
2023-03-10 13:04:38 +01:00
|
|
|
var displayminimapHeight = (miniCantoHeight*realScale)+6;
|
|
|
|
|
|
|
|
$(displayminimapId).height(displayminimapHeight);
|
|
|
|
$(fillerClass).height(Math.max(maxHeight-displayminimapHeight)+2, 0);
|
2023-02-23 20:04:59 +01:00
|
|
|
|
2023-02-08 18:58:03 +01:00
|
|
|
trackScrollCanto();
|
|
|
|
};
|
|
|
|
|
2023-02-06 12:51:34 +01:00
|
|
|
|
|
|
|
function trackScrollCanto() {
|
2023-02-22 18:36:28 +01:00
|
|
|
var minimapHeight = ($(currentMinimap)[0].clientHeight+32)*realScale;
|
2023-02-24 19:53:06 +01:00
|
|
|
var posDbefore = $(displayCantoWrapperId).scrollTop();
|
2023-02-09 19:21:04 +01:00
|
|
|
var srcCantoHeight = $(currentMinimap)[0].clientHeight;
|
2023-03-10 13:04:38 +01:00
|
|
|
//var posAfter = (minimapHeight*posDbefore*correctionFactor)/(srcCantoHeight*1.003);
|
|
|
|
var posAfter = (minimapHeight*posDbefore*correctionFactor)/(srcCantoHeight*scrollCorrectionFactor);
|
|
|
|
//var posAfter = (minimapHeight*posDbefore*correctionFactor)/(srcCantoHeight*1.02);
|
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');
|
|
|
|
});
|
2023-02-23 20:04:59 +01:00
|
|
|
//$(".minimap__container").remove();
|
2023-02-06 12:51:34 +01:00
|
|
|
currentMinimap = ''
|
|
|
|
}
|
|
|
|
|
|
|
|
|