Reduce some duplication when toggling buttons in the viewer toolbars

Currently we repeat the same code in lots of places, to update the "toggled" class and "aria-checked" attribute, when various toolbar buttons are clicked.

For the MOZCENTRAL build-target this patch reduces the size of the *built* `web/viewer.js` file by just over `1.2` kilo-bytes.
This commit is contained in:
Jonas Jenwald 2023-04-13 12:36:39 +02:00
parent b3932f70ed
commit 2a195beb30
4 changed files with 69 additions and 82 deletions

View file

@ -841,6 +841,13 @@ function apiPageModeToSidebarView(mode) {
return SidebarView.NONE; // Default value.
}
function toggleCheckedBtn(button, toggle, view = null) {
button.classList.toggle("toggled", toggle);
button.setAttribute("aria-checked", toggle);
view?.classList.toggle("hidden", !toggle);
}
export {
animationStarted,
apiPageLayoutToViewerModes,
@ -880,6 +887,7 @@ export {
SidebarView,
SpreadMode,
TextLayerMode,
toggleCheckedBtn,
UNKNOWN_SCALE,
VERTICAL_PADDING,
watchScroll,