Merge pull request #16248 from Snuffleupagus/editor-params-dispatchEvent

Reduce duplication when dispatching the "switchannotationeditorparams" event
This commit is contained in:
Jonas Jenwald 2023-04-03 13:32:33 +02:00 committed by GitHub
commit 96a3210501
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,40 +32,27 @@ class AnnotationEditorParams {
editorInkThickness, editorInkThickness,
editorInkOpacity, editorInkOpacity,
}) { }) {
editorFreeTextFontSize.addEventListener("input", evt => { const dispatchEvent = (typeStr, value) => {
this.eventBus.dispatch("switchannotationeditorparams", { this.eventBus.dispatch("switchannotationeditorparams", {
source: this, source: this,
type: AnnotationEditorParamsType.FREETEXT_SIZE, type: AnnotationEditorParamsType[typeStr],
value: editorFreeTextFontSize.valueAsNumber, value,
}); });
};
editorFreeTextFontSize.addEventListener("input", function () {
dispatchEvent("FREETEXT_SIZE", this.valueAsNumber);
}); });
editorFreeTextColor.addEventListener("input", evt => { editorFreeTextColor.addEventListener("input", function () {
this.eventBus.dispatch("switchannotationeditorparams", { dispatchEvent("FREETEXT_COLOR", this.value);
source: this,
type: AnnotationEditorParamsType.FREETEXT_COLOR,
value: editorFreeTextColor.value,
});
}); });
editorInkColor.addEventListener("input", evt => { editorInkColor.addEventListener("input", function () {
this.eventBus.dispatch("switchannotationeditorparams", { dispatchEvent("INK_COLOR", this.value);
source: this,
type: AnnotationEditorParamsType.INK_COLOR,
value: editorInkColor.value,
});
}); });
editorInkThickness.addEventListener("input", evt => { editorInkThickness.addEventListener("input", function () {
this.eventBus.dispatch("switchannotationeditorparams", { dispatchEvent("INK_THICKNESS", this.valueAsNumber);
source: this,
type: AnnotationEditorParamsType.INK_THICKNESS,
value: editorInkThickness.valueAsNumber,
});
}); });
editorInkOpacity.addEventListener("input", evt => { editorInkOpacity.addEventListener("input", function () {
this.eventBus.dispatch("switchannotationeditorparams", { dispatchEvent("INK_OPACITY", this.valueAsNumber);
source: this,
type: AnnotationEditorParamsType.INK_OPACITY,
value: editorInkOpacity.valueAsNumber,
});
}); });
this.eventBus._on("annotationeditorparamschanged", evt => { this.eventBus._on("annotationeditorparamschanged", evt => {