Inline the webViewerInitialized
function in PDFViewerApplication.run
Given the size of this function respectively method, it seems reasonable to simply inline the `webViewerInitialized`-code here.
This commit is contained in:
parent
cae8fe4c7e
commit
58252a528d
202
web/app.js
202
web/app.js
@ -685,8 +685,107 @@ const PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
run(config) {
|
async run(config) {
|
||||||
this.initialize(config).then(webViewerInitialized);
|
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() {
|
get initialized() {
|
||||||
@ -2199,105 +2298,6 @@ function reportPageStatsPDFBug({ pageNumber }) {
|
|||||||
globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
|
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.initPassiveLoading(file);
|
|
||||||
} else {
|
|
||||||
throw new Error("Not implemented: webViewerInitialized");
|
|
||||||
}
|
|
||||||
} catch (reason) {
|
|
||||||
l10n.get("loading_error").then(msg => {
|
|
||||||
PDFViewerApplication._documentError(msg, reason);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function webViewerPageRender({ pageNumber }) {
|
function webViewerPageRender({ pageNumber }) {
|
||||||
// If the page is (the most) visible when it starts rendering,
|
// If the page is (the most) visible when it starts rendering,
|
||||||
// ensure that the page number input loading indicator is displayed.
|
// ensure that the page number input loading indicator is displayed.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user