Skip to content

Commit

Permalink
Merge pull request #18523 from Snuffleupagus/Toolbar-more-bindListeners
Browse files Browse the repository at this point in the history
Move all event listeners into `Toolbar.prototype.#bindListeners`
  • Loading branch information
timvandermeij authored Aug 1, 2024
2 parents e6bb1f3 + 7c3aa94 commit d562e05
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions web/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,31 +118,7 @@ class Toolbar {
// Bind the event listeners for click and various other actions.
this.#bindListeners(buttons);

if (options.editorHighlightColorPicker) {
eventBus._on(
"annotationeditoruimanager",
({ uiManager }) => {
this.#setAnnotationEditorUIManager(
uiManager,
options.editorHighlightColorPicker
);
},
// Once the color picker has been added, we don't want to add it again.
{ once: true }
);
}

eventBus._on("showannotationeditorui", ({ mode }) => {
switch (mode) {
case AnnotationEditorType.HIGHLIGHT:
options.editorHighlightButton.click();
break;
}
});

eventBus._on("toolbardensity", this.#updateToolbarDensity.bind(this));
this.#updateToolbarDensity({ value: toolbarDensity });

this.reset();
}

Expand Down Expand Up @@ -188,7 +164,12 @@ class Toolbar {

#bindListeners(buttons) {
const { eventBus } = this;
const { pageNumber, scaleSelect } = this.#opts;
const {
editorHighlightColorPicker,
editorHighlightButton,
pageNumber,
scaleSelect,
} = this.#opts;
const self = this;

// The buttons within the toolbar.
Expand Down Expand Up @@ -243,6 +224,28 @@ class Toolbar {
"annotationeditormodechanged",
this.#editorModeChanged.bind(this)
);
eventBus._on("showannotationeditorui", ({ mode }) => {
switch (mode) {
case AnnotationEditorType.HIGHLIGHT:
editorHighlightButton.click();
break;
}
});
eventBus._on("toolbardensity", this.#updateToolbarDensity.bind(this));

if (editorHighlightColorPicker) {
eventBus._on(
"annotationeditoruimanager",
({ uiManager }) => {
this.#setAnnotationEditorUIManager(
uiManager,
editorHighlightColorPicker
);
},
// Once the color picker has been added, we don't want to add it again.
{ once: true }
);
}
}

#editorModeChanged({ mode }) {
Expand Down

0 comments on commit d562e05

Please sign in to comment.