Skip to content

Commit

Permalink
Auto-hide toolbar only on small touch devices
Browse files Browse the repository at this point in the history
The toolbar takes up only a small vertical space on larger devices even
in landscape mode; hence, not much space is gained by hiding it.
  • Loading branch information
shivaprsd committed Jun 7, 2024
1 parent 476968b commit 12d19d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/scripts/doqment.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
transition-duration: var(--sidebar-transition-duration);
transition-timing-function: var(--sidebar-transition-timing-function);
}
.toolbarHidden :is(#mainContainer, #sidebarContainer) {
.toolbarHidden:not(.auto) :is(#mainContainer, #sidebarContainer) {
/* Toolbar height is fixed at 32px, plus a 1px box-shadow */
margin-top: -33px;
}
/* Auto-hide only in small devices */
@media screen and (max-height: 384px) {
.toolbarHidden.auto :is(#mainContainer, #sidebarContainer) {
margin-top: -33px;
}
}
/* Reduce toolbar clutter in small devices */
@media screen and (max-width: 435px) {
#toolbarViewerLeft > #numPages {
Expand Down
13 changes: 9 additions & 4 deletions src/scripts/doqment.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ const Doqment = {
},

toggleToolbar() {
if (!this.options.autoToolbar)
const smallDevice = window.matchMedia("(max-height: 384px)");
if (!this.options.autoToolbar || !smallDevice.matches) {
return;
}
const hideThresh = 50, showThresh = -20;
const {viewer} = this.config;
let delta = viewer.scrollTop - this.oldScrollTop;
Expand All @@ -60,12 +62,13 @@ const Doqment = {
this.scrollMark = viewer.scrollTop;
}
if (this.scrollMark) {
const { viewerClassList } = this.config;
delta = viewer.scrollTop - this.scrollMark;
if (delta > hideThresh) {
this.config.viewerClassList.add("toolbarHidden");
viewerClassList.add("toolbarHidden", "auto");
this.scrollMark = 0;
} else if (delta < showThresh) {
this.config.viewerClassList.remove("toolbarHidden");
viewerClassList.remove("toolbarHidden", "auto");
this.scrollMark = 0;
}
}
Expand All @@ -78,7 +81,9 @@ const Doqment = {
e.target.isContentEditable || modifier)
return;
if (e.code === "F3" && !e.shiftKey) {
this.config.viewerClassList.toggle("toolbarHidden");
const { viewerClassList } = this.config;
viewerClassList.toggle("toolbarHidden");
viewerClassList.remove("auto");
e.preventDefault();
} else if (e.key === "z" || e.key === "Z") {
this.toggleSmartZoom(e);
Expand Down

0 comments on commit 12d19d9

Please sign in to comment.