Merge pull request #10579 from Snuffleupagus/PDFSidebar-signature

Re-factor the `PDFSidebar` constructor to simplify its call-site (PR 10123 follow-up)
This commit is contained in:
Tim van der Meij 2019-02-24 15:53:43 +01:00 committed by GitHub
commit 220b56717e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 29 deletions

View File

@ -287,8 +287,8 @@ let PDFViewerApplication = {
this.overlayManager = new OverlayManager(); this.overlayManager = new OverlayManager();
const dispatchToDOM = AppOptions.get('eventBusDispatchToDOM'); const eventBus = appConfig.eventBus ||
const eventBus = appConfig.eventBus || getGlobalEventBus(dispatchToDOM); getGlobalEventBus(AppOptions.get('eventBusDispatchToDOM'));
this.eventBus = eventBus; this.eventBus = eventBus;
let pdfRenderingQueue = new PDFRenderingQueue(); let pdfRenderingQueue = new PDFRenderingQueue();
@ -336,9 +336,8 @@ let PDFViewerApplication = {
pdfRenderingQueue.setViewer(this.pdfViewer); pdfRenderingQueue.setViewer(this.pdfViewer);
pdfLinkService.setViewer(this.pdfViewer); pdfLinkService.setViewer(this.pdfViewer);
let thumbnailContainer = appConfig.sidebar.thumbnailView;
this.pdfThumbnailViewer = new PDFThumbnailViewer({ this.pdfThumbnailViewer = new PDFThumbnailViewer({
container: thumbnailContainer, container: appConfig.sidebar.thumbnailView,
renderingQueue: pdfRenderingQueue, renderingQueue: pdfRenderingQueue,
linkService: pdfLinkService, linkService: pdfLinkService,
l10n: this.l10n, l10n: this.l10n,
@ -393,11 +392,13 @@ let PDFViewerApplication = {
downloadManager, downloadManager,
}); });
// TODO: improve `PDFSidebar` constructor parameter passing this.pdfSidebar = new PDFSidebar({
let sidebarConfig = Object.create(appConfig.sidebar); elements: appConfig.sidebar,
sidebarConfig.pdfViewer = this.pdfViewer; pdfViewer: this.pdfViewer,
sidebarConfig.pdfThumbnailViewer = this.pdfThumbnailViewer; pdfThumbnailViewer: this.pdfThumbnailViewer,
this.pdfSidebar = new PDFSidebar(sidebarConfig, eventBus, this.l10n); eventBus,
l10n: this.l10n,
});
this.pdfSidebar.onToggled = this.forceRendering.bind(this); this.pdfSidebar.onToggled = this.forceRendering.bind(this);
this.pdfSidebarResizer = new PDFSidebarResizer(appConfig.sidebarResizer, this.pdfSidebarResizer = new PDFSidebarResizer(appConfig.sidebarResizer,

View File

@ -29,8 +29,17 @@ const SidebarView = {
/** /**
* @typedef {Object} PDFSidebarOptions * @typedef {Object} PDFSidebarOptions
* @property {PDFSidebarElements} elements - The DOM elements.
* @property {PDFViewer} pdfViewer - The document viewer. * @property {PDFViewer} pdfViewer - The document viewer.
* @property {PDFThumbnailViewer} pdfThumbnailViewer - The thumbnail viewer. * @property {PDFThumbnailViewer} pdfThumbnailViewer - The thumbnail viewer.
* @property {EventBus} eventBus - The application event bus.
* @property {IL10n} l10n - The localization service.
* @property {boolean} disableNotification - (optional) Disable the notification
* for documents containing outline/attachments. The default value is `false`.
*/
/**
* @typedef {Object} PDFSidebarElements
* @property {HTMLDivElement} outerContainer - The outer container * @property {HTMLDivElement} outerContainer - The outer container
* (encasing both the viewer and sidebar elements). * (encasing both the viewer and sidebar elements).
* @property {HTMLDivElement} viewerContainer - The viewer container * @property {HTMLDivElement} viewerContainer - The viewer container
@ -49,17 +58,14 @@ const SidebarView = {
* the outline is placed. * the outline is placed.
* @property {HTMLDivElement} attachmentsView - The container in which * @property {HTMLDivElement} attachmentsView - The container in which
* the attachments are placed. * the attachments are placed.
* @property {boolean} disableNotification - (optional) Disable the notification
* for documents containing outline/attachments. The default value is `false`.
*/ */
class PDFSidebar { class PDFSidebar {
/** /**
* @param {PDFSidebarOptions} options * @param {PDFSidebarOptions} options
* @param {EventBus} eventBus - The application event bus.
* @param {IL10n} l10n - Localization service.
*/ */
constructor(options, eventBus, l10n = NullL10n) { constructor({ elements, pdfViewer, pdfThumbnailViewer, eventBus,
l10n = NullL10n, disableNotification = false, }) {
this.isOpen = false; this.isOpen = false;
this.active = SidebarView.THUMBS; this.active = SidebarView.THUMBS;
this.isInitialViewSet = false; this.isInitialViewSet = false;
@ -70,25 +76,24 @@ class PDFSidebar {
*/ */
this.onToggled = null; this.onToggled = null;
this.pdfViewer = options.pdfViewer; this.pdfViewer = pdfViewer;
this.pdfThumbnailViewer = options.pdfThumbnailViewer; this.pdfThumbnailViewer = pdfThumbnailViewer;
this.outerContainer = options.outerContainer; this.outerContainer = elements.outerContainer;
this.viewerContainer = options.viewerContainer; this.viewerContainer = elements.viewerContainer;
this.toggleButton = options.toggleButton; this.toggleButton = elements.toggleButton;
this.thumbnailButton = options.thumbnailButton; this.thumbnailButton = elements.thumbnailButton;
this.outlineButton = options.outlineButton; this.outlineButton = elements.outlineButton;
this.attachmentsButton = options.attachmentsButton; this.attachmentsButton = elements.attachmentsButton;
this.thumbnailView = options.thumbnailView; this.thumbnailView = elements.thumbnailView;
this.outlineView = options.outlineView; this.outlineView = elements.outlineView;
this.attachmentsView = options.attachmentsView; this.attachmentsView = elements.attachmentsView;
this.disableNotification = options.disableNotification || false;
this.eventBus = eventBus; this.eventBus = eventBus;
this.l10n = l10n; this.l10n = l10n;
this._disableNotification = disableNotification;
this._addEventListeners(); this._addEventListeners();
} }
@ -305,7 +310,7 @@ class PDFSidebar {
* @private * @private
*/ */
_showUINotification(view) { _showUINotification(view) {
if (this.disableNotification) { if (this._disableNotification) {
return; return;
} }
@ -339,7 +344,7 @@ class PDFSidebar {
* @private * @private
*/ */
_hideUINotification(view) { _hideUINotification(view) {
if (this.disableNotification) { if (this._disableNotification) {
return; return;
} }