Skip to content

Commit

Permalink
Toolbar hides if mouse moved out of viewer tab
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Oct 14, 2024
1 parent c91e7ce commit 2acb22a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
33 changes: 19 additions & 14 deletions viewer/components/gui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnType<typeof utils.getParams>>) {
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
Expand All @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion viewer/latexworkshop.css
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ html[dir='rtl'] .findbar {
}

#viewerContainer {
top: 0 !important;
top: 0;
}

#pageNumber {
Expand Down

0 comments on commit 2acb22a

Please sign in to comment.