UNPKG

@syncfusion/ej2-documenteditor

Version:

Feature-rich document editor control with built-in support for context menu, options pane and dialogs.

1,180 lines (1,179 loc) 281 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /* eslint-disable */ import { Dictionary } from '../../base/dictionary'; import { WAbstractList } from '../list/abstract-list'; import { WLevelOverride } from '../list/level-override'; import { WSectionFormat, WCharacterFormat, WParagraphFormat, WStyles, WColumnFormat } from '../format/index'; import { Layout } from './layout'; import { Renderer } from './render'; import { createElement, Browser, L10n } from '@syncfusion/ej2-base'; import { Page, Rect, Widget, ListTextElementBox, ParagraphWidget, HeaderFooterWidget, Padding, DropDownFormField, TextFormField, CheckBoxFormField, ShapeElementBox, TextFrame, Footnote, FootnoteElementBox, FootNoteWidget, TextElementBox, ShapeBase, ImageElementBox } from './page'; import { BodyWidget, LineWidget, TableWidget } from './page'; import { HelperMethods, Point } from '../editor/editor-helper'; import { TextHelper } from './text-helper'; import { isNullOrUndefined } from '@syncfusion/ej2-base'; import { CommentReviewPane } from '../index'; import { Zoom } from './zooming'; import { Dialog, createSpinner, showSpinner, hideSpinner } from '@syncfusion/ej2-popups'; import { beforePaneSwitchEvent, keyDownEvent, beforeFormFieldFillEvent, afterFormFieldFillEvent } from '../../base/index'; import { RestrictEditing } from '../restrict-editing/restrict-editing-pane'; import { FormFieldPopUp } from '../dialogs/form-field-popup'; import { TrackChangesPane } from '../track-changes/track-changes-pane'; import { Themes } from '../themes/themes'; import { beforeAutoResize, internalAutoResize } from '../../base/constants'; /** * @private */ var DocumentHelper = /** @class */ (function () { //#endregion function DocumentHelper(owner) { var _this = this; /** * @private */ this.isCompleted = true; /** * @private */ this.isSelectionCompleted = true; /** * @private */ this.scrollbarWidth = 0; /** * @private */ this.isWebPrinting = false; /** * @private */ this.isHeaderFooter = false; /** * @private */ this.currentPage = undefined; this.selectionStartPageIn = undefined; this.selectionEndPageIn = undefined; /** * @private */ this.fieldStacks = []; /** * @private */ this.showRevision = false; /** * @private */ this.splittedCellWidgets = []; /** * @private */ this.tableLefts = []; /** * @private */ this.tapCount = 0; this.timer = -1; this.isTimerStarted = false; /** * @private */ this.isFirstLineFitInShiftWidgets = false; /** * @private */ this.preZoomFactor = 0; /** * @private */ this.preDifference = -1; /** * @private */ this.fieldEndParagraph = undefined; /** * @private */ this.fieldToLayout = undefined; /** * @private */ this.backgroundColor = '#FFFFFF'; // Event /** * @private */ this.isMouseDown = false; this.isMouseEntered = false; this.scrollMoveTimer = 0; /** * @private */ this.isSelectionChangedOnMouseMoved = false; /** * @private */ this.isControlPressed = false; /** * @private */ this.isTouchInput = false; /** * @private */ this.isTouchMoved = false; /** * @private */ this.useTouchSelectionMark = false; /** * @private */ this.touchDownOnSelectionMark = 0; /** * @private */ this.isComposingIME = false; /** * @private */ this.lastComposedText = ''; /** * @private */ this.isCompositionStart = false; /** * @private */ this.isCompositionUpdated = false; /** * @private */ this.isCompositionCanceled = false; /** * @private */ this.isCompositionEnd = false; /** * @private */ this.prefix = ''; /** * @private */ this.suffix = ''; /** * @private */ this.fields = []; /** * @private */ this.heightInfoCollection = {}; /** * @private */ this.defaultTabWidth = 36; /** * @private */ this.dontUseHtmlParagraphAutoSpacing = false; /** * @private */ this.allowSpaceOfSameStyleInTable = false; /** * @private */ this.alignTablesRowByRow = false; /** * @private */ this.compatibilityMode = 'Word2013'; /** * @private */ this.lists = []; /** * @private */ this.comments = []; /** * @private */ this.authors = new Dictionary(); /** * @private */ this.revisionsInternal = new Dictionary(); /** * @private */ this.commentUserOptionId = 1; /** * @private */ this.abstractLists = []; /** * @private */ this.styles = new WStyles(); /** * @private */ this.stylesMap = new Dictionary(); /** * @private */ this.preDefinedStyles = undefined; /** * @private */ this.isRowOrCellResizing = false; /** * @private */ this.endBookmarksUpdated = []; /** * @private */ this.formFields = []; this.isMouseDownInFooterRegion = false; this.pageFitTypeIn = 'None'; /** * @private */ this.fieldCollection = []; /** * @private */ this.isPageField = false; /** * @private */ this.mouseDownOffset = new Point(0, 0); this.zoomFactorInternal = 1; /** * If movecaretposition is 1, Home key is pressed * If moveCaretPosition is 2, End key is pressed * * @private */ this.moveCaretPosition = 0; /** * @private */ this.isTextInput = false; /** * @private */ this.isTextFormEmpty = false; /** * @private */ this.isScrollHandler = false; /** * @private */ this.triggerElementsOnLoading = false; /** * @private */ this.triggerSpellCheck = false; //Document Protection Properties Starts /** * preserve the format * * @private */ this.restrictFormatting = false; /** * preserve the document protection type either readonly or no protection * * @private */ this.protectionType = 'NoProtection'; /** * Preserve the password protection is enforced or not * * @private */ this.isDocumentProtected = false; /** * preserve the hash value of password * * @private */ this.hashValue = ''; /** * @private */ this.saltValue = ''; /** * @private */ this.userCollection = []; /** * @private */ this.cachedPages = []; /** * @private */ this.skipScrollToPosition = false; /** * @private */ this.isIosDevice = false; /** * @private */ this.isMobileDevice = false; /** * @private */ this.isFormFilling = false; /** * @private */ this.themes = new Themes(); /** * @private */ this.hasThemes = false; /** * @private */ this.footnotes = new Footnote(); /** * @private */ this.endnotes = new Footnote(); /** * @private */ this.isFootnoteWidget = false; /** * @private */ this.isDragStarted = false; /** * @private */ this.isMouseDownInSelection = false; /** * @private */ this.isBookmarkInserted = true; this.isAutoResizeCanStart = false; /** * @private * @param {TextEvent} event - Specifies text event. * @returns {void} */ this.onTextInput = function (event) { if (!_this.isComposingIME) { event.preventDefault(); var text = event.data; _this.owner.editor.handleTextInput(text); } }; //#region Composition Event /** * Fires when composition starts. * * @private * @returns {void} */ this.compositionStart = function () { if (!Browser.isDevice && !_this.owner.isReadOnlyMode) { _this.isComposingIME = true; _this.positionEditableTarget(); if (_this.owner.editorHistory) { _this.owner.editor.initComplexHistory('IMEInput'); } } _this.isCompositionStart = true; }; /** * Fires on every input during composition. * * @private * @returns {void} */ this.compositionUpdated = function () { if (_this.isComposingIME && !_this.owner.isReadOnlyMode) { setTimeout(function () { _this.owner.editor.insertIMEText(_this.getEditableDivTextContent(), true); }, 0); } _this.isCompositionUpdated = true; }; /** * Fires when user selects a character/word and finalizes the input. * * @private * @param {CompositionEvent} event - Specifies text compisition event. * @returns {void} */ this.compositionEnd = function (event) { if (_this.isComposingIME && !_this.owner.isReadOnlyMode) { var text = _this.getEditableDivTextContent(); if (text !== '') { _this.owner.editor.insertIMEText(text, false); } _this.isComposingIME = false; _this.lastComposedText = ''; _this.iframe.setAttribute('style', 'pointer-events:none;position:absolute;left:' + _this.owner.viewer.containerLeft + 'px;top:' + _this.owner.viewer.containerTop + 'px;outline:none;background-color:transparent;width:0px;height:0px;overflow:hidden'); _this.editableDiv.innerHTML = ''; if (_this.owner.editorHistory) { if (text !== '') { _this.owner.editor.isSkipOperationsBuild = true; } _this.owner.editorHistory.updateComplexHistory(); if (text === '') { //When the composition in live. The Undo operation will terminate the composition and empty text will be return from text box. //At that time the the history should be updated. Undo the operation and clear the redo stack. This undo operation will not be saved for redo operation. _this.owner.editor.isSkipOperationsBuild = true; _this.owner.editorHistory.undo(); _this.owner.editorHistory.redoStack.pop(); } _this.owner.editor.isSkipOperationsBuild = false; } } event.preventDefault(); _this.isCompositionUpdated = false; _this.isCompositionEnd = true; }; /* eslint-disable @typescript-eslint/no-explicit-any */ this.onImageResizer = function (args) { if (!isNullOrUndefined(_this.owner) && !isNullOrUndefined(_this.owner.imageResizerModule) && _this.owner.imageResizerModule.isImageResizerVisible && _this.owner.imageResizerModule.isImageResizing) { if (args instanceof MouseEvent) { _this.onMouseUpInternal(args); } else if (args instanceof TouchEvent) { _this.onTouchUpInternal(args); } } if (_this.scrollMoveTimer) { _this.isMouseEntered = true; clearInterval(_this.scrollMoveTimer); } }; /* eslint-enable @typescript-eslint/no-explicit-any */ /** * @private * @param {KeyboardEvent} event - Specifies keyboard event * @returns {void} */ this.onKeyPressInternal = function (event) { var key = event.which || event.keyCode; _this.triggerElementsOnLoading = false; var ctrl = (event.ctrlKey || event.metaKey) ? true : ((key === 17) ? true : false); // ctrl detection var alt = event.altKey ? event.altKey : ((key === 18) ? true : false); // alt key detection if (Browser.isIE && alt && ctrl) { ctrl = false; } // tslint:disable-next-line:max-line-length if (ctrl && event.key === 'v' || ctrl && event.key === 'a' || (ctrl || (_this.isControlPressed && Browser.isIE)) && event.key === 'p') { if (Browser.isIE) { _this.isControlPressed = false; } return; } if (!_this.owner.isReadOnlyMode || (_this.selection && _this.selection.isInlineFormFillMode())) { var key_1 = event.keyCode || event.charCode; var char = ''; if (key_1) { char = String.fromCharCode(key_1); } else if (event.key) { char = event.key; } if (char !== ' ' && char !== '\r' && char !== '\b' && char !== String.fromCharCode(27) && !ctrl) { _this.owner.editorModule.handleTextInput(char); } else if (char === ' ') { _this.triggerSpellCheck = true; _this.owner.editorModule.handleTextInput(' '); _this.triggerSpellCheck = false; } event.preventDefault(); } _this.owner.focusIn(); }; /** * @private * @param {KeyboardEvent} event - Specifies keyboard event * @returns {void} */ this.onTextInputInternal = function (event) { if (!_this.owner.isReadOnlyMode) { _this.owner.editorModule.onTextInputInternal(); } else { _this.editableDiv.innerText = ''; } }; /** * Fired on paste. * * @private * @param {ClipboardEvent} event - Specifies clipboard event. * @returns {void} */ this.onPaste = function (event) { if ((!_this.owner.isReadOnlyMode && _this.owner.editor.canEditContentControl) || _this.selection.isInlineFormFillMode()) { _this.owner.editorModule.pasteInternal(event); } _this.editableDiv.innerText = ''; event.preventDefault(); }; /** * Fires when editable div loses focus. * * @private * @returns {void} */ this.onFocusOut = function () { if (!isNullOrUndefined(_this.selection)) { if (_this.owner.contextMenuModule && _this.owner.contextMenuModule.contextMenuInstance && _this.owner.contextMenuModule.contextMenuInstance.element.style.display === 'block') { return; } _this.selection.hideCaret(); } }; /** * Updates focus to editor area. * * @private * @returns {void} */ this.updateFocus = function () { if (!isNullOrUndefined(_this.currentSelectedComment) && !_this.owner.commentReviewPane.commentPane.isEditMode) { if (_this.owner.commentReviewPane && _this.owner.commentReviewPane.commentPane.isEditMode) { _this.owner.commentReviewPane.commentPane.selectComment(_this.currentSelectedComment); } _this.selection.hideCaret(); return; } if (_this.selection && !(_this.isMobileDevice && _this.owner.isReadOnly)) { if (navigator !== undefined && !Browser.isDevice && !Browser.isIE && !navigator.userAgent.match('Edge') && !isNullOrUndefined(_this.iframe)) { _this.iframe.focus(); } if (!isNullOrUndefined(_this.editableDiv)) { _this.editableDiv.focus(); } _this.selection.showCaret(); } }; /** * Fires on scrolling. * * @returns {void} */ this.scrollHandler = function () { if (_this.scrollTimer) { clearTimeout(_this.scrollTimer); } _this.clearContent(); _this.isScrollHandler = true; if (!Browser.isDevice && !_this.isComposingIME) { _this.iframe.style.top = _this.owner.viewer.containerTop + 'px'; _this.iframe.style.left = _this.owner.viewer.containerLeft + 'px'; } _this.owner.viewer.updateScrollBars(); var vtHeight = _this.owner.viewer.containerTop + _this.visibleBounds.height - (_this.owner.viewer.padding.top + _this.owner.viewer.padding.bottom); if (vtHeight > _this.pageContainer.offsetHeight) { _this.viewerContainer.scrollTop = _this.owner.viewer.containerTop - (vtHeight - _this.pageContainer.offsetHeight); } if (_this.owner.viewer instanceof PageLayoutViewer && !isNullOrUndefined(_this.owner)) { _this.owner.fireViewChange(); } _this.isScrollHandler = false; _this.scrollTimer = setTimeout(function () { if (!_this.isScrollHandler && !isNullOrUndefined(_this.owner) && _this.owner.isSpellCheck) { _this.isScrollToSpellCheck = true; _this.owner.viewer.updateScrollBars(); } }, 200); }; /** * Fires when the window gets resized. * * @private * @returns {void} */ this.onWindowResize = function () { if (_this.resizeTimer) { clearTimeout(_this.resizeTimer); } _this.resizeTimer = setTimeout(function () { if (!isNullOrUndefined(_this.owner) && !isNullOrUndefined(_this.owner.element)) { _this.updateViewerSize(); _this.clearContent(); _this.owner.viewer.updateScrollBars(); if (!isNullOrUndefined(_this.selection)) { _this.selection.updateCaretPosition(); } _this.updateTouchMarkPosition(); if (_this.owner.contextMenuModule && _this.owner.contextMenuModule.contextMenuInstance) { _this.owner.contextMenuModule.contextMenuInstance.close(); } if (_this.resizeTimer) { clearTimeout(_this.resizeTimer); } } }, 200); }; /** * @private * @param {MouseEvent} event - Specified mouse event. * @returns {void} */ this.onContextMenu = function (event) { if (_this.owner.contextMenuModule) { if (_this.isMouseDown) { _this.isMouseDown = false; } _this.owner.contextMenuModule.onContextMenuInternal(event); _this.updateFocus(); } }; /** * Called on mouse down. * * @private * @param {MouseEvent} event - Specifies mouse event. * @returns {void} */ this.onMouseDownInternal = function (event) { var target = event.target; _this.owner.focusIn(); if ((!isNullOrUndefined(target) && target !== _this.viewerContainer) || _this.isTouchInput || event.offsetX > (_this.visibleBounds.width - (_this.visibleBounds.width - _this.viewerContainer.clientWidth)) || event.offsetY > (_this.visibleBounds.height - (_this.visibleBounds.height - _this.viewerContainer.clientHeight))) { return; } _this.isFootnoteWidget = false; if (!isNullOrUndefined(_this.selection)) { _this.updateCursor(event); if (_this.formFillPopup) { _this.formFillPopup.hidePopup(); } if (_this.isLeftButtonPressed(event) && !_this.owner.isReadOnlyMode && _this.owner.enableImageResizerMode && !isNullOrUndefined(_this.owner.imageResizerModule.selectedResizeElement)) { if (_this.selection.isInShape) { var textFram = _this.owner.selection.getCurrentTextFrame(); var shape = textFram.containerShape; _this.selection.selectShape(shape); } _this.owner.imageResizerModule.isImageResizing = true; } event.preventDefault(); if (!_this.isTouchInput) { _this.selection.hideCaret(); } var cursorPoint = new Point(event.offsetX, event.offsetY); var touchPoint = _this.owner.viewer.findFocusedPage(cursorPoint, true, true); _this.mouseDownOffset.x = touchPoint.x; _this.mouseDownOffset.y = touchPoint.y; _this.isMouseDownInFooterRegion = _this.selection.isCursorInsidePageRect(cursorPoint, _this.currentPage) && _this.selection.isCursorInFooterRegion(cursorPoint, _this.currentPage); _this.isSelectionChangedOnMouseMoved = false; if (!_this.owner.isReadOnlyMode && (_this.owner.editorModule.tableResize.isInCellResizerArea(touchPoint) || _this.owner.editorModule.tableResize.isInRowResizerArea(touchPoint))) { _this.selection.hideCaret(); _this.isMouseDown = true; _this.isSelectionChangedOnMouseMoved = false; if (_this.isLeftButtonPressed(event)) { _this.owner.editorModule.tableResize.startingPoint.x = touchPoint.x; _this.owner.editorModule.tableResize.startingPoint.y = touchPoint.y; _this.owner.editorModule.tableResize.handleResize(touchPoint); } return; } if (event.ctrlKey) { _this.isControlPressed = true; } if (_this.owner.selection.isEmpty) { _this.useTouchSelectionMark = false; } var widget = _this.getLineWidget(touchPoint); if (event.which === 3 && !_this.owner.selection.isEmpty && _this.selection.checkCursorIsInSelection(widget, touchPoint)) { event.preventDefault(); return; } if (_this.owner && _this.owner.documentEditorSettings && _this.owner.documentEditorSettings.allowDragAndDrop && !_this.owner.selection.isEmpty && _this.selection.checkCursorIsInSelection(widget, touchPoint)) { _this.isMouseDownInSelection = true; } _this.isTouchInput = false; _this.isMouseDown = true; _this.updateFocus(); /* eslint-disable @typescript-eslint/indent */ _this.timer = setTimeout(function () { _this.tapCount++; if (_this.tapCount > 1) { _this.tapCount = 1; } if (!_this.isScrollHandler && !isNullOrUndefined(_this.owner) && _this.owner.isSpellCheck) { _this.isScrollToSpellCheck = true; _this.owner.viewer.updateScrollBars(); } }, 100); } }; /** * Called on mouse move. * * @private * @param {MouseEvent} event - Specified mouse event. * @returns {void} */ this.onMouseMoveInternal = function (event) { if (!isNullOrUndefined(event.target) && event.target !== _this.viewerContainer) { return; } event.preventDefault(); if (!isNullOrUndefined(_this.selection)) { //For image Resizing if (!_this.owner.isReadOnlyMode && _this.owner.enableImageResizerMode && _this.owner.imageResizerModule.isImageResizing) { if (!_this.owner.imageResizerModule.isImageMoveToNextPage) { _this.owner.imageResizerModule.handleImageResizingOnMouse(event); } return; } var cursorPoint = new Point(event.offsetX, event.offsetY); var touchPoint = _this.owner.viewer.findFocusedPage(cursorPoint, !_this.owner.enableHeaderAndFooter); var widget = _this.getLineWidget(touchPoint); if (_this.isMouseDown) { if (!isNullOrUndefined(_this.currentPage)) { var xPosition = touchPoint.x; var yPosition = touchPoint.y; if (!_this.owner.isReadOnlyMode && _this.isRowOrCellResizing) { var table = _this.owner.editorModule.tableResize.currentResizingTable; var startPosition = _this.selection.setPositionForBlock(table, true); var endPosition = _this.selection.setPositionForBlock(table, false); if (!(_this.owner.documentHelper.isDocumentProtected) || _this.selection.checkSelectionIsAtEditRegion(startPosition, endPosition)) { _this.owner.editorModule.tableResize.handleResizing(touchPoint); } } else { if (!_this.isDragStarted && _this.isMouseDownInSelection && _this.isLeftButtonPressed(event) && !_this.owner.selection.isEmpty && _this.selection.checkCursorIsInSelection(widget, touchPoint)) { _this.isDragStarted = true; _this.isMouseDownInSelection = false; if (_this.selection.isForward) { _this.dragStartParaInfo = _this.selection.getParagraphInfo(_this.selection.start); _this.dragEndParaInfo = _this.selection.getParagraphInfo(_this.selection.end); } else { _this.dragStartParaInfo = _this.selection.getParagraphInfo(_this.selection.end); _this.dragEndParaInfo = _this.selection.getParagraphInfo(_this.selection.start); } _this.selection.caret.classList.remove("e-de-cursor-animation"); } if (!(_this.isTouchInput || _this.isSelectionChangedOnMouseMoved || _this.touchDownOnSelectionMark > 0 || _this.isDragStarted)) { _this.updateTextPositionForSelection(touchPoint, 1); } if (_this.isLeftButtonPressed(event) && !_this.isDragStarted) { event.preventDefault(); var touchY = yPosition; var textPosition = _this.owner.selection.end; var touchPoint_1 = new Point(xPosition, touchY); if (!_this.owner.enableImageResizerMode || !_this.owner.imageResizerModule.isImageResizerVisible || _this.owner.imageResizerModule.isShapeResize) { _this.isCompleted = false; _this.owner.selection.moveTextPosition(touchPoint_1, textPosition); } _this.isSelectionChangedOnMouseMoved = true; } if (_this.isDragStarted && _this.isLeftButtonPressed(event)) { _this.autoScrollOnSelection(cursorPoint); _this.selection.updateTextPosition(widget, touchPoint); } } } _this.selection.checkForCursorVisibility(); } if (!_this.isRowOrCellResizing && !_this.isSelectionChangedOnMouseMoved) { _this.updateCursor(event); } if (_this.isRowOrCellResizing) { _this.selection.hideCaret(); } } }; /** * @private * @param {MouseEvent} event - Specifies mouse event * @returns {void} */ this.onMouseLeaveInternal = function (event) { event.preventDefault(); var cursorPoint = new Point(event.offsetX, event.offsetY); if (_this.isMouseDown) { var viewerTop = _this.viewerContainer.scrollTop; clearInterval(_this.scrollMoveTimer); if (event.offsetY + viewerTop > viewerTop) { _this.scrollMoveTimer = setInterval(function () { _this.scrollForwardOnSelection(cursorPoint); }, 100); } else { _this.scrollMoveTimer = setInterval(function () { _this.scrollBackwardOnSelection(cursorPoint); }, 100); } if (_this.isMouseEntered) { _this.isMouseEntered = false; } } if (_this.isDragStarted) { _this.selection.hideCaret(); if (_this.scrollMoveTimer) { clearInterval(_this.scrollMoveTimer); _this.scrollMoveTimer = 0; } } }; /** * @private * @returns {void} */ this.onMouseEnterInternal = function (event) { if (!_this.isMouseEntered) { _this.owner.viewer.updateScrollBars(); } _this.isMouseEntered = true; if (_this.scrollMoveTimer) { clearInterval(_this.scrollMoveTimer); } if (!_this.isLeftButtonPressed(event) && _this.isDragStarted) { if (!_this.selection.caret.classList.contains("e-de-cursor-animation")) { _this.selection.caret.classList.add("e-de-cursor-animation"); } _this.isDragStarted = false; } if (!_this.isLeftButtonPressed(event) && _this.isMouseDown) { _this.onMouseUpInternal(event); } }; /** * Fired on double tap. * * @private * @param {MouseEvent} event - Specifies mouse event. * @returns {void} */ this.onDoubleTap = function (event) { _this.owner.focusIn(); if (!isNullOrUndefined(event.target) && event.target !== _this.viewerContainer) { return; } if (!isNullOrUndefined(_this.selection)) { _this.isTouchInput = false; var cursorPoint = new Point(event.offsetX, event.offsetY); var touchPoint = _this.owner.viewer.findFocusedPage(cursorPoint, true); if (_this.selection.checkAndEnableHeaderFooter(cursorPoint, _this.owner.viewer.findFocusedPage(cursorPoint, true))) { return; } var widget = _this.getLineWidget(touchPoint); var formField = _this.selection.getHyperLinkFieldInCurrentSelection(widget, touchPoint, true); if (isNullOrUndefined(formField)) { formField = _this.selection.getCurrentFormField(); } if (!_this.isDocumentProtected && _this.owner.enableFormField) { var formatType = _this.selection.getFormFieldType(formField); if (formatType) { if (formatType.toString() !== '') { _this.selection.selectField(formField); } switch (formatType) { case 'Text': _this.owner.textFormFieldDialogModule.show(); break; case 'CheckBox': _this.owner.checkBoxFormFieldDialogModule.show(); break; case 'DropDown': _this.owner.dropDownFormFieldDialogModule.show(); break; } } } else if (_this.isDocumentProtected && formField && formField.formFieldData instanceof TextFormField && formField.formFieldData.type === 'Text') { _this.selection.selectField(); } var startPosition = _this.selection.start.clone(); var endPosition = _this.selection.end.clone(); var inlineObj = startPosition.currentWidget.getInline(startPosition.offset, 0); var inline = inlineObj.element; if (_this.owner.layoutType === 'Pages') { if (inline instanceof FootnoteElementBox) { if (inline.footnoteType === 'Footnote') { var footnotes = _this.currentPage.footnoteWidget; var i = void 0; for (i = 0; i <= footnotes.bodyWidgets.length; i++) { var footnoteText = (footnotes.bodyWidgets[i]).footNoteReference; if (inline.text === footnoteText.text) { break; } } startPosition.setPositionParagraph(footnotes.bodyWidgets[i].childWidgets[0].childWidgets[0], 0); endPosition.setPositionParagraph(footnotes.bodyWidgets[i].childWidgets[0].childWidgets[0], 0); _this.selection.selectRange(startPosition, endPosition); } else { var endnotes = _this.pages[_this.pages.length - 1].endnoteWidget; var i = void 0; if (!isNullOrUndefined(endnotes)) { for (i = 0; i <= endnotes.childWidgets.length; i++) { var endnoteText = (endnotes.bodyWidgets[i]).footNoteReference; if (inline.text === endnoteText.text) { break; } } } startPosition.setPositionParagraph(endnotes.bodyWidgets[i].childWidgets[0].childWidgets[0], 0); endPosition.setPositionParagraph(endnotes.bodyWidgets[i].childWidgets[0].childWidgets[0], 0); _this.selection.selectRange(startPosition, endPosition); } } else { if (inline instanceof TextElementBox && (_this.selection.isinEndnote || _this.selection.isinFootnote)) { _this.selection.footnoteReferenceElement(startPosition, endPosition, inline); } } } if (_this.selection.isEmpty && !isNullOrUndefined(_this.currentPage) && !isNullOrUndefined(_this.owner.selection.start)) { _this.owner.selection.selectCurrentWord(); _this.selection.checkForCursorVisibility(); _this.tapCount = 2; } } }; /** * Called on mouse up. * * @private * @param {MouseEvent} event - Specifies mouse event. * @return {void} */ /* eslint-disable */ this.onMouseUpInternal = function (event) { if (!isNullOrUndefined(event.target) && event.target !== _this.viewerContainer) { return; } event.preventDefault(); _this.isListTextSelected = false; var cursorPoint = new Point(event.offsetX, event.offsetY); var touchPoint = _this.owner.viewer.findFocusedPage(cursorPoint, true); if (!isNullOrUndefined(_this.selection)) { var tapCount = 1; if (!Browser.isIE) { if (event.detail > 2) { tapCount = event.detail; } } else { tapCount = _this.tapCount; } if (_this.isRowOrCellResizing) { _this.owner.editorModule.tableResize.updateResizingHistory(touchPoint); } if (_this.isMouseDown && !_this.isSelectionChangedOnMouseMoved && !isNullOrUndefined(_this.currentPage) && !isNullOrUndefined(_this.owner.selection.start) && (!_this.owner.enableImageResizerMode || !_this.owner.imageResizerModule.isImageResizing)) { if (_this.touchDownOnSelectionMark === 0 && !_this.isRowOrCellResizing) { var isShiftKeyPressed = event.shiftKey; if (isShiftKeyPressed) { var textPosition = _this.owner.selection.end; _this.owner.selection.moveTextPosition(touchPoint, textPosition); } else { _this.updateTextPositionForSelection(touchPoint, tapCount); } if (Browser.isIE && tapCount === 2) { _this.selection.checkAndEnableHeaderFooter(cursorPoint, touchPoint); } } _this.selection.checkForCursorVisibility(); if (!isNullOrUndefined(_this.currentSelectedComment) && _this.owner.commentReviewPane && !_this.owner.commentReviewPane.commentPane.isEditMode) { _this.currentSelectedComment = undefined; } } var isCtrlkeyPressed = _this.isIosDevice ? event.metaKey : event.ctrlKey; if (!isNullOrUndefined(_this.currentPage) && !isNullOrUndefined(_this.owner.selection.start) && (_this.owner.selection.isEmpty || _this.owner.selection.isImageSelected) && (((isCtrlkeyPressed && _this.owner.useCtrlClickToFollowHyperlink || !_this.owner.useCtrlClickToFollowHyperlink) && _this.isLeftButtonPressed(event) === true))) { _this.selection.navigateHyperLinkOnEvent(touchPoint, false); } if (_this.isMouseDown && _this.isLeftButtonPressed(event) && _this.isDocumentProtected && _this.protectionType === 'FormFieldsOnly' && _this.selection) { var widget = _this.getLineWidget(touchPoint); var formField = _this.selection.getHyperLinkFieldInCurrentSelection(widget, touchPoint, true); if (isNullOrUndefined(formField)) { formField = _this.selection.getCurrentFormField(true); } if (formField && formField.formFieldData && formField.formFieldData.enabled && !_this.selection.isInlineFormFillMode(formField)) { var data = { 'fieldName': formField.formFieldData.name }; if (formField.formFieldData instanceof TextFormField) { data.value = formField.resultText; } else if (formField.formFieldData instanceof CheckBoxFormField) { data.value = formField.formFieldData.checked; } else { data.value = formField.formFieldData.selectedIndex; } data.isCanceled = false; if (_this.owner.documentEditorSettings.formFieldSettings.formFillingMode === 'Popup' && _this.selection.previousSelectedFormField !== _this.selection.getCurrentFormField()) { _this.owner.trigger(beforeFormFieldFillEvent, data); } else { _this.owner.trigger(beforeFormFieldFillEvent, data); } if (!data.isCanceled) { if (_this.owner.documentEditorSettings.formFieldSettings.formFillingMode === 'Popup' && !(formField.formFieldData instanceof CheckBoxFormField) || (formField.formFieldData instanceof TextFormField && !(formField.formFieldData.type === 'Text')) || formField.formFieldData instanceof DropDownFormField) { _this.formFillPopup.showPopUp(formField); } else { _this.owner.editor.toggleCheckBoxFormField(formField); data.value = formField.formFieldData.checked; data.isCanceled = false; _this.owner.trigger(afterFormFieldFillEvent, data); } } } if (!formField && _this.isFormFillProtectedMode) { _this.selection.navigateToNextFormField(); } } else if (_this.isMouseDown) { if (_this.formFields.length > 0) { var formField = _this.selection.getCurrentFormField(true); if (formField && formField.formFieldData instanceof TextFormField) { _this.selection.selectField(); } else if (_this.isLeftButtonPressed(event) && formField && formField.formFieldData instanceof DropDownFormField) { var offset = formField.line.getOffset(formField, 0); var point = _this.selection.getPhysicalPositionInternal(formField.line, offset, false); _this.selection.selectInternal(formField.line, formField, 0, point); } } if (_this.isSelectionChangedOnMouseMoved) { _this.selection.fireSelectionChanged(true); } } if (!_this.owner.isReadOnlyMode && _this.isSelectionInListText(touchPoint)) { _this.selection.selectListText(); } if (!_this.owner.isReadOnlyMode && _this.owner.enableImageResizerMode && _this.owner.imageResizerModule.isImageResizing) { _this.owner.imageResizerModule.mouseUpInternal(); _this.scrollToPosition(_this.owner.selection.start, _this.owner.selection.end); _this.owner.imageResizerModule.isImageResizing = false; } if (_this.owner.enableImageResizerMode && _this.owner.imageResizerModule.isImageResizerVisible && !isNullOrUndefined(_this.selection.caret)) { _this.selection.caret.style.display = 'none'; } if (_this.isDragStarted) { _this.moveSelectedContent(); } if (_this.isMouseDown) { _this.updateFocus(); } _this.isMouseDownInSelection = false; _this.isMouseDown = false; _this.isFootnoteWidget = false; _this.isSelectionChangedOnMouseMoved = false; _this.isTouchInput = false; _this.useTouchSelectionMark = true; _this.isControlPressed = false; if (_this.isListTextSelected) { _this.selection.hideCaret(); } if (_this.owner.enableImageResizerMode) { var imageResizer = _this.owner.imageResizerModule; imageResizer.isImageResizing = false; imageResizer.isImageMoveToNextPage = false; imageResizer.leftValue = undefined; imageResizer.topValue = undefined; } _this.isMouseDownInFooterRegion = false; } if (_this.selection) { _this.selection.isCellPrevSelected = false; } }; /** * Fired on touch start. * * @private * @param {TouchEvent} event - Specifies touch event. * @returns {void} */ this.onTouchStartInternal = function (event) { if (_this.selection) { _this.isTouchMoved = false; _this.isCompositionStart = false; _this.isCompositionEnd = false; _this.isCompositionUpdated = false; _this.isCompositionCanceled = true; _this.isTouchInput = true; if (_this.isTimerStarted) { if (_this.tapCount === 1) { _this.tapCount = 2; } else { _this.tapCount = 3; _this.isTimerStarted = false; } } else { _this.isTimerStarted = true; _this.tapCount = 1; } if (event.touches.length === 1) { _this.zoomX = event.touches[0].clientX; _this.zoomY = event.touches[0].clientY; if (_this.owner.selection.isEmpty) { _this.useTouchSelectionMark = false; } _this.isMouseDown = true; _this.isSelectionChangedOnMouseMoved = false; var point = void 0; if (_this.isMouseDown) { point = _this.getTouchOffsetValue(event); } point = _this.owner.viewer.findFocusedPage(point, true, true); if (_this.owner.enableImageResizerMode) { var resizeObj = _this.owner.imageResizerModule.getImagePointOnTouch(point); _this.owner.imageResizerModule.selectedResizeElement = resizeObj.selectedElement; }