Skip to content

Commit cb818ce

Browse files
Merge pull request #19720 from Snuffleupagus/_initializeViewerComponents-shorten
Shorten the `PDFViewerApplication._initializeViewerComponents` method
2 parents 9d237b9 + 8f7d6f4 commit cb818ce

File tree

1 file changed

+33
-36
lines changed

1 file changed

+33
-36
lines changed

web/app.js

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -396,38 +396,35 @@ const PDFViewerApplication = {
396396
this.eventBus = AppOptions.eventBus = eventBus;
397397
mlManager?.setEventBus(eventBus, abortSignal);
398398

399-
this.overlayManager = new OverlayManager();
399+
const overlayManager = (this.overlayManager = new OverlayManager());
400400

401-
const pdfRenderingQueue = new PDFRenderingQueue();
402-
pdfRenderingQueue.onIdle = this._cleanup.bind(this);
403-
this.pdfRenderingQueue = pdfRenderingQueue;
401+
const renderingQueue = (this.pdfRenderingQueue = new PDFRenderingQueue());
402+
renderingQueue.onIdle = this._cleanup.bind(this);
404403

405-
const pdfLinkService = new PDFLinkService({
404+
const linkService = (this.pdfLinkService = new PDFLinkService({
406405
eventBus,
407406
externalLinkTarget: AppOptions.get("externalLinkTarget"),
408407
externalLinkRel: AppOptions.get("externalLinkRel"),
409408
ignoreDestinationZoom: AppOptions.get("ignoreDestinationZoom"),
410-
});
411-
this.pdfLinkService = pdfLinkService;
409+
}));
412410

413411
const downloadManager = (this.downloadManager = new DownloadManager());
414412

415-
const findController = new PDFFindController({
416-
linkService: pdfLinkService,
413+
const findController = (this.findController = new PDFFindController({
414+
linkService,
417415
eventBus,
418416
updateMatchesCountOnProgress:
419417
typeof PDFJSDev === "undefined"
420418
? !window.isGECKOVIEW
421419
: !PDFJSDev.test("GECKOVIEW"),
422-
});
423-
this.findController = findController;
420+
}));
424421

425-
const pdfScriptingManager = new PDFScriptingManager({
426-
eventBus,
427-
externalServices,
428-
docProperties: this._scriptingDocProperties.bind(this),
429-
});
430-
this.pdfScriptingManager = pdfScriptingManager;
422+
const pdfScriptingManager = (this.pdfScriptingManager =
423+
new PDFScriptingManager({
424+
eventBus,
425+
externalServices,
426+
docProperties: this._scriptingDocProperties.bind(this),
427+
}));
431428

432429
const container = appConfig.mainContainer,
433430
viewer = appConfig.viewerContainer;
@@ -440,12 +437,13 @@ const PDFViewerApplication = {
440437
foreground: AppOptions.get("pageColorsForeground"),
441438
}
442439
: null;
440+
443441
let altTextManager;
444442
if (AppOptions.get("enableUpdatedAddImage")) {
445443
altTextManager = appConfig.newAltTextDialog
446444
? new NewAltTextManager(
447445
appConfig.newAltTextDialog,
448-
this.overlayManager,
446+
overlayManager,
449447
eventBus
450448
)
451449
: null;
@@ -454,7 +452,7 @@ const PDFViewerApplication = {
454452
? new AltTextManager(
455453
appConfig.altTextDialog,
456454
container,
457-
this.overlayManager,
455+
overlayManager,
458456
eventBus
459457
)
460458
: null;
@@ -471,7 +469,7 @@ const PDFViewerApplication = {
471469
appConfig.editSignatureDialog,
472470
appConfig.annotationEditorParams?.editorSignatureAddSignature ||
473471
null,
474-
this.overlayManager,
472+
overlayManager,
475473
l10n,
476474
externalServices.createSignatureStorage(eventBus, abortSignal),
477475
eventBus
@@ -481,12 +479,12 @@ const PDFViewerApplication = {
481479
const enableHWA = AppOptions.get("enableHWA"),
482480
maxCanvasPixels = AppOptions.get("maxCanvasPixels"),
483481
maxCanvasDim = AppOptions.get("maxCanvasDim");
484-
const pdfViewer = new PDFViewer({
482+
const pdfViewer = (this.pdfViewer = new PDFViewer({
485483
container,
486484
viewer,
487485
eventBus,
488-
renderingQueue: pdfRenderingQueue,
489-
linkService: pdfLinkService,
486+
renderingQueue,
487+
linkService,
490488
downloadManager,
491489
altTextManager,
492490
signatureManager,
@@ -518,36 +516,35 @@ const PDFViewerApplication = {
518516
enableHWA,
519517
supportsPinchToZoom: this.supportsPinchToZoom,
520518
enableAutoLinking: AppOptions.get("enableAutoLinking"),
521-
});
522-
this.pdfViewer = pdfViewer;
519+
}));
523520

524-
pdfRenderingQueue.setViewer(pdfViewer);
525-
pdfLinkService.setViewer(pdfViewer);
521+
renderingQueue.setViewer(pdfViewer);
522+
linkService.setViewer(pdfViewer);
526523
pdfScriptingManager.setViewer(pdfViewer);
527524

528525
if (appConfig.sidebar?.thumbnailView) {
529526
this.pdfThumbnailViewer = new PDFThumbnailViewer({
530527
container: appConfig.sidebar.thumbnailView,
531528
eventBus,
532-
renderingQueue: pdfRenderingQueue,
533-
linkService: pdfLinkService,
529+
renderingQueue,
530+
linkService,
534531
maxCanvasPixels,
535532
maxCanvasDim,
536533
pageColors,
537534
abortSignal,
538535
enableHWA,
539536
});
540-
pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
537+
renderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
541538
}
542539

543540
// The browsing history is only enabled when the viewer is standalone,
544541
// i.e. not when it is embedded in a web page.
545542
if (!this.isViewerEmbedded && !AppOptions.get("disableHistory")) {
546543
this.pdfHistory = new PDFHistory({
547-
linkService: pdfLinkService,
544+
linkService,
548545
eventBus,
549546
});
550-
pdfLinkService.setHistory(this.pdfHistory);
547+
linkService.setHistory(this.pdfHistory);
551548
}
552549

553550
if (!this.supportsIntegratedFind && appConfig.findBar) {
@@ -578,7 +575,7 @@ const PDFViewerApplication = {
578575
if (mlManager && appConfig.secondaryToolbar?.imageAltTextSettingsButton) {
579576
this.imageAltTextSettings = new ImageAltTextSettings(
580577
appConfig.altTextSettingsDialog,
581-
this.overlayManager,
578+
overlayManager,
582579
eventBus,
583580
mlManager
584581
);
@@ -587,7 +584,7 @@ const PDFViewerApplication = {
587584
if (appConfig.documentProperties) {
588585
this.pdfDocumentProperties = new PDFDocumentProperties(
589586
appConfig.documentProperties,
590-
this.overlayManager,
587+
overlayManager,
591588
eventBus,
592589
l10n,
593590
/* fileNameLookup = */ () => this._docFilename
@@ -653,7 +650,7 @@ const PDFViewerApplication = {
653650
if (appConfig.passwordOverlay) {
654651
this.passwordPrompt = new PasswordPrompt(
655652
appConfig.passwordOverlay,
656-
this.overlayManager,
653+
overlayManager,
657654
this.isViewerEmbedded
658655
);
659656
}
@@ -663,7 +660,7 @@ const PDFViewerApplication = {
663660
container: appConfig.sidebar.outlineView,
664661
eventBus,
665662
l10n,
666-
linkService: pdfLinkService,
663+
linkService,
667664
downloadManager,
668665
});
669666
}

0 commit comments

Comments
 (0)