Skip to content

Commit

Permalink
Merge pull request #16410 from Snuffleupagus/toggleExpandedBtn
Browse files Browse the repository at this point in the history
Reduce some duplication when toggling "expanded" buttons in the viewer toolbars
  • Loading branch information
Snuffleupagus authored May 11, 2023
2 parents d520754 + 0305b04 commit 9417a37
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
9 changes: 3 additions & 6 deletions web/pdf_find_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

import { FindState } from "./pdf_find_controller.js";
import { toggleExpandedBtn } from "./ui_utils.js";

const MATCHES_COUNT_LIMIT = 1000;

Expand Down Expand Up @@ -173,9 +174,7 @@ class PDFFindBar {
open() {
if (!this.opened) {
this.opened = true;
this.toggleButton.classList.add("toggled");
this.toggleButton.setAttribute("aria-expanded", "true");
this.bar.classList.remove("hidden");
toggleExpandedBtn(this.toggleButton, true, this.bar);
}
this.findField.select();
this.findField.focus();
Expand All @@ -188,9 +187,7 @@ class PDFFindBar {
return;
}
this.opened = false;
this.toggleButton.classList.remove("toggled");
this.toggleButton.setAttribute("aria-expanded", "false");
this.bar.classList.add("hidden");
toggleExpandedBtn(this.toggleButton, false, this.bar);

this.eventBus.dispatch("findbarclose", { source: this });
}
Expand Down
7 changes: 3 additions & 4 deletions web/pdf_sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
RenderingStates,
SidebarView,
toggleCheckedBtn,
toggleExpandedBtn,
} from "./ui_utils.js";

const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
Expand Down Expand Up @@ -238,8 +239,7 @@ class PDFSidebar {
return;
}
this.isOpen = true;
this.toggleButton.classList.add("toggled");
this.toggleButton.setAttribute("aria-expanded", "true");
toggleExpandedBtn(this.toggleButton, true);

this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");

Expand All @@ -257,8 +257,7 @@ class PDFSidebar {
return;
}
this.isOpen = false;
this.toggleButton.classList.remove("toggled");
this.toggleButton.setAttribute("aria-expanded", "false");
toggleExpandedBtn(this.toggleButton, false);

this.outerContainer.classList.add("sidebarMoving");
this.outerContainer.classList.remove("sidebarOpen");
Expand Down
9 changes: 3 additions & 6 deletions web/secondary_toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ScrollMode,
SpreadMode,
toggleCheckedBtn,
toggleExpandedBtn,
} from "./ui_utils.js";
import { PagesCountLimit } from "./pdf_viewer.js";

Expand Down Expand Up @@ -292,19 +293,15 @@ class SecondaryToolbar {
return;
}
this.opened = true;
this.toggleButton.classList.add("toggled");
this.toggleButton.setAttribute("aria-expanded", "true");
this.toolbar.classList.remove("hidden");
toggleExpandedBtn(this.toggleButton, true, this.toolbar);
}

close() {
if (!this.opened) {
return;
}
this.opened = false;
this.toolbar.classList.add("hidden");
this.toggleButton.classList.remove("toggled");
this.toggleButton.setAttribute("aria-expanded", "false");
toggleExpandedBtn(this.toggleButton, false, this.toolbar);
}

toggle() {
Expand Down
8 changes: 8 additions & 0 deletions web/ui_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,13 @@ function toggleCheckedBtn(button, toggle, view = null) {
view?.classList.toggle("hidden", !toggle);
}

function toggleExpandedBtn(button, toggle, view = null) {
button.classList.toggle("toggled", toggle);
button.setAttribute("aria-expanded", toggle);

view?.classList.toggle("hidden", !toggle);
}

export {
animationStarted,
apiPageLayoutToViewerModes,
Expand Down Expand Up @@ -891,6 +898,7 @@ export {
SpreadMode,
TextLayerMode,
toggleCheckedBtn,
toggleExpandedBtn,
UNKNOWN_SCALE,
VERTICAL_PADDING,
watchScroll,
Expand Down
4 changes: 2 additions & 2 deletions web/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,10 @@
<div class="verticalToolbarSeparator hiddenMediumView"></div>

<div id="editorModeButtons" class="splitToolbarButton toggled" role="radiogroup">
<button id="editorFreeText" class="toolbarButton" disabled="disabled" title="Text" role="radio" aria-checked="false" tabindex="34" data-l10n-id="editor_free_text2">
<button id="editorFreeText" class="toolbarButton" disabled="disabled" title="Text" role="radio" aria-checked="false" aria-controls="editorFreeTextParamsToolbar" tabindex="34" data-l10n-id="editor_free_text2">
<span data-l10n-id="editor_free_text2_label">Text</span>
</button>
<button id="editorInk" class="toolbarButton" disabled="disabled" title="Draw" role="radio" aria-checked="false" tabindex="35" data-l10n-id="editor_ink2">
<button id="editorInk" class="toolbarButton" disabled="disabled" title="Draw" role="radio" aria-checked="false" aria-controls="editorInkParamsToolbar" tabindex="35" data-l10n-id="editor_ink2">
<span data-l10n-id="editor_ink2_label">Draw</span>
</button>
</div>
Expand Down

0 comments on commit 9417a37

Please sign in to comment.