From affca037e2d665d0f1b0aae988cd81f75085a053 Mon Sep 17 00:00:00 2001 From: D3V-D <98626679+D3V-D@users.noreply.github.com> Date: Mon, 6 May 2024 03:31:48 -0400 Subject: [PATCH] Move returnToCurrentPage function to uiUtil.js #1248 (#1249) Signed off by @D3V-D. --- www/js/app.js | 12 +----------- www/js/lib/uiUtil.js | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index 007c4267b..4c9c011e2 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1659,7 +1659,7 @@ function handleGlobalDragleave (e) { globalDropZone.classList.remove('dragging-over'); // Only return to page if a ZIM is actually loaded if (selectedArchive.isReady()) { - returnToCurrentPage(); + uiUtil.returnToCurrentPage(); } } } @@ -1700,16 +1700,6 @@ function hasType (typesList, type) { return false; } -// Function to switch back to currently loaded page from config page after dragleave event -function returnToCurrentPage () { - document.getElementById('liConfigureNav').classList.remove('active'); - document.getElementById('liHomeNav').classList.add('active'); - uiUtil.tabTransitionToSection('home', params.showUIAnimations); - const welcomeText = document.getElementById('welcomeText'); - welcomeText.style.display = 'none'; - viewArticle.style.display = 'none'; -} - async function handleFileDrop (packet) { packet.stopPropagation(); packet.preventDefault(); diff --git a/www/js/lib/uiUtil.js b/www/js/lib/uiUtil.js index d573fdff5..89a8a5910 100644 --- a/www/js/lib/uiUtil.js +++ b/www/js/lib/uiUtil.js @@ -926,15 +926,17 @@ function applyAppTheme (theme) { function showReturnLink () { var viewArticle = document.getElementById('viewArticle'); viewArticle.style.display = 'block'; - viewArticle.addEventListener('click', function (e) { - e.preventDefault(); - document.getElementById('liConfigureNav').classList.remove('active'); - document.getElementById('liHomeNav').classList.add('active'); - tabTransitionToSection('home', params.showUIAnimations); - const welcomeText = document.getElementById('welcomeText'); - welcomeText.style.display = 'none'; - viewArticle.style.display = 'none'; - }); + viewArticle.addEventListener('click', returnToCurrentPage); +} + +// Function to switch back to currently loaded page +function returnToCurrentPage () { + document.getElementById('liConfigureNav').classList.remove('active'); + document.getElementById('liHomeNav').classList.add('active'); + tabTransitionToSection('home', params.showUIAnimations); + const welcomeText = document.getElementById('welcomeText'); + welcomeText.style.display = 'none'; + viewArticle.style.display = 'none'; } // Reports an error in loading one of the ASM or WASM machines to the UI API Status Panel @@ -1077,5 +1079,6 @@ export default { reportSearchProviderToAPIStatusPanel: reportSearchProviderToAPIStatusPanel, warnAndOpenExternalLinkInNewTab: warnAndOpenExternalLinkInNewTab, closestAnchorEnclosingElement: closestAnchorEnclosingElement, - getBrowserLanguage: getBrowserLanguage + getBrowserLanguage: getBrowserLanguage, + returnToCurrentPage: returnToCurrentPage };