all files / pdfviewer/annotation/ input-element.js

8.7% Statements 10/115
0% Branches 0/72
28.57% Functions 2/7
8.7% Lines 10/115
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151                                                                                                                                                                                                                                                                                          
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var InputElement = (function () {
        function InputElement(pdfviewer, pdfViewerBase) {
            this.pdfViewer = pdfviewer;
            this.pdfViewerBase = pdfViewerBase;
            this.inputBoxElement = document.createElement('input');
            this.inputBoxElement.addEventListener('focusout', this.onFocusOutInputBox.bind(this));
            this.maxHeight = 24.6;
            this.maxWidth = 151;
            this.fontSize = 16;
            this.isInFocus = false;
            this.inputBoxElement.style.position = 'absolute';
            this.inputBoxElement.style.fontFamily = 'Helvetica';
        }
        InputElement.prototype.editLabel = function (currentPosition, annotation) {
            var pageIndex = this.pdfViewerBase.currentPageNumber - 1;
            var pageDiv = this.pdfViewerBase.getElement('_pageDiv_' + (pageIndex));
            var zoomFactor = this.pdfViewerBase.getZoomFactor();
            this.inputBoxElement.value = annotation.labelContent;
            this.inputBoxElement.select();
            annotation.labelContent = '';
            this.pdfViewer.nodePropertyChange(annotation, {});
            this.inputBoxElement.style.left = ((currentPosition.x) * zoomFactor) + 'px';
            this.inputBoxElement.style.top = ((currentPosition.y) * zoomFactor) + 'px';
            this.inputBoxElement.style.maxHeight = (this.maxHeight * zoomFactor) + 'px';
            this.inputBoxElement.style.maxWidth = (this.maxWidth * zoomFactor) + 'px';
            this.inputBoxElement.style.fontSize = (this.fontSize * zoomFactor) + 'px';
            this.inputBoxElement.style.textAlign = 'center';
            if (annotation && annotation.wrapper && annotation.wrapper.bounds) {
                this.inputBoxElement.style.width = annotation.wrapper.bounds.width ? (annotation.wrapper.bounds.width * zoomFactor) + 1 + 'px' : (this.maxWidth * zoomFactor) + 'px';
                var inputEleWidth = parseFloat(this.inputBoxElement.style.width);
                inputEleWidth = inputEleWidth > (this.maxWidth * zoomFactor) ? (this.maxWidth * zoomFactor) : inputEleWidth;
                if (annotation.wrapper.bounds.left) {
                    this.inputBoxElement.style.left = ((annotation.wrapper.bounds.left + (annotation.wrapper.bounds.width / 2) - (inputEleWidth / (zoomFactor * 2))) * zoomFactor) + 'px';
                }
                if (annotation.wrapper.bounds.top) {
                    if (annotation.shapeAnnotationType === 'Line' || annotation.shapeAnnotationType === 'LineWidthArrowHead' ||
                        annotation.shapeAnnotationType === 'Distance' || annotation.shapeAnnotationType === 'Polygon') {
                        this.inputBoxElement.style.top = ((annotation.wrapper.bounds.top + (annotation.wrapper.bounds.height / 2) - (this.maxHeight)) * zoomFactor) + 'px';
                    }
                    else {
                        this.inputBoxElement.style.top = ((annotation.wrapper.bounds.top + (annotation.wrapper.bounds.height / 2) - (this.maxHeight / 2)) * zoomFactor) + 'px';
                    }
                }
                this.inputBoxElement.maxLength = annotation.labelMaxLength;
                this.inputBoxElement.fontFamily = annotation.fontFamily;
                this.inputBoxElement.style.color = annotation.fontColor;
                this.inputBoxElement.style.border = '1px solid #ffffff00';
                this.inputBoxElement.style.padding = '2px';
                this.inputBoxElement.style.background = annotation.labelFillColor;
            }
            pageDiv.appendChild(this.inputBoxElement);
            this.isInFocus = true;
            this.inputBoxElement.focus();
        };
        InputElement.prototype.onFocusOutInputBox = function () {
            var pageIndex = this.pdfViewerBase.currentPageNumber - 1;
            var pageDiv = this.pdfViewerBase.getElement('_pageDiv_' + (pageIndex));
            var inputEleHeight = parseFloat(this.inputBoxElement.style.height);
            var inputEleWidth = parseFloat(this.inputBoxElement.style.width);
            this.isInFocus = false;
            var selectedAnnotation = this.pdfViewer.selectedItems.annotations[0];
            if (selectedAnnotation) {
                inputEleWidth = ((inputEleWidth - 1) / this.pdfViewerBase.getZoomFactor());
                inputEleHeight = ((inputEleHeight - 1) / this.pdfViewerBase.getZoomFactor());
                selectedAnnotation.labelContent = this.inputBoxElement.value;
                selectedAnnotation.notes = this.inputBoxElement.value;
                if (selectedAnnotation.shapeAnnotationType === 'Rectangle' || selectedAnnotation.shapeAnnotationType === 'Ellipse' || selectedAnnotation.shapeAnnotationType === 'Line'
                    || selectedAnnotation.shapeAnnotationType === 'LineWidthArrowHead') {
                    this.pdfViewer.annotation.shapeAnnotationModule.modifyInCollection('labelContent', pageIndex, selectedAnnotation, null);
                }
                else if (selectedAnnotation.shapeAnnotationType === 'Radius' && selectedAnnotation.measureType) {
                    this.pdfViewer.annotation.measureAnnotationModule.modifyInCollection('labelContent', pageIndex, selectedAnnotation);
                }
                this.pdfViewer.nodePropertyChange(selectedAnnotation, {});
                this.pdfViewer.renderSelector(selectedAnnotation.pageIndex, this.pdfViewer.annotationSelectorSettings);
                var commentsDiv = document.getElementById(this.pdfViewer.selectedItems.annotations[0].annotName);
                if (commentsDiv && commentsDiv.childNodes && this.inputBoxElement.value !== 'label') {
                    if (commentsDiv.childNodes[0].ej2_instances) {
                        commentsDiv.childNodes[0].ej2_instances[0].value = this.inputBoxElement.value;
                    }
                    else if (commentsDiv.childNodes[0].childNodes && commentsDiv.childNodes[0].childNodes[1].ej2_instances) {
                        commentsDiv.childNodes[0].childNodes[1].ej2_instances[0].value = this.inputBoxElement.value;
                    }
                }
            }
            pageDiv.removeChild(this.inputBoxElement);
            var canvass = document.getElementById(this.pdfViewer.element.id + '_annotationCanvas_' + pageIndex);
            this.pdfViewer.renderDrawing(canvass, pageIndex);
        };
        InputElement.prototype.calculateLabelBounds = function (bounds, pageIndex) {
            var labelBounds = {};
            if (bounds) {
                var labelTop = 0;
                var labelLeft = 0;
                var labelWidth = 0;
                var labelHeight = 24.6;
                var labelMaxWidth = 151;
                if (pageIndex === undefined) {
                    pageIndex = this.pdfViewerBase.currentPageNumber - 1;
                }
                var rotation = this.pdfViewerBase.pageSize[parseInt(pageIndex.toString(), 10)].rotation;
                if (bounds.width) {
                    labelWidth = (bounds.width / 2);
                    labelWidth = (labelWidth > 0 && labelWidth < labelMaxWidth) ? labelWidth : labelMaxWidth;
                }
                if (bounds.left) {
                    labelLeft = (bounds.left + (bounds.width / 2) - (labelWidth / 2));
                }
                if (bounds.top) {
                    labelTop = (bounds.top + (bounds.height / 2) - (labelHeight / 2));
                }
                if (rotation === 1 || rotation === 3) {
                    labelBounds = { left: labelLeft, top: labelTop, width: (labelWidth - labelHeight) + (labelWidth / 2),
                        height: (labelHeight * 2) + labelWidth, right: 0, bottom: 0 };
                }
                else {
                    labelBounds = { left: labelLeft, top: labelTop, width: labelWidth, height: labelHeight, right: 0, bottom: 0 };
                }
            }
            return labelBounds;
        };
        InputElement.prototype.calculateLabelBoundsFromLoadedDocument = function (bounds) {
            var labelBounds = {};
            if (bounds) {
                var labelTop = 0;
                var labelLeft = 0;
                var labelWidth = 0;
                var labelHeight = 24.6;
                var labelMaxWidth = 151;
                if (bounds.Width) {
                    labelWidth = (bounds.Width / 2);
                    labelWidth = (labelWidth > 0 && labelWidth < labelMaxWidth) ? labelWidth : labelMaxWidth;
                }
                if (bounds.Left) {
                    labelLeft = (bounds.Left + (bounds.Width / 2) - (labelWidth / 2));
                }
                if (bounds.Top) {
                    labelTop = (bounds.Top + (bounds.Height / 2) - (labelHeight / 2));
                }
                labelBounds = { left: labelLeft, top: labelTop, width: labelWidth, height: labelHeight, right: 0, bottom: 0 };
            }
            return labelBounds;
        };
        return InputElement;
    }());
    exports.InputElement = InputElement;
});