mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 14:48:08 +02:00
Shorten the PDFViewerApplication._initializeViewerComponents
method
By tweaking a few local variable names we can shorten various viewer-component initialization code, and we can also reduce some duplication when assigning components to the `PDFViewerApplication`-scope.
This commit is contained in:
parent
a8c77633a1
commit
8f7d6f4118
1 changed files with 33 additions and 36 deletions
69
web/app.js
69
web/app.js
|
@ -396,38 +396,35 @@ const PDFViewerApplication = {
|
|||
this.eventBus = AppOptions.eventBus = eventBus;
|
||||
mlManager?.setEventBus(eventBus, abortSignal);
|
||||
|
||||
this.overlayManager = new OverlayManager();
|
||||
const overlayManager = (this.overlayManager = new OverlayManager());
|
||||
|
||||
const pdfRenderingQueue = new PDFRenderingQueue();
|
||||
pdfRenderingQueue.onIdle = this._cleanup.bind(this);
|
||||
this.pdfRenderingQueue = pdfRenderingQueue;
|
||||
const renderingQueue = (this.pdfRenderingQueue = new PDFRenderingQueue());
|
||||
renderingQueue.onIdle = this._cleanup.bind(this);
|
||||
|
||||
const pdfLinkService = new PDFLinkService({
|
||||
const linkService = (this.pdfLinkService = new PDFLinkService({
|
||||
eventBus,
|
||||
externalLinkTarget: AppOptions.get("externalLinkTarget"),
|
||||
externalLinkRel: AppOptions.get("externalLinkRel"),
|
||||
ignoreDestinationZoom: AppOptions.get("ignoreDestinationZoom"),
|
||||
});
|
||||
this.pdfLinkService = pdfLinkService;
|
||||
}));
|
||||
|
||||
const downloadManager = (this.downloadManager = new DownloadManager());
|
||||
|
||||
const findController = new PDFFindController({
|
||||
linkService: pdfLinkService,
|
||||
const findController = (this.findController = new PDFFindController({
|
||||
linkService,
|
||||
eventBus,
|
||||
updateMatchesCountOnProgress:
|
||||
typeof PDFJSDev === "undefined"
|
||||
? !window.isGECKOVIEW
|
||||
: !PDFJSDev.test("GECKOVIEW"),
|
||||
});
|
||||
this.findController = findController;
|
||||
}));
|
||||
|
||||
const pdfScriptingManager = new PDFScriptingManager({
|
||||
eventBus,
|
||||
externalServices,
|
||||
docProperties: this._scriptingDocProperties.bind(this),
|
||||
});
|
||||
this.pdfScriptingManager = pdfScriptingManager;
|
||||
const pdfScriptingManager = (this.pdfScriptingManager =
|
||||
new PDFScriptingManager({
|
||||
eventBus,
|
||||
externalServices,
|
||||
docProperties: this._scriptingDocProperties.bind(this),
|
||||
}));
|
||||
|
||||
const container = appConfig.mainContainer,
|
||||
viewer = appConfig.viewerContainer;
|
||||
|
@ -440,12 +437,13 @@ const PDFViewerApplication = {
|
|||
foreground: AppOptions.get("pageColorsForeground"),
|
||||
}
|
||||
: null;
|
||||
|
||||
let altTextManager;
|
||||
if (AppOptions.get("enableUpdatedAddImage")) {
|
||||
altTextManager = appConfig.newAltTextDialog
|
||||
? new NewAltTextManager(
|
||||
appConfig.newAltTextDialog,
|
||||
this.overlayManager,
|
||||
overlayManager,
|
||||
eventBus
|
||||
)
|
||||
: null;
|
||||
|
@ -454,7 +452,7 @@ const PDFViewerApplication = {
|
|||
? new AltTextManager(
|
||||
appConfig.altTextDialog,
|
||||
container,
|
||||
this.overlayManager,
|
||||
overlayManager,
|
||||
eventBus
|
||||
)
|
||||
: null;
|
||||
|
@ -471,7 +469,7 @@ const PDFViewerApplication = {
|
|||
appConfig.editSignatureDialog,
|
||||
appConfig.annotationEditorParams?.editorSignatureAddSignature ||
|
||||
null,
|
||||
this.overlayManager,
|
||||
overlayManager,
|
||||
l10n,
|
||||
externalServices.createSignatureStorage(eventBus, abortSignal),
|
||||
eventBus
|
||||
|
@ -481,12 +479,12 @@ const PDFViewerApplication = {
|
|||
const enableHWA = AppOptions.get("enableHWA"),
|
||||
maxCanvasPixels = AppOptions.get("maxCanvasPixels"),
|
||||
maxCanvasDim = AppOptions.get("maxCanvasDim");
|
||||
const pdfViewer = new PDFViewer({
|
||||
const pdfViewer = (this.pdfViewer = new PDFViewer({
|
||||
container,
|
||||
viewer,
|
||||
eventBus,
|
||||
renderingQueue: pdfRenderingQueue,
|
||||
linkService: pdfLinkService,
|
||||
renderingQueue,
|
||||
linkService,
|
||||
downloadManager,
|
||||
altTextManager,
|
||||
signatureManager,
|
||||
|
@ -518,36 +516,35 @@ const PDFViewerApplication = {
|
|||
enableHWA,
|
||||
supportsPinchToZoom: this.supportsPinchToZoom,
|
||||
enableAutoLinking: AppOptions.get("enableAutoLinking"),
|
||||
});
|
||||
this.pdfViewer = pdfViewer;
|
||||
}));
|
||||
|
||||
pdfRenderingQueue.setViewer(pdfViewer);
|
||||
pdfLinkService.setViewer(pdfViewer);
|
||||
renderingQueue.setViewer(pdfViewer);
|
||||
linkService.setViewer(pdfViewer);
|
||||
pdfScriptingManager.setViewer(pdfViewer);
|
||||
|
||||
if (appConfig.sidebar?.thumbnailView) {
|
||||
this.pdfThumbnailViewer = new PDFThumbnailViewer({
|
||||
container: appConfig.sidebar.thumbnailView,
|
||||
eventBus,
|
||||
renderingQueue: pdfRenderingQueue,
|
||||
linkService: pdfLinkService,
|
||||
renderingQueue,
|
||||
linkService,
|
||||
maxCanvasPixels,
|
||||
maxCanvasDim,
|
||||
pageColors,
|
||||
abortSignal,
|
||||
enableHWA,
|
||||
});
|
||||
pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
|
||||
renderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
|
||||
}
|
||||
|
||||
// The browsing history is only enabled when the viewer is standalone,
|
||||
// i.e. not when it is embedded in a web page.
|
||||
if (!this.isViewerEmbedded && !AppOptions.get("disableHistory")) {
|
||||
this.pdfHistory = new PDFHistory({
|
||||
linkService: pdfLinkService,
|
||||
linkService,
|
||||
eventBus,
|
||||
});
|
||||
pdfLinkService.setHistory(this.pdfHistory);
|
||||
linkService.setHistory(this.pdfHistory);
|
||||
}
|
||||
|
||||
if (!this.supportsIntegratedFind && appConfig.findBar) {
|
||||
|
@ -578,7 +575,7 @@ const PDFViewerApplication = {
|
|||
if (mlManager && appConfig.secondaryToolbar?.imageAltTextSettingsButton) {
|
||||
this.imageAltTextSettings = new ImageAltTextSettings(
|
||||
appConfig.altTextSettingsDialog,
|
||||
this.overlayManager,
|
||||
overlayManager,
|
||||
eventBus,
|
||||
mlManager
|
||||
);
|
||||
|
@ -587,7 +584,7 @@ const PDFViewerApplication = {
|
|||
if (appConfig.documentProperties) {
|
||||
this.pdfDocumentProperties = new PDFDocumentProperties(
|
||||
appConfig.documentProperties,
|
||||
this.overlayManager,
|
||||
overlayManager,
|
||||
eventBus,
|
||||
l10n,
|
||||
/* fileNameLookup = */ () => this._docFilename
|
||||
|
@ -653,7 +650,7 @@ const PDFViewerApplication = {
|
|||
if (appConfig.passwordOverlay) {
|
||||
this.passwordPrompt = new PasswordPrompt(
|
||||
appConfig.passwordOverlay,
|
||||
this.overlayManager,
|
||||
overlayManager,
|
||||
this.isViewerEmbedded
|
||||
);
|
||||
}
|
||||
|
@ -663,7 +660,7 @@ const PDFViewerApplication = {
|
|||
container: appConfig.sidebar.outlineView,
|
||||
eventBus,
|
||||
l10n,
|
||||
linkService: pdfLinkService,
|
||||
linkService,
|
||||
downloadManager,
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue