all files / pdfviewer/organize-pdf/organize-core/ organize-event-handler.js

15.43% Statements 27/175
0% Branches 0/119
5.88% Functions 1/17
15.43% Lines 27/175
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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241                                                                                                                                                                                                                                                                                                                                                                                                                                            
define(["require", "exports", "@syncfusion/ej2-base", "./tile-interaction", "./organize-toolbar", "./organize-importaction"], function (require, exports, ej2_base_1, tile_interaction_1, organize_toolbar_1, organize_importaction_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function initEventListeners() {
        this.boundOnTileAreaMouseDown = onTileAreaMouseDown.bind(this);
        this.boundOnTileAreaKeyDown = onTileAreaKeyDown.bind(this);
        this.boundOnTileAreaKeyUp = onTileAreaKeyUp.bind(this);
        this.boundPageOrganizerOnScroll = pageOrganizerOnScroll.bind(this);
        this.dialogDivElement.addEventListener('wheel', this.boundPageOrganizerOnScroll);
        this.tileAreaDiv.addEventListener('mousedown', this.boundOnTileAreaMouseDown);
        document.addEventListener('keydown', this.boundOnTileAreaKeyDown);
        document.addEventListener('keyup', this.boundOnTileAreaKeyUp);
    }
    exports.initEventListeners = initEventListeners;
    function removeEventListeners() {
        if (!ej2_base_1.isNullOrUndefined(this.dialogDivElement)) {
            this.dialogDivElement.removeEventListener('wheel', this.boundPageOrganizerOnScroll);
        }
        if (!ej2_base_1.isNullOrUndefined(this.tileAreaDiv)) {
            this.tileAreaDiv.removeEventListener('mousedown', this.boundOnTileAreaMouseDown);
        }
        document.removeEventListener('keydown', this.boundOnTileAreaKeyDown);
        document.removeEventListener('keyup', this.boundOnTileAreaKeyUp);
    }
    exports.removeEventListeners = removeEventListeners;
    function pageOrganizerOnScroll(event) {
        if (this.ctrlKey) {
            event.preventDefault();
            var imageZoom = this.getImageZoomValue();
            var imageZoomMin = this.getImageZoomMin();
            var imageZoomMax = this.getImageZoomMax();
            if (event.deltaY < 0 && (imageZoom < imageZoomMax)) {
                if (imageZoom + this.pageZoomSliderStep < imageZoomMax) {
                    this.handlePageZoomChange(imageZoom + this.pageZoomSliderStep, imageZoom);
                }
                else if (imageZoom + this.pageZoomSliderStep > imageZoomMax && imageZoom !== imageZoomMax) {
                    this.handlePageZoomChange(imageZoomMax, imageZoom);
                }
            }
            else if (event.deltaY > 0 && (imageZoom > imageZoomMin)) {
                if (imageZoom - this.pageZoomSliderStep > imageZoomMin) {
                    this.handlePageZoomChange(imageZoom - this.pageZoomSliderStep, imageZoom);
                }
                else if (imageZoom - this.pageZoomSliderStep < imageZoomMin && imageZoom !== imageZoomMin) {
                    this.handlePageZoomChange(imageZoomMin, imageZoom);
                }
            }
        }
    }
    exports.pageOrganizerOnScroll = pageOrganizerOnScroll;
    function onTileAreaMouseDown(event) {
        var _this = this;
        if (event.target && event.target.parentElement && event.target.parentElement.firstElementChild &&
            event.target.parentElement.firstElementChild.classList.contains('e-pv-organize-tile-checkbox')) {
            this.isClickedOnCheckBox = true;
        }
        else {
            this.isClickedOnCheckBox = false;
        }
        if (event.target.closest('.e-pv-organize-anchor-node')) {
            var targetTile = event.target;
            var tiles = Array.from(this.tileAreaDiv.children);
            if (this.shiftKey && this.startTile) {
                var currentIndex_1 = Array.from(this.tileAreaDiv.children).indexOf(targetTile.closest('.e-pv-organize-anchor-node'));
                if (this.startTile) {
                    var startIndex_1 = Array.from(this.tileAreaDiv.children).indexOf(this.startTile.closest('.e-pv-organize-anchor-node'));
                    tile_interaction_1.selectRange.call(this, startIndex_1, currentIndex_1);
                    tiles.forEach(function (tile, index) {
                        if (index < Math.min(startIndex_1, currentIndex_1) || index > Math.max(startIndex_1, currentIndex_1)) {
                            tile_interaction_1.deselectTile.call(_this, tile);
                        }
                    });
                }
            }
            else if (!this.ctrlKey) {
                this.startTile = targetTile;
            }
        }
        else {
            if (!this.ctrlKey && !this.shiftKey) {
                tile_interaction_1.clearSelection.call(this);
                this.startTile = null;
            }
        }
        organize_toolbar_1.updateSelectAllCheckbox.call(this);
        organize_toolbar_1.enableDisableToolbarItems.call(this);
    }
    exports.onTileAreaMouseDown = onTileAreaMouseDown;
    function onTileAreaKeyDown(event) {
        if ((event.ctrlKey || event.metaKey) && !event.shiftKey) {
            this.ctrlKey = true;
            var keyCode = this.pdfViewerBase.getLegacyKeyCode(event);
            if (this.isOrganizeWindowOpen) {
                if (keyCode === 65) {
                    event.preventDefault();
                    tile_interaction_1.selectAllTiles.call(this);
                }
                if (keyCode === 90) {
                    event.preventDefault();
                    this.undo();
                }
                else if (keyCode === 89) {
                    event.preventDefault();
                    this.redo();
                }
            }
        }
        if (event.shiftKey) {
            this.shiftKey = true;
        }
    }
    exports.onTileAreaKeyDown = onTileAreaKeyDown;
    function onTileAreaKeyUp(event) {
        if (!(event.ctrlKey || event.metaKey)) {
            this.ctrlKey = false;
        }
        if (!event.shiftKey) {
            this.shiftKey = false;
        }
    }
    exports.onTileAreaKeyUp = onTileAreaKeyUp;
    function onSelectAllClick(event) {
        if (event.checked) {
            tile_interaction_1.selectAllTiles.call(this);
        }
        else {
            tile_interaction_1.clearSelection.call(this);
        }
    }
    exports.onSelectAllClick = onSelectAllClick;
    function autoScroll(e) {
        var proxy = this;
        var viewportY = e.event.type === 'touchmove' ? e.event.touches[0].clientY : e.event.clientY;
        var edgeSize = 10;
        this.autoScrollInterval = null;
        var viewportHeight = window.innerHeight;
        var edgeTop = edgeSize;
        var edgeBottom = (viewportHeight - edgeSize);
        var toolbarBottom = document.getElementById(this.pdfViewer.element.id + '_toolbar_appearance').getBoundingClientRect().bottom + edgeSize;
        var footer = this.organizeDialog.element.getElementsByClassName('e-footer-content');
        var footerBounds;
        if (!ej2_base_1.isNullOrUndefined(footer) && footer.length > 0) {
            footerBounds = footer[0].getBoundingClientRect();
        }
        var footerTop = !ej2_base_1.isNullOrUndefined(footerBounds) ? (footerBounds.top - edgeSize) :
            (this.tileAreaDiv.getBoundingClientRect().bottom - edgeSize);
        edgeTop = parseFloat(Math.max(edgeTop, toolbarBottom).toFixed(2));
        edgeBottom = Math.min(edgeBottom, footerTop);
        if (this.virtualEle.getBoundingClientRect().height >= this.tileAreaDiv.getBoundingClientRect().height) {
            clearTimeout(this.autoScrollInterval);
            proxy.autoScrollInterval = null;
            return;
        }
        var isInTopEdge = (parseFloat(this.virtualEle.getBoundingClientRect().top.toFixed(2)) <= edgeTop);
        var isInBottomEdge = (this.virtualEle.getBoundingClientRect().bottom >= edgeBottom);
        if (!(isInTopEdge || isInBottomEdge)) {
            clearTimeout(this.autoScrollInterval);
            proxy.autoScrollInterval = null;
            return;
        }
        var maxScrollY = (this.tileAreaDiv.scrollHeight - this.tileAreaDiv.clientHeight);
        (function checkForWindowScroll() {
            clearTimeout(proxy.autoScrollInterval);
            proxy.autoScrollInterval = null;
            if (adjustWindowScroll()) {
                proxy.autoScrollInterval = window.setTimeout(checkForWindowScroll, 30);
            }
        })();
        function adjustWindowScroll() {
            proxy.tileAreaDiv.onscroll = function () {
                var outerBorder = document.querySelector('.e-pv-organize-outer-border');
                if (!ej2_base_1.isNullOrUndefined(outerBorder)) {
                    outerBorder.style.display = 'none';
                }
            };
            var elementBounds = proxy.virtualEle.getBoundingClientRect();
            var dragDownDiffrence = elementBounds.bottom - (proxy.previousClientY + elementBounds.height);
            var dragUpDiffrence = elementBounds.top - proxy.previousClientY;
            proxy.previousClientY = elementBounds.top;
            var currentScrollY = proxy.tileAreaDiv.scrollTop;
            var canScrollUp = (currentScrollY > 0 && dragUpDiffrence <= 0);
            var canScrollDown = (currentScrollY < maxScrollY && dragDownDiffrence >= 0);
            var nextScrollY = currentScrollY;
            var maxStep = 10;
            if (isInTopEdge && canScrollUp) {
                var intensity = ((edgeTop - proxy.virtualEle.getBoundingClientRect().top) / edgeSize);
                nextScrollY = (nextScrollY - (maxStep * intensity));
            }
            else if (isInBottomEdge && canScrollDown) {
                var intensity = ((proxy.virtualEle.getBoundingClientRect().bottom - edgeBottom) / edgeSize);
                nextScrollY = (nextScrollY + (maxStep * intensity));
            }
            nextScrollY = Math.max(0, Math.min(maxScrollY, nextScrollY));
            if (nextScrollY !== currentScrollY) {
                proxy.tileAreaDiv.scrollTop = nextScrollY;
                return (true);
            }
            else {
                return (false);
            }
        }
    }
    exports.autoScroll = autoScroll;
    function handlePageMove(e, tileRect, gapBetweenDivs, outerBorder) {
        var isRightInsertion = isTileRightInsertion(e);
        if (!ej2_base_1.isNullOrUndefined(isTileRightInsertion)) {
            var offset = isRightInsertion ? (tileRect['width'] + gapBetweenDivs / 2) : (-gapBetweenDivs / 2);
            var parentBound = outerBorder.parentElement.getBoundingClientRect();
            outerBorder.style.left = (tileRect['x'] + offset - parentBound.x) + 'px';
            outerBorder.style.top = (tileRect['top'] - parentBound.y) + 'px';
            outerBorder.style.height = tileRect['height'] + 'px';
            this.isRightInsertion = isRightInsertion;
        }
    }
    exports.handlePageMove = handlePageMove;
    function isTileRightInsertion(e) {
        var mainTileElement = !ej2_base_1.isNullOrUndefined(e.target) ? e.target.closest('.e-pv-organize-anchor-node') : null;
        if (!ej2_base_1.isNullOrUndefined(mainTileElement)) {
            var tileRect = mainTileElement.getBoundingClientRect();
            var virtualElementClientX = e.event.type === 'mousemove' ? e.event.clientX : e.event.touches[0].clientX;
            return virtualElementClientX > tileRect['x'] + (tileRect['width'] / 2);
        }
        return null;
    }
    exports.isTileRightInsertion = isTileRightInsertion;
    function importDocWireEvent() {
        if (this.importDocInputElement) {
            this.boundImportDocument = organize_importaction_1.importDocument.bind(this);
            this.importDocInputElement.addEventListener('change', this.boundImportDocument);
        }
    }
    exports.importDocWireEvent = importDocWireEvent;
    function importDocUnWireEvent() {
        if (this.importDocInputElement) {
            this.boundImportDocument = null;
            this.importDocInputElement.removeEventListener('change', this.boundImportDocument);
        }
    }
    exports.importDocUnWireEvent = importDocUnWireEvent;
});