Merge pull request #15991 from Snuffleupagus/PDFViewerApplication-open-loops
Remove a couple of manual loops in the `PDFViewerApplication.open` method
This commit is contained in:
commit
cbe4912a16
29
web/app.js
29
web/app.js
@ -919,12 +919,9 @@ const PDFViewerApplication = {
|
|||||||
await this.close();
|
await this.close();
|
||||||
}
|
}
|
||||||
// Set the necessary global worker parameters, using the available options.
|
// Set the necessary global worker parameters, using the available options.
|
||||||
const workerParameters = AppOptions.getAll(OptionKind.WORKER);
|
const workerParams = AppOptions.getAll(OptionKind.WORKER);
|
||||||
for (const key in workerParameters) {
|
Object.assign(GlobalWorkerOptions, workerParams);
|
||||||
GlobalWorkerOptions[key] = workerParameters[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
const parameters = Object.create(null);
|
|
||||||
if (
|
if (
|
||||||
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) &&
|
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) &&
|
||||||
args.url
|
args.url
|
||||||
@ -938,26 +935,16 @@ const PDFViewerApplication = {
|
|||||||
this.setTitleUsingUrl(args.url, /* downloadUrl = */ args.url);
|
this.setTitleUsingUrl(args.url, /* downloadUrl = */ args.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set the necessary API parameters, using the available options.
|
// Set the necessary API parameters, using all the available options.
|
||||||
const apiParameters = AppOptions.getAll(OptionKind.API);
|
const apiParams = AppOptions.getAll(OptionKind.API);
|
||||||
for (const key in apiParameters) {
|
const params = { ...apiParams, ...args };
|
||||||
let value = apiParameters[key];
|
|
||||||
|
|
||||||
if (key === "docBaseUrl") {
|
|
||||||
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
|
||||||
value ||= document.URL.split("#")[0];
|
params.docBaseUrl ||= document.URL.split("#")[0];
|
||||||
} else if (PDFJSDev.test("MOZCENTRAL || CHROME")) {
|
} else if (PDFJSDev.test("MOZCENTRAL || CHROME")) {
|
||||||
value ||= this.baseUrl;
|
params.docBaseUrl ||= this.baseUrl;
|
||||||
}
|
}
|
||||||
}
|
const loadingTask = getDocument(params);
|
||||||
parameters[key] = value;
|
|
||||||
}
|
|
||||||
// Finally, update the API parameters with the arguments.
|
|
||||||
for (const key in args) {
|
|
||||||
parameters[key] = args[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadingTask = getDocument(parameters);
|
|
||||||
this.pdfLoadingTask = loadingTask;
|
this.pdfLoadingTask = loadingTask;
|
||||||
|
|
||||||
loadingTask.onPassword = (updateCallback, reason) => {
|
loadingTask.onPassword = (updateCallback, reason) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user