Merge pull request #16628 from Snuffleupagus/app-webViewerInitialized-inline
Inline the `webViewerInitialized` function in `PDFViewerApplication.run`
This commit is contained in:
commit
2c74323e3d
207
web/app.js
207
web/app.js
@ -685,8 +685,107 @@ const PDFViewerApplication = {
|
||||
}
|
||||
},
|
||||
|
||||
run(config) {
|
||||
this.initialize(config).then(webViewerInitialized);
|
||||
async run(config) {
|
||||
await this.initialize(config);
|
||||
|
||||
const { appConfig, eventBus, l10n } = this;
|
||||
let file;
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
const queryString = document.location.search.substring(1);
|
||||
const params = parseQueryString(queryString);
|
||||
file = params.get("file") ?? AppOptions.get("defaultUrl");
|
||||
validateFileURL(file);
|
||||
} else if (PDFJSDev.test("MOZCENTRAL")) {
|
||||
file = window.location.href;
|
||||
} else if (PDFJSDev.test("CHROME")) {
|
||||
file = AppOptions.get("defaultUrl");
|
||||
}
|
||||
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
const fileInput = appConfig.openFileInput;
|
||||
fileInput.value = null;
|
||||
|
||||
fileInput.addEventListener("change", function (evt) {
|
||||
const { files } = evt.target;
|
||||
if (!files || files.length === 0) {
|
||||
return;
|
||||
}
|
||||
eventBus.dispatch("fileinputchange", {
|
||||
source: this,
|
||||
fileInput: evt.target,
|
||||
});
|
||||
});
|
||||
|
||||
// Enable dragging-and-dropping a new PDF file onto the viewerContainer.
|
||||
appConfig.mainContainer.addEventListener("dragover", function (evt) {
|
||||
evt.preventDefault();
|
||||
|
||||
evt.dataTransfer.dropEffect =
|
||||
evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
|
||||
});
|
||||
appConfig.mainContainer.addEventListener("drop", function (evt) {
|
||||
evt.preventDefault();
|
||||
|
||||
const { files } = evt.dataTransfer;
|
||||
if (!files || files.length === 0) {
|
||||
return;
|
||||
}
|
||||
eventBus.dispatch("fileinputchange", {
|
||||
source: this,
|
||||
fileInput: evt.dataTransfer,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (!this.supportsDocumentFonts) {
|
||||
AppOptions.set("disableFontFace", true);
|
||||
l10n.get("web_fonts_disabled").then(msg => {
|
||||
console.warn(msg);
|
||||
});
|
||||
}
|
||||
|
||||
if (!this.supportsPrinting) {
|
||||
appConfig.toolbar?.print?.classList.add("hidden");
|
||||
appConfig.secondaryToolbar?.printButton.classList.add("hidden");
|
||||
}
|
||||
|
||||
if (!this.supportsFullscreen) {
|
||||
appConfig.secondaryToolbar?.presentationModeButton.classList.add(
|
||||
"hidden"
|
||||
);
|
||||
}
|
||||
|
||||
if (this.supportsIntegratedFind) {
|
||||
appConfig.toolbar?.viewFind?.classList.add("hidden");
|
||||
}
|
||||
|
||||
appConfig.mainContainer.addEventListener(
|
||||
"transitionend",
|
||||
function (evt) {
|
||||
if (evt.target === /* mainContainer */ this) {
|
||||
eventBus.dispatch("resize", { source: this });
|
||||
}
|
||||
},
|
||||
true
|
||||
);
|
||||
|
||||
try {
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
if (file) {
|
||||
this.open({ url: file });
|
||||
} else {
|
||||
this._hideViewBookmark();
|
||||
}
|
||||
} else if (PDFJSDev.test("MOZCENTRAL || CHROME")) {
|
||||
this.initPassiveLoading(file);
|
||||
} else {
|
||||
throw new Error("Not implemented: run");
|
||||
}
|
||||
} catch (reason) {
|
||||
l10n.get("loading_error").then(msg => {
|
||||
this._documentError(msg, reason);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
get initialized() {
|
||||
@ -768,13 +867,15 @@ const PDFViewerApplication = {
|
||||
return this.externalServices.supportedMouseWheelZoomModifierKeys;
|
||||
},
|
||||
|
||||
initPassiveLoading() {
|
||||
initPassiveLoading(file) {
|
||||
if (
|
||||
typeof PDFJSDev === "undefined" ||
|
||||
!PDFJSDev.test("MOZCENTRAL || CHROME")
|
||||
) {
|
||||
throw new Error("Not implemented: initPassiveLoading");
|
||||
}
|
||||
this.setTitleUsingUrl(file, /* downloadUrl = */ file);
|
||||
|
||||
this.externalServices.initPassiveLoading({
|
||||
onOpenWithTransport: range => {
|
||||
this.open({ range });
|
||||
@ -2197,106 +2298,6 @@ function reportPageStatsPDFBug({ pageNumber }) {
|
||||
globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
|
||||
}
|
||||
|
||||
function webViewerInitialized() {
|
||||
const { appConfig, eventBus, l10n } = PDFViewerApplication;
|
||||
let file;
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
const queryString = document.location.search.substring(1);
|
||||
const params = parseQueryString(queryString);
|
||||
file = params.get("file") ?? AppOptions.get("defaultUrl");
|
||||
validateFileURL(file);
|
||||
} else if (PDFJSDev.test("MOZCENTRAL")) {
|
||||
file = window.location.href;
|
||||
} else if (PDFJSDev.test("CHROME")) {
|
||||
file = AppOptions.get("defaultUrl");
|
||||
}
|
||||
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
const fileInput = appConfig.openFileInput;
|
||||
fileInput.value = null;
|
||||
|
||||
fileInput.addEventListener("change", function (evt) {
|
||||
const { files } = evt.target;
|
||||
if (!files || files.length === 0) {
|
||||
return;
|
||||
}
|
||||
eventBus.dispatch("fileinputchange", {
|
||||
source: this,
|
||||
fileInput: evt.target,
|
||||
});
|
||||
});
|
||||
|
||||
// Enable dragging-and-dropping a new PDF file onto the viewerContainer.
|
||||
appConfig.mainContainer.addEventListener("dragover", function (evt) {
|
||||
evt.preventDefault();
|
||||
|
||||
evt.dataTransfer.dropEffect =
|
||||
evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
|
||||
});
|
||||
appConfig.mainContainer.addEventListener("drop", function (evt) {
|
||||
evt.preventDefault();
|
||||
|
||||
const { files } = evt.dataTransfer;
|
||||
if (!files || files.length === 0) {
|
||||
return;
|
||||
}
|
||||
eventBus.dispatch("fileinputchange", {
|
||||
source: this,
|
||||
fileInput: evt.dataTransfer,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (!PDFViewerApplication.supportsDocumentFonts) {
|
||||
AppOptions.set("disableFontFace", true);
|
||||
l10n.get("web_fonts_disabled").then(msg => {
|
||||
console.warn(msg);
|
||||
});
|
||||
}
|
||||
|
||||
if (!PDFViewerApplication.supportsPrinting) {
|
||||
appConfig.toolbar?.print?.classList.add("hidden");
|
||||
appConfig.secondaryToolbar?.printButton.classList.add("hidden");
|
||||
}
|
||||
|
||||
if (!PDFViewerApplication.supportsFullscreen) {
|
||||
appConfig.secondaryToolbar?.presentationModeButton.classList.add("hidden");
|
||||
}
|
||||
|
||||
if (PDFViewerApplication.supportsIntegratedFind) {
|
||||
appConfig.toolbar?.viewFind?.classList.add("hidden");
|
||||
}
|
||||
|
||||
appConfig.mainContainer.addEventListener(
|
||||
"transitionend",
|
||||
function (evt) {
|
||||
if (evt.target === /* mainContainer */ this) {
|
||||
eventBus.dispatch("resize", { source: this });
|
||||
}
|
||||
},
|
||||
true
|
||||
);
|
||||
|
||||
try {
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
if (file) {
|
||||
PDFViewerApplication.open({ url: file });
|
||||
} else {
|
||||
PDFViewerApplication._hideViewBookmark();
|
||||
}
|
||||
} else if (PDFJSDev.test("MOZCENTRAL || CHROME")) {
|
||||
PDFViewerApplication.setTitleUsingUrl(file, /* downloadUrl = */ file);
|
||||
PDFViewerApplication.initPassiveLoading();
|
||||
} else {
|
||||
throw new Error("Not implemented: webViewerInitialized");
|
||||
}
|
||||
} catch (reason) {
|
||||
l10n.get("loading_error").then(msg => {
|
||||
PDFViewerApplication._documentError(msg, reason);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function webViewerPageRender({ pageNumber }) {
|
||||
// If the page is (the most) visible when it starts rendering,
|
||||
// ensure that the page number input loading indicator is displayed.
|
||||
|
Loading…
x
Reference in New Issue
Block a user