UNPKG

@syncfusion/ej2-pdfviewer

Version:
978 lines 134 kB
import { createElement, Browser, isBlazor, isNullOrUndefined, initializeCSPTemplate } from '@syncfusion/ej2-base'; import { Toolbar as tool } from '@syncfusion/ej2-navigations'; import { NumericTextBox } from '@syncfusion/ej2-inputs'; import { ComboBox } from '@syncfusion/ej2-dropdowns'; import { AnnotationToolbar } from '../index'; import { Tooltip } from '@syncfusion/ej2-popups'; import { DropDownButton } from '@syncfusion/ej2-splitbuttons'; import { FormFieldDataFormat } from '../base/types'; import { FormDesignerToolbar } from './formdesigner-toolbar'; /* eslint-disable valid-jsdoc */ /** * Toolbar module * * @param {string} args - args * @param {Event} event - args * @returns {void} */ var Toolbar = /** @class */ (function () { /** * @param {PdfViewer} viewer - It describes about the viewer * @param {PdfViewerBase} viewerBase - It describes about the viewer base * @private * @returns {void} */ function Toolbar(viewer, viewerBase) { var _this = this; this.isPageNavigationToolDisabled = false; this.isMagnificationToolDisabled = false; /** * @private */ this.isSelectionToolDisabled = false; this.isScrollingToolDisabled = false; this.isOpenBtnVisible = true; this.isNavigationToolVisible = true; this.isMagnificationToolVisible = true; this.isSelectionBtnVisible = true; this.isScrollingBtnVisible = true; this.isDownloadBtnVisible = true; this.isPrintBtnVisible = true; this.isSearchBtnVisible = true; /** * @private */ this.isTextSearchBoxDisplayed = false; this.isUndoRedoBtnsVisible = true; this.isAnnotationEditBtnVisible = true; this.isFormDesignerEditBtnVisible = true; this.isCommentBtnVisible = true; this.isSubmitbtnvisible = true; this.toolItems = []; this.itemsIndexArray = []; this.onToolbarKeydown = function (event) { var isSkip = event.key === 'Tab' || event.shiftKey === true || event.key === 'Enter' || event.key === ' ' || event.key === 'ArrowUp' || event.key === 'ArrowDown' || event.key === 'ArrowLeft' || event.key === 'ArrowRight'; var targetId = event.target.id; var customItem = _this.toolItems.filter(function (toolItem) { return toolItem.id === targetId; }); if (!(targetId === _this.pdfViewer.element.id + '_currentPageInput' || targetId === _this.pdfViewer.element.id + '_zoomDropDown' || customItem.length > 0) && !isSkip) { event.preventDefault(); event.stopPropagation(); } }; this.toolbarClickHandler = function (args) { var isKeyBoardEvent = args.originalEvent && args.originalEvent.pointerType !== 'mouse' && args.originalEvent.pointerType !== 'touch'; if (!Browser.isDevice || _this.pdfViewer.enableDesktopMode) { if (args.originalEvent.target === _this.zoomDropdownItem.parentElement.childNodes[1] || args.originalEvent.target === _this.zoomDropdownItem.parentElement.childNodes[2]) { args.cancel = true; } else if (args.originalEvent.target.id === _this.pdfViewer.element.id + '_openIcon') { var tooltipData = args.originalEvent.target.parentElement.dataset; if (tooltipData && tooltipData.tooltipId) { var tooltipElement = document.getElementById(tooltipData.tooltipId); if (tooltipElement) { tooltipElement.style.display = 'none'; } } } } _this.handleToolbarBtnClick(args, isKeyBoardEvent); var targetElement = args.originalEvent.target; var customItem = []; if (!isNullOrUndefined(args.item)) { customItem = _this.toolItems.filter(function (toolItem) { return toolItem.id === args.item.id; }); } if (!Browser.isDevice || _this.pdfViewer.enableDesktopMode) { if (!(args.originalEvent.target === _this.zoomDropdownItem.parentElement.childNodes[1] || args.originalEvent.target === _this.zoomDropdownItem.parentElement.childNodes[2] || args.originalEvent.target === _this.currentPageBoxElement || args.originalEvent.target === _this.textSearchItem.childNodes[0] || customItem.length > 0)) { if (!isKeyBoardEvent && targetElement.parentElement.id !== _this.pdfViewer.element.id + '_toolbarContainer_nav' && targetElement.id !== _this.pdfViewer.element.id + '_toolbarContainer_nav') { args.originalEvent.target.blur(); _this.pdfViewerBase.focusViewerContainer(); } } } else { args.originalEvent.target.blur(); _this.pdfViewerBase.focusViewerContainer(); } }; this.loadDocument = function (args) { var upoadedFiles = args.target.files; if (args.target.files[0] !== null) { var uploadedFile = upoadedFiles[0]; if (uploadedFile) { _this.uploadedDocumentName = uploadedFile.name; var reader = new FileReader(); if (_this.pdfViewerBase.clientSideRendering) { reader.readAsArrayBuffer(uploadedFile); } else { reader.readAsDataURL(uploadedFile); } reader.onload = function (e) { args.target.value = null; var uploadedFileUrl = e.currentTarget.result; _this.pdfViewer.uploadedFileByteArray = new Uint8Array(uploadedFileUrl); if (isBlazor()) { _this.pdfViewer._dotnetInstance.invokeMethodAsync('LoadDocumentFromClient', uploadedFileUrl); } else { if (_this.pdfViewerBase.clientSideRendering) { _this.uploadedFile = _this.pdfViewer.uploadedFileByteArray; _this.pdfViewer.load(_this.pdfViewer.uploadedFileByteArray, null); _this.pdfViewerBase.isSkipDocumentPath = true; _this.pdfViewer.documentPath = _this.pdfViewer.uploadedFileByteArray; _this.pdfViewerBase.documentPathByteArray = _this.pdfViewer.documentPath; } else { _this.uploadedFile = uploadedFileUrl; _this.pdfViewer.load(uploadedFileUrl, null); _this.pdfViewerBase.isSkipDocumentPath = true; _this.pdfViewer.documentPath = uploadedFileUrl; _this.pdfViewerBase.documentPathByteArray = _this.pdfViewer.documentPath; } } if (!isNullOrUndefined(_this.fileInputElement)) { _this.fileInputElement.value = ''; } }; } } }; this.navigateToPage = function (args) { if (args.which === 13) { var enteredValue = parseInt(_this.currentPageBoxElement.value, 10); if (enteredValue !== null) { if (enteredValue > 0 && enteredValue <= _this.pdfViewerBase.pageCount) { if (_this.pdfViewer.navigationModule) { _this.pdfViewer.navigationModule.goToPage(enteredValue); } } else { _this.updateCurrentPage(_this.pdfViewerBase.currentPageNumber); } } else { _this.updateCurrentPage(_this.pdfViewerBase.currentPageNumber); } _this.currentPageBoxElement.blur(); _this.pdfViewerBase.focusViewerContainer(); } }; this.textBoxFocusOut = function () { if (_this.currentPageBox.value === null || _this.currentPageBox.value >= _this.pdfViewerBase.pageCount || _this.currentPageBox.value !== _this.pdfViewerBase.currentPageNumber) { _this.updateCurrentPage(_this.pdfViewerBase.currentPageNumber); } }; this.pdfViewer = viewer; this.pdfViewerBase = viewerBase; } /** * @param {string} width - It describes about the width * @private * @returns {HTMLElement} - html element */ Toolbar.prototype.intializeToolbar = function (width) { var toolbarDiv; if (!isBlazor()) { toolbarDiv = this.createToolbar(width); } else { if (!Browser.isDevice || this.pdfViewer.enableDesktopMode) { toolbarDiv = this.pdfViewer.element.querySelector('.e-pv-toolbar'); this.toolbarElement = toolbarDiv; } } var isIE = !!document.documentMode; if (isIE) { if (isBlazor()) { this.pdfViewerBase.blazorUIAdaptor.totalPageElement.classList.add('e-pv-total-page-ms'); } else { if (!Browser.isDevice) { this.totalPageItem.classList.add('e-pv-total-page-ms'); } } } this.createFileElement(toolbarDiv); this.wireEvent(); if (!isBlazor()) { this.updateToolbarItems(); if (!Browser.isDevice || this.pdfViewer.enableDesktopMode) { this.applyToolbarSettings(); this.initialEnableItems(); this.pdfViewerBase.navigationPane.adjustPane(); } else { this.initialEnableItems(); } if (this.pdfViewer.annotationModule) { this.annotationToolbarModule = new AnnotationToolbar(this.pdfViewer, this.pdfViewerBase, this); if (!Browser.isDevice || this.pdfViewer.enableDesktopMode) { this.annotationToolbarModule.initializeAnnotationToolbar(); } } if (this.pdfViewer.formDesignerModule) { this.formDesignerToolbarModule = new FormDesignerToolbar(this.pdfViewer, this.pdfViewerBase, this); if (!Browser.isDevice || this.pdfViewer.enableDesktopMode) { this.formDesignerToolbarModule.initializeFormDesignerToolbar(); } } } else { if (!Browser.isDevice || this.pdfViewer.enableDesktopMode) { this.initialEnableItems(); this.pdfViewerBase.navigationPane.adjustPane(); if (this.pdfViewer.enableToolbar) { this.bindOpenIconEvent(); } } this.PanElement = document.getElementById(this.pdfViewer.element.id + '_handTool').children[0]; this.PanElement.classList.add('e-pv-tbar-btn'); this.SelectToolElement = document.getElementById(this.pdfViewer.element.id + '_selectTool').children[0]; this.SelectToolElement.classList.add('e-pv-tbar-btn'); this.CommentElement = document.getElementById(this.pdfViewer.element.id + '_comment').children[0]; this.CommentElement.classList.add('e-pv-tbar-btn'); this.annotationToolbarModule = new AnnotationToolbar(this.pdfViewer, this.pdfViewerBase, this); if (this.pdfViewer.enableToolbar && this.pdfViewer.enableAnnotationToolbar || (this.pdfViewer.enableDesktopMode && Browser.isDevice)) { this.annotationToolbarModule.afterAnnotationToolbarCreationInBlazor(); } } return toolbarDiv; }; Toolbar.prototype.bindOpenIconEvent = function () { var openElement = document.getElementById(this.pdfViewer.element.id + '_open'); if (openElement) { openElement.addEventListener('click', this.openFileDialogBox.bind(this)); } }; Toolbar.prototype.InitializeMobileToolbarInBlazor = function () { var toolbarDiv = this.pdfViewer.element.querySelector('.e-pv-mobile-toolbar'); this.createFileElement(toolbarDiv); this.wireEvent(); }; /** * Shows /hides the toolbar in the PdfViewer * * @param {boolean} enableToolbar - If set true , its show the Toolbar * @returns {void} */ Toolbar.prototype.showToolbar = function (enableToolbar) { var toolbar; if (!isNullOrUndefined(this.toolbarElement)) { toolbar = this.toolbarElement; } if (enableToolbar) { if (!isNullOrUndefined(toolbar) && !(this.pdfViewerBase.navigationPane && this.pdfViewerBase.navigationPane.isNavigationToolbarVisible)) { toolbar.style.display = 'block'; } var toolbarContainer = this.pdfViewerBase.getElement('_toolbarContainer'); if (toolbarContainer) { var toolbarHeight = toolbarContainer.clientHeight; if (toolbarHeight === 0) { toolbarHeight = parseFloat(window.getComputedStyle(toolbarContainer)['height']) + 1; } this.pdfViewerBase.toolbarHeight = toolbarHeight; } if ((Browser.isDevice && !this.pdfViewer.enableDesktopMode) && this.pdfViewer.toolbarModule && this.pdfViewer.toolbarModule.annotationToolbarModule) { this.pdfViewer.toolbarModule.annotationToolbarModule.hideMobileAnnotationToolbar(); } } else { this.pdfViewerBase.toolbarHeight = 0; if (enableToolbar) { if (Browser.isDevice && this.pdfViewer.toolbarModule.annotationToolbarModule.toolbar) { this.annotationToolbarModule.toolbarCreated = false; this.annotationToolbarModule.adjustMobileViewer(); this.pdfViewer.toolbarModule.annotationToolbarModule.toolbar.element.style.display = 'none'; } if (Browser.isDevice && this.annotationToolbarModule.propertyToolbar) { this.annotationToolbarModule.propertyToolbar.element.style.display = 'none'; } } if (!isNullOrUndefined(toolbar)) { toolbar.style.display = 'none'; } } }; /** * Shows/hides the Navigation toolbar in the PdfViewer * * @param {boolean} enableNavigationToolbar - If set true , its show the Navigation Toolbar * @returns {void} */ Toolbar.prototype.showNavigationToolbar = function (enableNavigationToolbar) { if (!Browser.isDevice || this.pdfViewer.enableDesktopMode) { var navigationToolbar = this.pdfViewerBase.navigationPane.sideBarToolbar; var navigationToolbarSplitter = this.pdfViewerBase.navigationPane.sideBarToolbarSplitter; if (enableNavigationToolbar) { if (!isNullOrUndefined(navigationToolbar)) { navigationToolbar.style.display = 'block'; } if (!isNullOrUndefined(navigationToolbarSplitter)) { navigationToolbarSplitter.style.display = 'block'; } if (this.pdfViewerBase.navigationPane.isBookmarkOpen || this.pdfViewerBase.navigationPane.isThumbnailOpen) { this.pdfViewerBase.navigationPane.clear(); } } else { if (!isNullOrUndefined(navigationToolbar)) { navigationToolbar.style.display = 'none'; } if (!isNullOrUndefined(navigationToolbarSplitter)) { navigationToolbarSplitter.style.display = 'none'; } if (this.pdfViewerBase.navigationPane.isBookmarkOpen || this.pdfViewerBase.navigationPane.isThumbnailOpen) { this.pdfViewerBase.navigationPane.updateViewerContainerOnClose(); } } } }; /** * Shows /hides the annotation toolbar in the PdfViewer * * @param {boolean} enableAnnotationToolbar - If set true , its show the annotation Toolbar * @returns {void} */ Toolbar.prototype.showAnnotationToolbar = function (enableAnnotationToolbar) { if (enableAnnotationToolbar) { this.annotationToolbarModule.isToolbarHidden = true; this.annotationToolbarModule.showAnnotationToolbar(null, false, true); } else { this.annotationToolbarModule.isToolbarHidden = false; this.annotationToolbarModule.showAnnotationToolbar(null, false, false); } }; /** * Shows /hides the the toolbar items in the PdfViewer * * @param {string[]} items - Defines the toolbar items in the toolbar * @param {boolean} isVisible - If set true, then its show the toolbar Items * @returns {void} */ Toolbar.prototype.showToolbarItem = function (items, isVisible) { for (var i = 0; i < items.length; i++) { switch (items[parseInt(i.toString(), 10)]) { case 'OpenOption': this.showOpenOption(isVisible); break; case 'PageNavigationTool': this.showPageNavigationTool(isVisible); break; case 'MagnificationTool': this.showMagnificationTool(isVisible); break; case 'SelectionTool': this.showSelectionTool(isVisible); break; case 'PanTool': this.showScrollingTool(isVisible); break; case 'DownloadOption': this.showDownloadOption(isVisible); break; case 'PrintOption': this.showPrintOption(isVisible); break; case 'SearchOption': this.showSearchOption(isVisible); break; case 'UndoRedoTool': this.showUndoRedoTool(isVisible); break; case 'AnnotationEditTool': this.showAnnotationEditTool(isVisible); break; case 'FormDesignerEditTool': this.showFormDesignerEditTool(isVisible); break; case 'CommentTool': this.showCommentOption(isVisible); break; case 'SubmitForm': this.showSubmitForm(isVisible); break; } } if (!Browser.isDevice || this.pdfViewer.enableDesktopMode) { this.applyHideToToolbar(true, this.itemsIndexArray[0].endIndex + 1, this.itemsIndexArray[0].endIndex + 1); this.applyHideToToolbar(true, this.itemsIndexArray[1].endIndex + 1, this.itemsIndexArray[1].endIndex + 1); this.applyHideToToolbar(true, this.itemsIndexArray[2].endIndex + 1, this.itemsIndexArray[2].endIndex + 1); this.applyHideToToolbar(true, this.itemsIndexArray[4].endIndex + 1, this.itemsIndexArray[4].endIndex + 1); this.applyHideToToolbar(true, this.itemsIndexArray[5].endIndex + 1, this.itemsIndexArray[5].endIndex + 1); } else { this.applyHideToToolbar(true, 1, 1); this.applyHideToToolbar(true, 8, 8); this.applyHideToToolbar(true, 12, 12); this.applyHideToToolbar(true, 15, 15); } this.showSeparator(items); }; /** * Enables /disables the the toolbar items in the PdfViewer * * @param {string[]} items - Defines the toolbar items in the toolbar * @param {boolean} isEnable - If set true, then its Enable the toolbar Items * @returns {void} */ Toolbar.prototype.enableToolbarItem = function (items, isEnable) { for (var i = 0; i < items.length; i++) { switch (items[parseInt(i.toString(), 10)]) { case 'OpenOption': this.enableOpenOption(isEnable); break; case 'PageNavigationTool': this.isPageNavigationToolDisabled = isEnable; this.enablePageNavigationTool(isEnable); break; case 'MagnificationTool': this.isMagnificationToolDisabled = isEnable; this.enableMagnificationTool(isEnable); break; case 'SelectionTool': this.isSelectionToolDisabled = isEnable; this.enableSelectionTool(isEnable); break; case 'PanTool': this.isScrollingToolDisabled = isEnable; this.enableScrollingTool(isEnable); break; case 'DownloadOption': this.enableDownloadOption(isEnable); break; case 'PrintOption': this.enablePrintOption(isEnable); break; case 'SearchOption': this.enableSearchOption(isEnable); break; case 'UndoRedoTool': this.enableUndoRedoTool(isEnable); break; case 'AnnotationEditTool': this.enableAnnotationEditTool(isEnable); break; case 'FormDesignerEditTool': this.enableFormDesignerEditTool(isEnable); break; case 'CommentTool': this.enableCommentsTool(isEnable); break; case 'OrganizePagesTool': this.enableOrganizePagesButton(isEnable); break; } } }; /** * @param {any} restrictionSummary - It describes about the restriction summary * @param {boolean} isEnable - It describes about the isEnable boolean value * @private * @returns {void} */ Toolbar.prototype.DisableToolbarItems = function (restrictionSummary, isEnable) { switch (restrictionSummary) { case 'Print': this.enablePrintOption(isEnable); break; case 'CopyContent': this.isSelectionToolDisabled = isEnable; this.enableSelectionTool(isEnable); if (isEnable) { this.pdfViewerBase.initiateTextSelectMode(); this.updateInteractionTools(isEnable); } else { this.pdfViewerBase.initiatePanning(); this.updateInteractionTools(isEnable); } break; case 'EditAnnotations': this.enableAnnotationEditTool(isEnable); if (this.annotationToolbarModule && !this.annotationToolbarModule.isToolbarHidden) { this.annotationToolbarModule.showAnnotationToolbar(); } break; } }; Toolbar.prototype.showOpenOption = function (enableOpenOption) { this.isOpenBtnVisible = enableOpenOption; //For mobile devices, the default previous value for OpenOption has been passed as (0,0). this.applyHideToToolbar(enableOpenOption, !isNullOrUndefined(this.itemsIndexArray[0]) ? this.itemsIndexArray[0].startIndex : 0, !isNullOrUndefined(this.itemsIndexArray[0]) ? this.itemsIndexArray[0].endIndex : 0); }; Toolbar.prototype.showPageNavigationTool = function (enablePageNavigationTool) { this.isNavigationToolVisible = enablePageNavigationTool; //For mobile devices, the default previous value for PageNavigationTool has been passed as (2,7). this.applyHideToToolbar(enablePageNavigationTool, !isNullOrUndefined(this.itemsIndexArray[1]) ? this.itemsIndexArray[1].startIndex : 2, !isNullOrUndefined(this.itemsIndexArray[1]) ? this.itemsIndexArray[1].endIndex : 7); }; Toolbar.prototype.showMagnificationTool = function (enableMagnificationTool) { this.isMagnificationToolVisible = enableMagnificationTool; //For mobile devices, the default previous value for MagnificationTool has been passed as (9,11). this.applyHideToToolbar(enableMagnificationTool, !isNullOrUndefined(this.itemsIndexArray[2]) ? this.itemsIndexArray[2].startIndex : 9, !isNullOrUndefined(this.itemsIndexArray[2]) ? this.itemsIndexArray[2].endIndex : 11); }; Toolbar.prototype.showSelectionTool = function (enableSelectionTool) { this.isSelectionBtnVisible = enableSelectionTool; //For mobile devices, the default previous value for SelectionTool has been passed as (13,13). this.applyHideToToolbar(enableSelectionTool, !isNullOrUndefined(this.itemsIndexArray[3]) ? this.itemsIndexArray[3].startIndex : 13, !isNullOrUndefined(this.itemsIndexArray[3]) ? this.itemsIndexArray[3].endIndex : 13); }; Toolbar.prototype.showScrollingTool = function (enableScrollingTool) { this.isScrollingBtnVisible = enableScrollingTool; //For mobile devices, the default previous value for ScrollingTool has been passed as (14,14). this.applyHideToToolbar(enableScrollingTool, !isNullOrUndefined(this.itemsIndexArray[4]) ? this.itemsIndexArray[4].startIndex : 14, !isNullOrUndefined(this.itemsIndexArray[4]) ? this.itemsIndexArray[4].endIndex : 14); }; Toolbar.prototype.showDownloadOption = function (enableDownloadOption) { this.isDownloadBtnVisible = enableDownloadOption; if (!Browser.isDevice || this.pdfViewer.enableDesktopMode) { //The itemsIndexArray is null, the default previous value for DownloadOption has been passed as (26,26). this.applyHideToToolbar(enableDownloadOption, !isNullOrUndefined(this.itemsIndexArray[12]) ? this.itemsIndexArray[12].startIndex : 26, !isNullOrUndefined(this.itemsIndexArray[12]) ? this.itemsIndexArray[12].endIndex : 26); } else { this.applyHideToToolbar(enableDownloadOption, 6, 6); } }; Toolbar.prototype.showPageOrganizerToolbar = function (enablePageOrganizer) { if (Browser.isDevice && !this.pdfViewer.enableDesktopMode) { this.applyHideToToolbar(enablePageOrganizer, 4, 4); } }; Toolbar.prototype.showPrintOption = function (enablePrintOption) { this.isPrintBtnVisible = enablePrintOption; //For mobile devices, the default previous value for PrintOption has been passed as (25,25). this.applyHideToToolbar(enablePrintOption, !isNullOrUndefined(this.itemsIndexArray[11]) ? this.itemsIndexArray[11].startIndex : 25, !isNullOrUndefined(this.itemsIndexArray[11]) ? this.itemsIndexArray[11].endIndex : 25); }; Toolbar.prototype.showSearchOption = function (enableSearchOption) { this.isSearchBtnVisible = enableSearchOption; if (!Browser.isDevice || this.pdfViewer.enableDesktopMode) { //The itemsIndexArray is null, the default previous value for SearchOption has been passed as (22,22). this.applyHideToToolbar(enableSearchOption, !isNullOrUndefined(this.itemsIndexArray[8]) ? this.itemsIndexArray[8].startIndex : 22, !isNullOrUndefined(this.itemsIndexArray[8]) ? this.itemsIndexArray[8].endIndex : 22); } else { this.applyHideToToolbar(enableSearchOption, 6, 6); } }; Toolbar.prototype.showUndoRedoTool = function (isEnable) { this.isUndoRedoBtnsVisible = isEnable; if (!Browser.isDevice || this.pdfViewer.enableDesktopMode) { //The itemsIndexArray is null, the default previous value for PageNavigationTool has been passed as (16,17). this.applyHideToToolbar(isEnable, !isNullOrUndefined(this.itemsIndexArray[5]) ? this.itemsIndexArray[5].startIndex : 16, !isNullOrUndefined(this.itemsIndexArray[5]) ? this.itemsIndexArray[5].endIndex : 17); } else { this.applyHideToToolbar(isEnable, 2, 3); } }; Toolbar.prototype.showCommentOption = function (isEnable) { if (!this.pdfViewer.enableStickyNotesAnnotation) { this.isCommentBtnVisible = isEnable; //For mobile devices, the default previous value for CommentOption has been passed as (18,19). this.applyHideToToolbar(this.pdfViewer.enableStickyNotesAnnotation, !isNullOrUndefined(this.itemsIndexArray[6]) ? this.itemsIndexArray[6].startIndex : 18, !isNullOrUndefined(this.itemsIndexArray[6]) ? this.itemsIndexArray[6].endIndex : 19); } else { this.isCommentBtnVisible = isEnable; //For mobile devices, the default previous value for CommentOption has been passed as (18,19). this.applyHideToToolbar(isEnable, !isNullOrUndefined(this.itemsIndexArray[6]) ? this.itemsIndexArray[6].startIndex : 18, !isNullOrUndefined(this.itemsIndexArray[6]) ? this.itemsIndexArray[6].endIndex : 19); } }; Toolbar.prototype.showAnnotationEditTool = function (isEnable) { this.isAnnotationEditBtnVisible = isEnable; if (!Browser.isDevice || this.pdfViewer.enableDesktopMode) { //The itemsIndexArray is null, the default previous value for AnnotationEditTool has been passed as (23,23). this.applyHideToToolbar(isEnable, !isNullOrUndefined(this.itemsIndexArray[9]) ? this.itemsIndexArray[9].startIndex : 23, !isNullOrUndefined(this.itemsIndexArray[9]) ? this.itemsIndexArray[9].endIndex : 23); } else { this.applyHideToToolbar(isEnable, 5, 5); } }; Toolbar.prototype.showFormDesignerEditTool = function (isEnable) { this.isFormDesignerEditBtnVisible = isEnable; //For mobile devices, the default previous value for FormDesignerEditTool has been passed as (24,24). this.applyHideToToolbar(isEnable, !isNullOrUndefined(this.itemsIndexArray[10]) ? this.itemsIndexArray[10].startIndex : 24, !isNullOrUndefined(this.itemsIndexArray[10]) ? this.itemsIndexArray[10].endIndex : 24); }; Toolbar.prototype.showSubmitForm = function (isEnable) { this.isSubmitbtnvisible = isEnable; //For mobile devices, the default previous value for SubmitForm has been passed as (20,21). this.applyHideToToolbar(isEnable, !isNullOrUndefined(this.itemsIndexArray[7]) ? this.itemsIndexArray[7].startIndex : 20, !isNullOrUndefined(this.itemsIndexArray[7]) ? this.itemsIndexArray[7].endIndex : 21); }; Toolbar.prototype.enableOpenOption = function (enableOpenOption) { this.enableItems(this.openDocumentItem.parentElement, enableOpenOption); }; Toolbar.prototype.enablePageNavigationTool = function (enablePageNavigationTool) { this.enableItems(this.firstPageItem.parentElement, enablePageNavigationTool); this.enableItems(this.previousPageItem.parentElement, enablePageNavigationTool); this.enableItems(this.nextPageItem.parentElement, enablePageNavigationTool); this.enableItems(this.lastPageItem.parentElement, enablePageNavigationTool); this.currentPageBox.readonly = !enablePageNavigationTool; }; Toolbar.prototype.enableMagnificationTool = function (enableMagnificationTool) { this.enableItems(this.zoomInItem.parentElement, enableMagnificationTool); this.enableItems(this.zoomOutItem.parentElement, enableMagnificationTool); this.zoomDropDown.readonly = !enableMagnificationTool; }; Toolbar.prototype.enableSelectionTool = function (enableSelectionTool) { if (this.textSelectItem && this.textSelectItem.parentElement) { this.enableItems(this.textSelectItem.parentElement, enableSelectionTool); } }; Toolbar.prototype.enableScrollingTool = function (enableScrollingTool) { this.enableItems(this.panItem.parentElement, enableScrollingTool); }; Toolbar.prototype.enableDownloadOption = function (enableDownloadOption) { this.enableItems(this.downloadItem.parentElement, enableDownloadOption); }; Toolbar.prototype.enablePrintOption = function (enablePrintOption) { this.enableItems(this.printItem.parentElement, enablePrintOption); }; Toolbar.prototype.enableSearchOption = function (enableSearchOption) { this.enableItems(this.textSearchItem.parentElement, enableSearchOption); }; Toolbar.prototype.enableUndoRedoTool = function (isEnable) { this.enableItems(this.undoItem.parentElement, isEnable); this.enableItems(this.redoItem.parentElement, isEnable); }; Toolbar.prototype.enableAnnotationEditTool = function (isEnable) { this.enableItems(this.annotationItem.parentElement, isEnable); }; Toolbar.prototype.enableFormDesignerEditTool = function (isEnable) { this.enableItems(this.formDesignerItem.parentElement, isEnable); }; Toolbar.prototype.enableCommentsTool = function (isEnable) { if (this.pdfViewer.enableStickyNotesAnnotation) { this.enableItems(this.annotationItem.parentElement, isEnable); } }; Toolbar.prototype.enableOrganizePagesButton = function (isEnable) { if (!isNullOrUndefined(this.organizePageItem) && !isNullOrUndefined(this.organizePageItem.parentElement) && this.pdfViewer.enablePageOrganizer) { this.enableItems(this.organizePageItem.parentElement, isEnable); } }; /** * @private * @returns {void} */ Toolbar.prototype.resetToolbar = function () { if (!Browser.isDevice || this.pdfViewer.enableDesktopMode) { if (!isNullOrUndefined(this.currentPageBox)) { this.currentPageBox.min = 0; this.currentPageBox.value = 0; } this.updateTotalPage(); this.updateToolbarItems(); if (this.pdfViewer.toolbarModule && this.annotationToolbarModule) { this.pdfViewer.toolbarModule.annotationToolbarModule.updateFontSizeInIcon(16); } if (this.annotationToolbarModule) { this.annotationToolbarModule.clear(); } else { if (this.annotationToolbarModule) { if (this.annotationToolbarModule.propertyToolbar) { this.annotationToolbarModule.propertyToolbar.destroy(); } var commentsContainer = document.getElementById(this.pdfViewer.element.id + '_commentscontentcontainer'); if (commentsContainer) { commentsContainer.innerHTML = ''; } } } } }; /** * @private * @returns {void} */ Toolbar.prototype.updateToolbarItems = function () { if (!Browser.isDevice || this.pdfViewer.enableDesktopMode) { if (this.toolbar) { if (this.pdfViewerBase.pageCount === 0) { this.enableItems(this.downloadItem.parentElement, false); this.enableItems(this.printItem.parentElement, false); this.enableItems(this.commentItem.parentElement, false); this.updateUndoRedoButtons(); this.updateNavigationButtons(); this.enableItems(this.zoomInItem.parentElement, false); this.enableItems(this.zoomOutItem.parentElement, false); if (this.pdfViewer.magnificationModule) { this.zoomDropDown.readonly = true; } this.enableItems(this.submitItem.parentElement, false); this.toolbar.enableItems(this.pdfViewerBase.getElement('_currentPageInputContainer'), false); this.enableItems(this.pdfViewerBase.getElement('_zoomDropDownContainer'), false); this.enableItems(this.textSelectItem.parentElement, false); this.enableItems(this.annotationItem.parentElement, false); this.enableItems(this.formDesignerItem.parentElement, false); this.enableItems(this.panItem.parentElement, false); this.enableItems(this.textSearchItem.parentElement, false); this.deSelectItem(this.annotationItem); if (this.annotationToolbarModule) { this.annotationToolbarModule.resetToolbar(); } this.deSelectItem(this.formDesignerItem); if (this.formDesignerToolbarModule) { this.formDesignerToolbarModule.resetFormDesignerToolbar(); } } else if (this.pdfViewerBase.pageCount > 0) { var obj = this.pdfViewerBase.getElement('_currentPageInputContainer'); if (obj) { this.enableItems(this.downloadItem.parentElement, true); this.enableItems(this.printItem.parentElement, true); this.toolbar.enableItems(this.pdfViewerBase.getElement('_currentPageInputContainer'), true); this.enableItems(this.pdfViewerBase.getElement('_zoomDropDownContainer'), true); this.updateUndoRedoButtons(); this.updateNavigationButtons(); this.updateZoomButtons(); if (this.pdfViewer.magnificationModule) { this.zoomDropDown.readonly = false; } this.updateInteractionItems(); // modify this condition if new annotation types are added. if (this.pdfViewer.annotationModule && this.pdfViewer.enableAnnotation) { this.enableItems(this.annotationItem.parentElement, true); } if (this.pdfViewer.formDesignerModule && this.pdfViewer.enableFormDesigner) { this.enableItems(this.formDesignerItem.parentElement, true); } if (this.pdfViewer.textSearchModule && this.pdfViewer.enableTextSearch) { this.enableItems(this.textSearchItem.parentElement, true); } if (this.pdfViewer.annotationModule && this.pdfViewer.enableStickyNotesAnnotation) { this.enableItems(this.commentItem.parentElement, true); } } } if (this.pdfViewer.toolbarSettings.annotationToolbarItems) { if (this.pdfViewer.toolbarSettings.annotationToolbarItems.length === 0 || !this.pdfViewer.annotationModule || !this.pdfViewer.enableAnnotationToolbar) { this.enableToolbarItem(['AnnotationEditTool'], false); } } if (this.pdfViewer.toolbarSettings.formDesignerToolbarItems) { if (this.pdfViewer.toolbarSettings.formDesignerToolbarItems.length === 0 || !this.pdfViewer.formDesignerModule || !this.pdfViewer.enableFormDesignerToolbar) { this.enableToolbarItem(['FormDesignerEditTool'], false); } } if (!this.pdfViewer.enableDownload) { this.enableDownloadOption(false); } if (!this.pdfViewer.enablePrint) { this.enablePrintOption(false); } } } else { if (this.pdfViewerBase.pageCount === 0) { this.enableItems(this.textSearchItem.parentElement, false); this.enableItems(this.moreOptionItem.parentElement, false); this.enableItems(this.annotationItem.parentElement, false); } else if (this.pdfViewerBase.pageCount > 0) { this.enableItems(this.textSearchItem.parentElement, true); this.enableItems(this.moreOptionItem.parentElement, true); if (this.pdfViewer.annotationModule && this.pdfViewer.enableAnnotation) { this.enableItems(this.annotationItem.parentElement, true); } if (!this.pdfViewer.annotationModule || !this.pdfViewer.enableAnnotationToolbar) { this.enableToolbarItem(['AnnotationEditTool'], false); } this.updateUndoRedoButtons(); if (this.pdfViewer && this.pdfViewer.element && this.pdfViewer.element.id && this.pdfViewer.isAnnotationToolbarOpen) { var annotationId = this.pdfViewer.element.id + '_annotationIcon'; this.annotationToolbarModule.createAnnotationToolbarForMobile(annotationId); } } } }; /** * @private * @returns {void} */ Toolbar.prototype.updateNavigationButtons = function () { if (this.pdfViewer.navigationModule && !this.isPageNavigationToolDisabled) { if (this.pdfViewerBase.pageCount === 0 || (this.pdfViewerBase.currentPageNumber === 1 && this.pdfViewerBase.pageCount === 1)) { this.enableItems(this.firstPageItem.parentElement, false); this.enableItems(this.previousPageItem.parentElement, false); this.enableItems(this.nextPageItem.parentElement, false); this.enableItems(this.lastPageItem.parentElement, false); } else if (this.pdfViewerBase.currentPageNumber === 1 && this.pdfViewerBase.pageCount > 0) { this.enableItems(this.firstPageItem.parentElement, false); this.enableItems(this.previousPageItem.parentElement, false); this.enableItems(this.nextPageItem.parentElement, true); this.enableItems(this.lastPageItem.parentElement, true); } else if (this.pdfViewerBase.currentPageNumber === this.pdfViewerBase.pageCount && this.pdfViewerBase.pageCount > 0) { this.enableItems(this.firstPageItem.parentElement, true); this.enableItems(this.previousPageItem.parentElement, true); this.enableItems(this.nextPageItem.parentElement, false); this.enableItems(this.lastPageItem.parentElement, false); } else if (this.pdfViewerBase.currentPageNumber > 1 && this.pdfViewerBase.currentPageNumber < this.pdfViewerBase.pageCount) { this.enableItems(this.firstPageItem.parentElement, true); this.enableItems(this.previousPageItem.parentElement, true); this.enableItems(this.nextPageItem.parentElement, true); this.enableItems(this.lastPageItem.parentElement, true); } } else { this.enableItems(this.firstPageItem.parentElement, false); this.enableItems(this.previousPageItem.parentElement, false); this.enableItems(this.nextPageItem.parentElement, false); this.enableItems(this.lastPageItem.parentElement, false); this.currentPageBox.readonly = true; } }; /** * @private * @returns {void} */ Toolbar.prototype.updateZoomButtons = function () { if (this.pdfViewer.magnificationModule && !this.isMagnificationToolDisabled && (!Browser.isDevice || this.pdfViewer.enableDesktopMode)) { if (this.pdfViewer.minZoom != null || this.pdfViewer.maxZoom != null) { if (this.pdfViewer.magnificationModule.zoomFactor <= this.pdfViewer.minZoom / 100) { this.enableItems(this.zoomInItem.parentElement, true); this.enableItems(this.zoomOutItem.parentElement, false); } else if (this.pdfViewer.magnificationModule.zoomFactor >= this.pdfViewer.maxZoom / 100) { this.enableItems(this.zoomInItem.parentElement, false); this.enableItems(this.zoomOutItem.parentElement, true); } else { this.enableItems(this.zoomInItem.parentElement, true); this.enableItems(this.zoomOutItem.parentElement, true); } } else { if (this.pdfViewer.magnificationModule.zoomFactor <= 0.1) { this.enableItems(this.zoomInItem.parentElement, true); this.enableItems(this.zoomOutItem.parentElement, false); } else if (this.pdfViewer.magnificationModule.zoomFactor >= 4) { this.enableItems(this.zoomInItem.parentElement, false); this.enableItems(this.zoomOutItem.parentElement, true); } else { this.enableItems(this.zoomInItem.parentElement, true); this.enableItems(this.zoomOutItem.parentElement, true); } } } }; /** * @private * @returns {void} */ Toolbar.prototype.updateUndoRedoButtons = function () { if (this.pdfViewer.annotationModule) { if (this.pdfViewerBase.pageCount > 0) { if (isBlazor()) { this.enableCollectionAvailableInBlazor(this.pdfViewer.annotationModule.actionCollection, 'undo'); this.enableCollectionAvailableInBlazor(this.pdfViewer.annotationModule.redoCollection, 'redo'); } else { if (!isNullOrUndefined(this.undoItem) && !isNullOrUndefined(this.undoItem.parentElement)) { this.enableCollectionAvailable(this.pdfViewer.annotationModule.actionCollection, this.undoItem.parentElement); } if (!isNullOrUndefined(this.redoItem) && !isNullOrUndefined(this.redoItem.parentElement)) { this.enableCollectionAvailable(this.pdfViewer.annotationModule.redoCollection, this.redoItem.parentElement); } } } else { if (isBlazor()) { //this.pdfViewer._dotnetInstance.invokeMethodAsync('DisableUndoRedoButton', null); this.pdfViewerBase.blazorUIAdaptor.disableUndoRedoButton(); } else { this.disableUndoRedoButtons(); } } } else { if (isBlazor()) { //this.pdfViewer._dotnetInstance.invokeMethodAsync('DisableUndoRedoButton', null); this.pdfViewerBase.blazorUIAdaptor.disableUndoRedoButton(); } else { this.disableUndoRedoButtons(); } } }; Toolbar.prototype.enableCollectionAvailable = function (collection, item) { if (collection.length > 0) { this.toolbar.enableItems(item, true); } else { this.toolbar.enableItems(item, false); } }; Toolbar.prototype.enableCollectionAvailableInBlazor = function (collection, item) { if (collection.length > 0) { //this.pdfViewer._dotnetInstance.invokeMethodAsync('UpdateUndoRedoButton', item, true); this.pdfViewerBase.blazorUIAdaptor.updateUndoRedoButton(item, true); } else { // this.pdfViewer._dotnetInstance.invokeMethodAsync('UpdateUndoRedoButton', item, false); this.pdfViewerBase.blazorUIAdaptor.updateUndoRedoButton(item, false); } }; Toolbar.prototype.disableUndoRedoButtons = function () { this.enableItems(this.undoItem.parentElement, false); this.enableItems(this.redoItem.parentElement, false); }; /** * @private * @returns {void} */ Toolbar.prototype.destroy = function () { if (!isBlazor()) { this.unWireEvent(); this.destroyComponent(); if (this.moreDropDown) { this.moreDropDown.destroy(); } if (this.annotationToolbarModule) { this.annotationToolbarModule.destroy(); } if (this.formDesignerToolbarModule) { this.formDesignerToolbarModule.destroy(); } if (this.toolbar) { this.toolbar.destroy(); } if (this.toolbarElement) { this.toolbarElement.parentElement.removeChild(this.toolbarElement); } } }; Toolbar.prototype.destroyComponent = function () { var componentElement = [this.openDocumentItem, this.firstPageItem, t