1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Replace onScrollModeChanged and onSpreadModeChanged with one function

Given that these event handlers are virtually identical, obviously with the exception of the name-parameter, let's reduce a little bit of code duplication.
This commit is contained in:
Jonas Jenwald 2024-08-01 14:33:20 +02:00
parent 22ec252193
commit aae223f79b

View file

@ -1969,15 +1969,19 @@ const PDFViewerApplication = {
eventBus._on("switchscrollmode", evt => (pdfViewer.scrollMode = evt.mode), {
signal,
});
eventBus._on("scrollmodechanged", onScrollModeChanged.bind(this), {
signal,
});
eventBus._on(
"scrollmodechanged",
onViewerModesChanged.bind(this, "scrollMode"),
{ signal }
);
eventBus._on("switchspreadmode", evt => (pdfViewer.spreadMode = evt.mode), {
signal,
});
eventBus._on("spreadmodechanged", onSpreadModeChanged.bind(this), {
signal,
});
eventBus._on(
"spreadmodechanged",
onViewerModesChanged.bind(this, "spreadMode"),
{ signal }
);
eventBus._on("imagealttextsettings", onImageAltTextSettings.bind(this), {
signal,
});
@ -2402,19 +2406,10 @@ function onUpdateViewarea({ location }) {
}
}
function onScrollModeChanged(evt) {
function onViewerModesChanged(name, evt) {
if (this.isInitialViewSet && !this.pdfViewer.isInPresentationMode) {
// Only update the storage when the document has been loaded *and* rendered.
this.store?.set("scrollMode", evt.mode).catch(() => {
// Unable to write to storage.
});
}
}
function onSpreadModeChanged(evt) {
if (this.isInitialViewSet && !this.pdfViewer.isInPresentationMode) {
// Only update the storage when the document has been loaded *and* rendered.
this.store?.set("spreadMode", evt.mode).catch(() => {
this.store?.set(name, evt.mode).catch(() => {
// Unable to write to storage.
});
}