From 53fb9ea537a2ce034fbb0d459d1f6e9ff35f4fcf Mon Sep 17 00:00:00 2001 From: Luca Trupiano Date: Tue, 21 Mar 2023 15:20:01 +0100 Subject: [PATCH] Risolti altri due bug del resize window --- js/cesareBrowse.js | 13 +++---------- js/minimap.js | 44 ++++++++++++-------------------------------- js/script_4.2.js | 21 +++++++++++++++++---- 3 files changed, 32 insertions(+), 46 deletions(-) diff --git a/js/cesareBrowse.js b/js/cesareBrowse.js index 642bceb..b574d68 100644 --- a/js/cesareBrowse.js +++ b/js/cesareBrowse.js @@ -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;'); diff --git a/js/minimap.js b/js/minimap.js index c4e784d..cd2ac71 100644 --- a/js/minimap.js +++ b/js/minimap.js @@ -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 = ' ' 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; @@ -48,7 +39,7 @@ function drawMinimap(name, onlyContent = false){ }; initOffset = parseInt($("body").css("padding-top").replace("px", ""))+63; - + if ($(displayminimapId).lenght > 0) { $(displayminimapId)[0].remove(); } @@ -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}); - } - - - function hideMinimap() { - $('.canto').each(function() { - $(this).attr("style", 'display:none'); - }); - //$(".minimap__container").remove(); - currentMinimap = '' - } + latestOffset = posDbefore; + }; + diff --git a/js/script_4.2.js b/js/script_4.2.js index 829b15a..2e59127 100644 --- a/js/script_4.2.js +++ b/js/script_4.2.js @@ -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); + +}); +