Risolti altri due bug del resize window

This commit is contained in:
Luca Trupiano 2023-03-21 15:20:01 +01:00
parent 20ef7062c0
commit 53fb9ea537
3 changed files with 32 additions and 46 deletions

View File

@ -54,7 +54,7 @@ $(document).ready(function() {
showCanto(formeprima, '1','1')
$("#InfernoCanto_1").attr('style', 'display: d-flex;')
loadedCanti.add("InfernoCanto_1")
drawMinimap("#InfernoCanto_1")
drawMinimap("#InfernoCanto_1", false)
const minim=$(" .minimap__content")
//const end = performance.now();
//console.log(`Load cantiche time: ${end - start} ms`);
@ -253,7 +253,7 @@ $(" ."+formaClass).hover(function(idx, element) {
loadFrasi();
}
addFormaListenersInCanto()
drawMinimap('#vistaFrasi')
drawMinimap('#vistaFrasi', false)
}
@ -465,7 +465,7 @@ $(" ."+formaClass).hover(function(idx, element) {
drawMinimap("#" + $(this).attr('name').replace(" ", "_"))
drawMinimap("#" + $(this).attr('name').replace(" ", "_"), false)
if (selectedVista=='frasi'){
@ -1223,13 +1223,6 @@ function resetFrasi(){
//calcolo numero dei contesti
countResultContexts()
//aggiorna minimap
/*
if (currentMinimap != '') {
showMinimap()
}
*/
});
queryExecuted = true;
$(cantoDisplayed).attr('style', 'display: d-flex;');

View File

@ -8,8 +8,6 @@ const minimapviewerId = '#minimapviewer';
const displayminimapId = '#displayminimap';
const visCantoClass = '.visCanto';
const fillerClass = '.filler';
const cssTableMainHeight = 0.95; //.tableMain {height: 95%;}
const cssCantoHeight = 0.65;
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>'
let minimap = document.createElement('div');
@ -19,21 +17,14 @@ let realScale;
let currentMinimap = '';
let initOffset = '';
let correctionFactor = 1;
let scrollCorrectionFactor = 1.003;
let scrollCorrectionFactor = 0.997;
function drawMinimap(name, onlyContent = false){
function drawMinimap(name, onlyContent = false, cantoOffset = 0){
var cantoHeightToSet = $("body")[0].clientHeight*cssCantoHeight;
var maxCantoHeightToSet = $("body")[0].clientHeight*cssTableMainHeight-110; // 63 padding top + 47 margine bottom
$(visCantoClass).css("max-height", maxCantoHeightToSet);
$(visCantoClass).css("height", cantoHeightToSet);
$(displayCantoId).css("max-height", maxCantoHeightToSet);
$(displayCantoId).css("height", cantoHeightToSet);
//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");
currentMinimap = name;
@ -56,9 +47,8 @@ function drawMinimap(name, onlyContent = false){
showMinimap(onlyContent);
if (onlyContent == false) {
$(displayCantoWrapperId).scrollTop(0);
$(displayCantoWrapperId).scrollTop(cantoOffset);
$(minimapviewerId).offset({ top: initOffset});
var minimapTopPos = $(minimapviewerId).offset().top;
$(minimapviewerId).draggable({
@ -66,12 +56,16 @@ function drawMinimap(name, onlyContent = false){
containment: $(displayminimapId),
scroll: false,
start: function(event, ui) { minimapScrolling = true; },
stop: function(event, ui) { minimapScrolling = false; },
stop: function(event, ui) {
minimapScrolling = false;
latestOffset = $(displayCantoWrapperId).scrollTop()
},
drag: function(event, ui) {
minimapScrolling = true;
$(displayCantoWrapperId).scrollTop((ui.offset.top - minimapTopPos) / (realScale*correctionFactor));
}
});
trackScrollCanto();
};
}
@ -118,8 +112,6 @@ function showMinimap(onlyContent) {
$(".visInfo").css("height", (infoHeightToSet+4)+"px");
getDimensionsDiv(false, onlyContent);
//window.addEventListener('resize', getDimensionsDiv);
}
@ -133,12 +125,10 @@ function showMinimap(onlyContent) {
var resizableWidth = $(visCantoClass)[0].clientWidth;
var resizableHeight = $(visCantoClass)[0].clientHeight;
var resizableRatio = resizableHeight/resizableWidth;
//var widthRatio = resizableWidth/srcCantoWidth;
var heightRatio = resizableHeight/srcCantoHeight;
if (onlyViewer == false) {
realScale= Math.min((maxWidth/miniCantoWidth), (maxHeight/miniCantoHeight), 1);
//realScale= Math.max(realScale, 0.1);
minimapContent.style.transform = `scale(${realScale})`;
minimapContent.style.height = miniCantoHeight + "px";
minimapContent.style.width = maxWidth/realScale + "px";
@ -148,7 +138,6 @@ function showMinimap(onlyContent) {
let viewerWidth = Math.min(viewerHeight/resizableRatio, maxWidth-3)+2; // -3 bordi
var displayminimapHeight = (miniCantoHeight*realScale)+6;
//var displayminimapHeight = Math.min((miniCantoHeight*realScale)+6,maxHeight);
$(displayminimapId).height(displayminimapHeight);
$(fillerClass).height(Math.max(maxHeight-displayminimapHeight)+2, 0);
@ -165,19 +154,10 @@ function showMinimap(onlyContent) {
var minimapHeight = ($(currentMinimap)[0].clientHeight+32)*realScale;
var posDbefore = $(displayCantoWrapperId).scrollTop();
var srcCantoHeight = $(currentMinimap)[0].clientHeight;
//var posAfter = (minimapHeight*posDbefore*correctionFactor)/(srcCantoHeight*1.003);
var posAfter = (minimapHeight*posDbefore*correctionFactor)/(srcCantoHeight*scrollCorrectionFactor);
//var posAfter = (minimapHeight*posDbefore*correctionFactor)/(srcCantoHeight*1.02);
$(minimapviewerId).offset({ top: initOffset + posAfter});
}
latestOffset = posDbefore;
};
function hideMinimap() {
$('.canto').each(function() {
$(this).attr("style", 'display:none');
});
//$(".minimap__container").remove();
currentMinimap = ''
}

View File

@ -7,6 +7,9 @@ var currStyle = "style1";
var currPage = 0;
var latestPhraseId = "";
var numeroPagine = 0;
var latestOffset = 0;
const cssCantoHeight = 0.65;
const cssTableMainHeight = 0.95; //.tableMain {height: 95%;}
$(document).ready(function() {
@ -18,8 +21,8 @@ $(document).ready(function() {
function doneResizing(){
$("#displayminimap").empty();;
$('#displayminimap').css('height', 'auto');
drawMinimap(currentMinimap, false);
}
drawMinimap(currentMinimap, false, latestOffset);
};
$(displayCantoWrapperId).scroll(function() {
if (minimapScrolling) {
@ -61,7 +64,7 @@ $(document).ready(function() {
default:
};
$('#bgImg').replaceWith(bgImgEl);
drawMinimap(currentMinimap);
drawMinimap(currentMinimap, false);
}
});
@ -73,7 +76,7 @@ $(document).ready(function() {
$('#displaycanto').css("font-size", newFontSize);
$('#displaycanto h4').css("font-size", newH4FontSize);
//$('#displaycanto li::marker').css("font-size", newLiFontSize);
drawMinimap(currentMinimap);
drawMinimap(currentMinimap, false);
$('iframe').contents().find('.blog-main').css("font-size", newFontSize);
$('iframe').contents().find('.blog-main h4').css("font-size", newH4FontSize);
});
@ -1391,3 +1394,13 @@ $(document).ready(function() {
};
});
$(window).on('load', function() {
var cantoHeightToSet = $("body")[0].clientHeight*cssCantoHeight;
var maxCantoHeightToSet = $("body")[0].clientHeight*cssTableMainHeight-110; // 63 padding top + 47 margine bottom
$(visCantoClass).css("max-height", maxCantoHeightToSet);
$(visCantoClass).css("height", cantoHeightToSet);
$(displayCantoId).css("max-height", maxCantoHeightToSet);
$(displayCantoId).css("height", cantoHeightToSet);
});