Skip to content

Commit

Permalink
Merge pull request #16248 from Snuffleupagus/editor-params-dispatchEvent
Browse files Browse the repository at this point in the history
Reduce duplication when dispatching the "switchannotationeditorparams" event
  • Loading branch information
Snuffleupagus committed Apr 3, 2023
2 parents b135dad + d256168 commit 96a3210
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions web/annotation_editor_params.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,27 @@ class AnnotationEditorParams {
editorInkThickness,
editorInkOpacity,
}) {
editorFreeTextFontSize.addEventListener("input", evt => {
const dispatchEvent = (typeStr, value) => {
this.eventBus.dispatch("switchannotationeditorparams", {
source: this,
type: AnnotationEditorParamsType.FREETEXT_SIZE,
value: editorFreeTextFontSize.valueAsNumber,
type: AnnotationEditorParamsType[typeStr],
value,
});
};
editorFreeTextFontSize.addEventListener("input", function () {
dispatchEvent("FREETEXT_SIZE", this.valueAsNumber);
});
editorFreeTextColor.addEventListener("input", evt => {
this.eventBus.dispatch("switchannotationeditorparams", {
source: this,
type: AnnotationEditorParamsType.FREETEXT_COLOR,
value: editorFreeTextColor.value,
});
editorFreeTextColor.addEventListener("input", function () {
dispatchEvent("FREETEXT_COLOR", this.value);
});
editorInkColor.addEventListener("input", evt => {
this.eventBus.dispatch("switchannotationeditorparams", {
source: this,
type: AnnotationEditorParamsType.INK_COLOR,
value: editorInkColor.value,
});
editorInkColor.addEventListener("input", function () {
dispatchEvent("INK_COLOR", this.value);
});
editorInkThickness.addEventListener("input", evt => {
this.eventBus.dispatch("switchannotationeditorparams", {
source: this,
type: AnnotationEditorParamsType.INK_THICKNESS,
value: editorInkThickness.valueAsNumber,
});
editorInkThickness.addEventListener("input", function () {
dispatchEvent("INK_THICKNESS", this.valueAsNumber);
});
editorInkOpacity.addEventListener("input", evt => {
this.eventBus.dispatch("switchannotationeditorparams", {
source: this,
type: AnnotationEditorParamsType.INK_OPACITY,
value: editorInkOpacity.valueAsNumber,
});
editorInkOpacity.addEventListener("input", function () {
dispatchEvent("INK_OPACITY", this.valueAsNumber);
});

this.eventBus._on("annotationeditorparamschanged", evt => {
Expand Down

0 comments on commit 96a3210

Please sign in to comment.