Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline single-line event handlers in the web/app.js file #18527

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 60 additions & 115 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1886,10 +1886,9 @@ const PDFViewerApplication = {
},

triggerPrinting() {
if (!this.supportsPrinting) {
return;
if (this.supportsPrinting) {
window.print();
}
window.print();
},

bindEvents() {
Expand All @@ -1900,6 +1899,10 @@ const PDFViewerApplication = {

const {
eventBus,
externalServices,
pdfDocumentProperties,
pdfViewer,
preferences,
_eventBusAbortController: { signal },
} = this;

Expand All @@ -1916,44 +1919,60 @@ const PDFViewerApplication = {
eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged, { signal });
eventBus._on("pagemode", webViewerPageMode, { signal });
eventBus._on("namedaction", webViewerNamedAction, { signal });
eventBus._on("presentationmodechanged", webViewerPresentationModeChanged, {
eventBus._on(
"presentationmodechanged",
evt => (pdfViewer.presentationModeState = evt.state),
{ signal }
);
eventBus._on("presentationmode", this.requestPresentationMode.bind(this), {
signal,
});
eventBus._on("presentationmode", webViewerPresentationMode, { signal });
eventBus._on(
"switchannotationeditormode",
webViewerSwitchAnnotationEditorMode,
evt => (pdfViewer.annotationEditorMode = evt),
{ signal }
);
eventBus._on(
"switchannotationeditorparams",
webViewerSwitchAnnotationEditorParams,
evt => (pdfViewer.annotationEditorParams = evt),
{ signal }
);
eventBus._on("print", webViewerPrint, { signal });
eventBus._on("download", webViewerDownload, { signal });
eventBus._on("firstpage", webViewerFirstPage, { signal });
eventBus._on("lastpage", webViewerLastPage, { signal });
eventBus._on("nextpage", webViewerNextPage, { signal });
eventBus._on("previouspage", webViewerPreviousPage, { signal });
eventBus._on("zoomin", webViewerZoomIn, { signal });
eventBus._on("zoomout", webViewerZoomOut, { signal });
eventBus._on("zoomreset", webViewerZoomReset, { signal });
eventBus._on("print", this.triggerPrinting.bind(this), { signal });
eventBus._on("download", this.downloadOrSave.bind(this), { signal });
eventBus._on("firstpage", () => (this.page = 1), { signal });
eventBus._on("lastpage", () => (this.page = this.pagesCount), { signal });
eventBus._on("nextpage", () => pdfViewer.nextPage(), { signal });
eventBus._on("previouspage", () => pdfViewer.previousPage(), { signal });
eventBus._on("zoomin", this.zoomIn.bind(this), { signal });
eventBus._on("zoomout", this.zoomOut.bind(this), { signal });
eventBus._on("zoomreset", this.zoomReset.bind(this), { signal });
eventBus._on("pagenumberchanged", webViewerPageNumberChanged, { signal });
eventBus._on("scalechanged", webViewerScaleChanged, { signal });
eventBus._on("rotatecw", webViewerRotateCw, { signal });
eventBus._on("rotateccw", webViewerRotateCcw, { signal });
eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig, {
eventBus._on(
"scalechanged",
evt => (pdfViewer.currentScaleValue = evt.value),
{ signal }
);
eventBus._on("rotatecw", this.rotatePages.bind(this, 90), { signal });
eventBus._on("rotateccw", this.rotatePages.bind(this, -90), { signal });
eventBus._on(
"optionalcontentconfig",
evt => (pdfViewer.optionalContentConfigPromise = evt.promise),
{ signal }
);
eventBus._on("switchscrollmode", evt => (pdfViewer.scrollMode = evt.mode), {
signal,
});
eventBus._on("switchscrollmode", webViewerSwitchScrollMode, { signal });
eventBus._on("scrollmodechanged", webViewerScrollModeChanged, { signal });
eventBus._on("switchspreadmode", webViewerSwitchSpreadMode, { signal });
eventBus._on("switchspreadmode", evt => (pdfViewer.spreadMode = evt.mode), {
signal,
});
eventBus._on("spreadmodechanged", webViewerSpreadModeChanged, { signal });
eventBus._on("imagealttextsettings", webViewerImageAltTextSettings, {
signal,
});
eventBus._on("documentproperties", webViewerDocumentProperties, { signal });
eventBus._on("documentproperties", () => pdfDocumentProperties?.open(), {
signal,
});
eventBus._on("findfromurlhash", webViewerFindFromUrlHash, { signal });
eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount, {
signal,
Expand All @@ -1969,16 +1988,24 @@ const PDFViewerApplication = {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
eventBus._on(
"annotationeditorstateschanged",
webViewerAnnotationEditorStatesChanged,
evt => externalServices.updateEditorStates(evt),
{ signal }
);
eventBus._on(
"reporttelemetry",
evt => externalServices.reportTelemetry(evt.details),
{ signal }
);
eventBus._on("reporttelemetry", webViewerReportTelemetry, { signal });
}
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("TESTING || MOZCENTRAL")
) {
eventBus._on("setpreference", webViewerSetPreference, { signal });
eventBus._on(
"setpreference",
evt => preferences.set(evt.name, evt.value),
{ signal }
);
}
},

Expand All @@ -1991,12 +2018,13 @@ const PDFViewerApplication = {
const {
eventBus,
appConfig: { mainContainer },
pdfViewer,
_windowAbortController: { signal },
} = this;

function addWindowResolutionChange(evt = null) {
if (evt) {
webViewerResolutionChange(evt);
pdfViewer.refresh();
}
const mediaQueryList = window.matchMedia(
`(resolution: ${window.devicePixelRatio || 1}dppx)`
Expand Down Expand Up @@ -2029,9 +2057,7 @@ const PDFViewerApplication = {
window.addEventListener("keyup", webViewerKeyUp, { signal });
window.addEventListener(
"resize",
() => {
eventBus.dispatch("resize", { source: window });
},
() => eventBus.dispatch("resize", { source: window }),
{ signal }
);
window.addEventListener(
Expand All @@ -2046,24 +2072,20 @@ const PDFViewerApplication = {
);
window.addEventListener(
"beforeprint",
() => {
eventBus.dispatch("beforeprint", { source: window });
},
() => eventBus.dispatch("beforeprint", { source: window }),
{ signal }
);
window.addEventListener(
"afterprint",
() => {
eventBus.dispatch("afterprint", { source: window });
},
() => eventBus.dispatch("afterprint", { source: window }),
{ signal }
);
window.addEventListener(
"updatefromsandbox",
event => {
evt => {
eventBus.dispatch("updatefromsandbox", {
source: window,
detail: event.detail,
detail: evt.detail,
});
},
{ signal }
Expand Down Expand Up @@ -2317,10 +2339,6 @@ function webViewerNamedAction(evt) {
}
}

function webViewerPresentationModeChanged(evt) {
PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
}

function webViewerSidebarViewChanged({ view }) {
PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled =
view === SidebarView.THUMBS;
Expand Down Expand Up @@ -2436,42 +2454,6 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
};
}

function webViewerPresentationMode() {
PDFViewerApplication.requestPresentationMode();
}
function webViewerSwitchAnnotationEditorMode(evt) {
PDFViewerApplication.pdfViewer.annotationEditorMode = evt;
}
function webViewerSwitchAnnotationEditorParams(evt) {
PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
}
function webViewerPrint() {
PDFViewerApplication.triggerPrinting();
}
function webViewerDownload() {
PDFViewerApplication.downloadOrSave();
}
function webViewerFirstPage() {
PDFViewerApplication.page = 1;
}
function webViewerLastPage() {
PDFViewerApplication.page = PDFViewerApplication.pagesCount;
}
function webViewerNextPage() {
PDFViewerApplication.pdfViewer.nextPage();
}
function webViewerPreviousPage() {
PDFViewerApplication.pdfViewer.previousPage();
}
function webViewerZoomIn() {
PDFViewerApplication.zoomIn();
}
function webViewerZoomOut() {
PDFViewerApplication.zoomOut();
}
function webViewerZoomReset() {
PDFViewerApplication.zoomReset();
}
function webViewerPageNumberChanged(evt) {
const pdfViewer = PDFViewerApplication.pdfViewer;
// Note that for `<input type="number">` HTML elements, an empty string will
Expand All @@ -2492,27 +2474,6 @@ function webViewerPageNumberChanged(evt) {
);
}
}
function webViewerScaleChanged(evt) {
PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
}
function webViewerRotateCw() {
PDFViewerApplication.rotatePages(90);
}
function webViewerRotateCcw() {
PDFViewerApplication.rotatePages(-90);
}
function webViewerOptionalContentConfig(evt) {
PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
}
function webViewerSwitchScrollMode(evt) {
PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
}
function webViewerSwitchSpreadMode(evt) {
PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
}
function webViewerDocumentProperties() {
PDFViewerApplication.pdfDocumentProperties?.open();
}

function webViewerImageAltTextSettings() {
PDFViewerApplication.imageAltTextSettings?.open({
Expand Down Expand Up @@ -2599,10 +2560,6 @@ function webViewerPageChanging({ pageNumber, pageLabel }) {
);
}

function webViewerResolutionChange(evt) {
PDFViewerApplication.pdfViewer.refresh();
}

function webViewerWheel(evt) {
const {
pdfViewer,
Expand Down Expand Up @@ -3204,16 +3161,4 @@ function beforeUnload(evt) {
return false;
}

function webViewerAnnotationEditorStatesChanged(data) {
PDFViewerApplication.externalServices.updateEditorStates(data);
}

function webViewerReportTelemetry({ details }) {
PDFViewerApplication.externalServices.reportTelemetry(details);
}

function webViewerSetPreference({ name, value }) {
PDFViewerApplication.preferences.set(name, value);
}

export { PDFViewerApplication };