diff --git a/src/index.html b/src/index.html index f11be064b..ef384ce95 100644 --- a/src/index.html +++ b/src/index.html @@ -148,6 +148,7 @@ enableThumbnailsSidebar: true, showAnnotations: true, showDownload: true, + showFileName: true, // <- Note: Example of usage here }; previewOptions.container = '.preview-container'; diff --git a/src/lib/Preview.js b/src/lib/Preview.js index 773de069a..04fbaae50 100644 --- a/src/lib/Preview.js +++ b/src/lib/Preview.js @@ -855,6 +855,12 @@ class Preview extends EventEmitter { * @return {void} */ setupUI() { + /* + + Note: this.file.name is not present when this function is called - therefore, have to set the name later + + */ + // Setup the shell this.container = this.ui.setup( this.options, @@ -928,6 +934,9 @@ class Preview extends EventEmitter { // Whether the loading indicator should be shown this.options.showLoading = options.showLoading !== false; + // Whether to show the file name in the header + this.options.showFileName = options.showFileName; + // Whether annotations v4 buttons should be shown in toolbar this.options.showAnnotationsControls = !!options.showAnnotationsControls; @@ -1326,6 +1335,10 @@ class Preview extends EventEmitter { this.ui.showPrintButton(this.print); } + if (this.options.showFileName && this.file.name) { + this.ui.showFileName(this.file.name); + } + const { error } = data; if (error) { // Bump up preview count diff --git a/src/lib/PreviewUI.js b/src/lib/PreviewUI.js index 6b959d042..d12f6cb20 100644 --- a/src/lib/PreviewUI.js +++ b/src/lib/PreviewUI.js @@ -341,6 +341,24 @@ class PreviewUI { } } + /** + * Sets the file name in the header + * + * @param {string} fileName - Name of the file + * @return {void} + */ + showFileName(fileName) { + const headerContainerEl = this.container.querySelector(SELECTOR_BOX_PREVIEW_HEADER_CONTAINER); + + const headerEl = headerContainerEl.firstElementChild; + + const fileNameEl = headerEl.querySelector('.bp-file-name'); + if (fileNameEl) { + fileNameEl.classList.remove(CLASS_HIDDEN); + fileNameEl.innerText = fileName; + } + } + //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- @@ -368,6 +386,14 @@ class PreviewUI { * @return {void} */ setupHeader(headerTheme, logoUrl) { + /* + + NOTE: May have some setup that should be done in this function for showing file name + + However, when this function is called, this.file in Preview.js does not yet know the file name. Therefore, can't + do everything in here for setting the file name + + */ const headerContainerEl = this.container.querySelector(SELECTOR_BOX_PREVIEW_HEADER_CONTAINER); headerContainerEl.classList.remove(CLASS_HIDDEN); diff --git a/src/lib/shell.html b/src/lib/shell.html index 76131292b..5c6dd89fc 100644 --- a/src/lib/shell.html +++ b/src/lib/shell.html @@ -9,6 +9,8 @@ + +