From c91e7ce377c948bd32d8f8183e6361d4d8051eeb Mon Sep 17 00:00:00 2001 From: James Yu Date: Mon, 14 Oct 2024 16:54:15 +0800 Subject: [PATCH 1/3] Viewer container does not move --- viewer/components/gui.ts | 10 +++++----- viewer/latexworkshop.css | 4 ---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/viewer/components/gui.ts b/viewer/components/gui.ts index f9b6ed9db..a5d7cd3ce 100644 --- a/viewer/components/gui.ts +++ b/viewer/components/gui.ts @@ -18,6 +18,11 @@ export async function patchViewerUI() { const params = await utils.getParams() + if (params.toolbar === 0) { + const containerDom = document.getElementById('viewerContainer')! + containerDom.style.top = '32px' + } + document.getElementById('outerContainer')!.onmousemove = (e) => { if (params.toolbar === 0) { return @@ -36,8 +41,6 @@ export async function patchViewerUI() { hideToolbar = setTimeout(() => { const toolbarDom = document.getElementsByClassName('toolbar')[0] toolbarDom.classList.add('hide') - const containerDom = document.getElementById('viewerContainer')! - containerDom.classList.add('topped') hideToolbar = undefined }, params.toolbar * 1000) } @@ -48,7 +51,6 @@ export async function patchViewerUI() { document.getElementById('firstPage')?.previousElementSibling?.classList.add('visibleLargeView') if (params.toolbar !== 0) { document.getElementsByClassName('toolbar')[0]?.classList.add('hide') - document.getElementById('viewerContainer')!.classList.add('topped') } const template = document.createElement('template') @@ -241,6 +243,4 @@ export function repositionAnnotation() { function showToolbar() { const toolbarDom = document.getElementsByClassName('toolbar')[0] toolbarDom.classList.remove('hide') - const containerDom = document.getElementById('viewerContainer')! - containerDom.classList.remove('topped') } diff --git a/viewer/latexworkshop.css b/viewer/latexworkshop.css index 1fc491f72..79a53220a 100644 --- a/viewer/latexworkshop.css +++ b/viewer/latexworkshop.css @@ -143,10 +143,6 @@ html[dir='rtl'] .findbar { } #viewerContainer { - transition: all 0.2s cubic-bezier(.23,.96,.57,.99) !important; -} - -#viewerContainer.topped { top: 0 !important; } From 2acb22a60636df241730886771f04e13bee0a72e Mon Sep 17 00:00:00 2001 From: James Yu Date: Mon, 14 Oct 2024 17:03:12 +0800 Subject: [PATCH 2/3] Toolbar hides if mouse moved out of viewer tab --- viewer/components/gui.ts | 33 +++++++++++++++++++-------------- viewer/latexworkshop.css | 2 +- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/viewer/components/gui.ts b/viewer/components/gui.ts index a5d7cd3ce..c43cf143b 100644 --- a/viewer/components/gui.ts +++ b/viewer/components/gui.ts @@ -8,7 +8,19 @@ import type { PDFViewerApplicationType } from './interface.js' declare const PDFViewerApplication: PDFViewerApplicationType -let hideToolbar: number | undefined +let hideToolbarTimeout: number | undefined +function hideToolbar(params: Awaited>) { + if (typeof PDFViewerApplication === 'undefined') { + return + } + if (hideToolbarTimeout === undefined && !PDFViewerApplication.findBar.opened && !PDFViewerApplication.pdfSidebar.isOpen && !PDFViewerApplication.secondaryToolbar.isOpen) { + hideToolbarTimeout = setTimeout(() => { + const toolbarDom = document.getElementsByClassName('toolbar')[0] + toolbarDom.classList.add('hide') + hideToolbarTimeout = undefined + }, params.toolbar * 1000) + } +} export async function patchViewerUI() { if (utils.isEmbedded()) { // Cannot simply remove this element, as pdf.js indeed require it to @@ -23,27 +35,20 @@ export async function patchViewerUI() { containerDom.style.top = '32px' } + document.getElementById('outerContainer')!.onmouseleave = () => { hideToolbar(params) } + document.getElementById('outerContainer')!.onmousemove = (e) => { if (params.toolbar === 0) { return } if (e.clientY <= 64) { - if (hideToolbar) { - clearTimeout(hideToolbar) - hideToolbar = undefined + if (hideToolbarTimeout) { + clearTimeout(hideToolbarTimeout) + hideToolbarTimeout = undefined } showToolbar() } else { - if (typeof PDFViewerApplication === 'undefined') { - return - } - if (hideToolbar === undefined && !PDFViewerApplication.findBar.opened && !PDFViewerApplication.pdfSidebar.isOpen && !PDFViewerApplication.secondaryToolbar.isOpen) { - hideToolbar = setTimeout(() => { - const toolbarDom = document.getElementsByClassName('toolbar')[0] - toolbarDom.classList.add('hide') - hideToolbar = undefined - }, params.toolbar * 1000) - } + hideToolbar(params) } } diff --git a/viewer/latexworkshop.css b/viewer/latexworkshop.css index 79a53220a..99512fb49 100644 --- a/viewer/latexworkshop.css +++ b/viewer/latexworkshop.css @@ -143,7 +143,7 @@ html[dir='rtl'] .findbar { } #viewerContainer { - top: 0 !important; + top: 0; } #pageNumber { From 4adb279c7aa702b72b4a3a9840e55af4dfb045db Mon Sep 17 00:00:00 2001 From: James Yu Date: Mon, 14 Oct 2024 17:08:41 +0800 Subject: [PATCH 3/3] Hide toolbar on viewer launch --- dev/editviewer.py | 1 + viewer/components/gui.ts | 13 +++++++------ viewer/viewer.html | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/dev/editviewer.py b/dev/editviewer.py index f9d469027..1e521518a 100644 --- a/dev/editviewer.py +++ b/dev/editviewer.py @@ -14,6 +14,7 @@ .replace('''''', '''\n ''') .replace('''''', '''''') .replace('''''', '''''') + .replace('''
''', '''
''') .replace('''
''', '''''') ) diff --git a/viewer/components/gui.ts b/viewer/components/gui.ts index c43cf143b..5b982a2b7 100644 --- a/viewer/components/gui.ts +++ b/viewer/components/gui.ts @@ -31,11 +31,15 @@ export async function patchViewerUI() { const params = await utils.getParams() if (params.toolbar === 0) { - const containerDom = document.getElementById('viewerContainer')! - containerDom.style.top = '32px' + document.getElementsByClassName('toolbar')[0]?.classList.remove('hide') + document.getElementById('viewerContainer')!.style.top = '32px' } - document.getElementById('outerContainer')!.onmouseleave = () => { hideToolbar(params) } + document.getElementById('outerContainer')!.onmouseleave = () => { + if (params.toolbar !== 0) { + hideToolbar(params) + } + } document.getElementById('outerContainer')!.onmousemove = (e) => { if (params.toolbar === 0) { @@ -54,9 +58,6 @@ export async function patchViewerUI() { document.getElementById('sidebarResizer')?.classList.add('hidden') document.getElementById('firstPage')?.previousElementSibling?.classList.add('visibleLargeView') - if (params.toolbar !== 0) { - document.getElementsByClassName('toolbar')[0]?.classList.add('hide') - } const template = document.createElement('template') template.innerHTML = diff --git a/viewer/viewer.html b/viewer/viewer.html index 48b286276..10e634932 100644 --- a/viewer/viewer.html +++ b/viewer/viewer.html @@ -84,7 +84,7 @@
-
+